From 98e41f787e00c933ac57fa7abb0dfd46edd62190 Mon Sep 17 00:00:00 2001 From: Ruairidh MacLeod Date: Mon, 8 Jan 2024 13:52:41 +0000 Subject: [PATCH] cover CT and SR cases in test --- .../RunnerTests/DicomFileRunnerTest.cs | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Tests/IsIdentifiableTests/RunnerTests/DicomFileRunnerTest.cs b/Tests/IsIdentifiableTests/RunnerTests/DicomFileRunnerTest.cs index e2a1af9c..3e1c55b3 100644 --- a/Tests/IsIdentifiableTests/RunnerTests/DicomFileRunnerTest.cs +++ b/Tests/IsIdentifiableTests/RunnerTests/DicomFileRunnerTest.cs @@ -23,7 +23,7 @@ public void OneTimeSetUp() var testRulesDir = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, "data", "IsIdentifiableRules")); testRulesDir.Create(); - _tessDir = new DirectoryInfo(Path.Combine(testRulesDir.Parent.FullName, "tessdata")); + _tessDir = new DirectoryInfo(Path.Combine(testRulesDir.Parent!.FullName, "tessdata")); _tessDir.Create(); var dest = Path.Combine(_tessDir.FullName, "eng.traineddata"); if (!File.Exists(dest)) @@ -157,8 +157,9 @@ public void SkipPixelSR() }); } - [Test] - public void MissingPixelDataWhenValidationSkippedShouldThrow() + [TestCase("CT")] + [TestCase("SR")] + public void MissingPixelDataWhenValidationSkippedShouldThrow(string modality) { // Arrange @@ -169,9 +170,15 @@ public void MissingPixelDataWhenValidationSkippedShouldThrow() }; var fileName = Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(DicomFileRunnerTest), "nopixels.dcm"); + DicomUID sopClassUid = modality switch + { + "CT" => DicomUID.CTImageStorage, + "SR" => DicomUID.BasicTextSRStorage, + _ => throw new Exception($"No case for {modality}"), + }; var ds = new DicomDataset() { - { DicomTag.SOPClassUID, DicomUID.CTImageStorage }, + { DicomTag.SOPClassUID, sopClassUid }, { DicomTag.SOPInstanceUID, "1" }, }; var df = new DicomFile(ds); @@ -189,8 +196,30 @@ public void MissingPixelDataWhenValidationSkippedShouldThrow() // Assert - var exc = Assert.Throws(() => call()); - Assert.That(exc.Message, Is.EqualTo("Could not create DicomImage for file with SOPClassUID 'CT Image Storage [1.2.840.10008.5.1.4.1.1.2]'")); + switch (modality) + { + case "CT": + var exc = Assert.Throws(() => call()); + Assert.Multiple(() => + { + Assert.That(exc!.Message, Is.EqualTo("Could not create DicomImage for file with SOPClassUID 'CT Image Storage [1.2.840.10008.5.1.4.1.1.2]'")); + Assert.That(runner.FilesValidated, Is.EqualTo(0)); + Assert.That(runner.PixelFilesValidated, Is.EqualTo(0)); + }); + break; + + case "SR": + Assert.DoesNotThrow(() => call()); + Assert.Multiple(() => + { + Assert.That(runner.FilesValidated, Is.EqualTo(1)); + Assert.That(runner.PixelFilesValidated, Is.EqualTo(0)); + }); + break; + + default: + throw new Exception($"No case for {modality}"); + } } #endregion