From 66b49dd9e8f8167dc580c7d09d50ba96849eb0ca Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Tue, 17 Dec 2024 22:20:15 +0000 Subject: [PATCH] wip: fix errors & tidy test --- .../DicomAnonymiserHostTests.cs | 76 ++----------------- 1 file changed, 8 insertions(+), 68 deletions(-) diff --git a/tests/SmiServices.IntegrationTests/Microservices/DicomAnonymiser/DicomAnonymiserHostTests.cs b/tests/SmiServices.IntegrationTests/Microservices/DicomAnonymiser/DicomAnonymiserHostTests.cs index d7e22570e..36822b768 100644 --- a/tests/SmiServices.IntegrationTests/Microservices/DicomAnonymiser/DicomAnonymiserHostTests.cs +++ b/tests/SmiServices.IntegrationTests/Microservices/DicomAnonymiser/DicomAnonymiserHostTests.cs @@ -10,7 +10,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.IO.Abstractions; using System.Linq; using System.Threading; @@ -19,34 +18,10 @@ namespace SmiServices.IntegrationTests.Microservices.DicomAnonymiser; [RequiresRabbit] public class DicomAnonymiserHostTests { - #region Fixture Methods - - // Private fields (_tempTestDir, _dicomRoot, _fakeDicom) that - // are used in the setup and teardown of each test. private DirectoryInfo _tempTestDir = null!; private DirectoryInfo _dicomRoot = null!; private string _fakeDicom = null!; - - // [OneTimeSetUp] and [OneTimeTearDown] methods are run once - // before and after all the tests in the class, respectively. - // In this case, the setup method is used to set up a logger. - [OneTimeSetUp] - public void OneTimeSetUp() - { - } - - [OneTimeTearDown] - public void OneTimeTearDown() { } - - #endregion - - #region Test Methods - - // [SetUp] and [TearDown] methods are run before and after each - // test, respectively. In this case, the setup method creates a - // temporary directory and a fake DICOM file, and the teardown - // method deletes the temporary directory. [SetUp] public void SetUp() { @@ -64,33 +39,15 @@ public void TearDown() _tempTestDir.Delete(recursive: true); } - #endregion - - #region Tests - - // The Integration_HappyPath_MockAnonymiser method is a test case - // structured in the Arrange-Act-Assert pattern. It tests for the - // scenario where the DICOM Anonymiser successfully anonymises a - // DICOM file. [Test] public void Integration_HappyPath_MockAnonymiser() { - // Arrange - // It sets up the necessary objects and state for the test. This - // includes creating a mock DICOM Anonymiser, setting file paths, - // and creating a DicomAnonymiserHost. - GlobalOptions globals = new GlobalOptionsFactory().Load(nameof(Integration_HappyPath_MockAnonymiser)); globals.FileSystemOptions!.FileSystemRoot = _dicomRoot.FullName; var extractRoot = Directory.CreateDirectory(Path.Combine(_tempTestDir.FullName, "extractRoot")); globals.FileSystemOptions.ExtractRoot = extractRoot.FullName; - // NOTE: The commented out code below is an alternative way to create - // a fake DICOM file, however, it is not used in this test. - // File.Create(_fakeDicom).Dispose(); - // File.SetAttributes(_fakeDicom, File.GetAttributes(_fakeDicom) | FileAttributes.ReadOnly); - var dicomFile = new DicomFile(); dicomFile.Dataset.Add(DicomTag.PatientID, "12345678"); dicomFile.Dataset.Add(DicomTag.Modality, "CT"); @@ -122,18 +79,14 @@ public void Integration_HappyPath_MockAnonymiser() OutputPath = "foo-an.dcm", }; - // The test uses the Moq library to create a mock implementation of - // the IDicomAnonymiser interface. This allows the test to control the - // behavior of the DICOM Anonymiser and verify that it is called with - // the correct arguments. var mockAnonymiser = new Mock(MockBehavior.Strict); mockAnonymiser .Setup( x => x.Anonymise( - It.Is(x => x.ExtractionJobIdentifier == testExtractFileMessage.ExtractionJobIdentifier), - It.Is(x => x.FullName == _fakeDicom), - It.Is(x => x.FullName == Path.Combine(extractDirAbs.FullName, "foo-an.dcm")), - out It.Ref.IsAny + It.Is(x => x.Name == _fakeDicom), + It.Is(x => x.Name == Path.Combine(extractDirAbs.FullName, "foo-an.dcm")), + It.IsAny(), + out It.Ref.IsAny ) ) .Callback(() => File.Create(expectedAnonPathAbs).Dispose()) @@ -145,13 +98,11 @@ out It.Ref.IsAny List statusMessages = []; - using ( - var tester = new MicroserviceTester( + using var tester = new MicroserviceTester( globals.RabbitOptions!, globals.DicomAnonymiserOptions.AnonFileConsumerOptions! - ) - ) - { + ); + tester.CreateExchange(statusExchange, successQueue, isSecondaryBinding: false, routingKey: "verify"); tester.CreateExchange(statusExchange, failureQueue, isSecondaryBinding: true, routingKey: "noverify"); @@ -159,10 +110,6 @@ out It.Ref.IsAny var host = new DicomAnonymiserHost(globals, mockAnonymiser.Object); - // Act - // It starts the DicomAnonymiserHost and waits for it to process - //a message. - host.Start(); var timeoutSecs = 10; @@ -178,12 +125,7 @@ out It.Ref.IsAny } host.Stop("Test end"); - } - - // Assert - // It checks that the expected outcome has occurred. In this case, it - // checks that the status message indicates that the file was anonymised - // and that the anonymised file exists. + tester.Dispose(); var statusMessage = statusMessages.Single(); Assert.Multiple(() => @@ -192,6 +134,4 @@ out It.Ref.IsAny Assert.That(File.Exists(expectedAnonPathAbs), Is.True); }); } - - #endregion }