Skip to content

Commit

Permalink
add more tests for FromCataloguesExtractionRequestFulfiller
Browse files Browse the repository at this point in the history
  • Loading branch information
rkm committed Dec 11, 2024
1 parent 703ac32 commit d5bf0be
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public FromCataloguesExtractionRequestFulfiller(ICatalogue[] cataloguesToUseForI
{
_logger = LogManager.GetCurrentClassLogger();

_logger.Debug("Preparing to filter " + cataloguesToUseForImageLookup.Length + " Catalogues to look for compatible ones");
_logger.Debug($"Preparing to filter {cataloguesToUseForImageLookup.Length} Catalogues to look for compatible ones");

_catalogues = cataloguesToUseForImageLookup.OrderBy(c => c.ID).Select(QueryToExecuteColumnSet.Create).Where(s => s != null).ToArray()!;

_logger.Debug("Found " + _catalogues.Length + " Catalogues matching filter criteria");
_logger.Debug($"Found {_catalogues.Length} Catalogues matching filter criteria");

if (_catalogues.Length == 0)
throw new ArgumentOutOfRangeException(nameof(cataloguesToUseForImageLookup), "There are no compatible Catalogues in the repository (See QueryToExecuteColumnSet for required columns)");
Expand Down Expand Up @@ -111,9 +111,7 @@ private IEnumerable<IRejector> GetRejectorsFor(ExtractionRequestMessage message)
{
// they had better all override or none of them!
if (!applicableRejectors.All(r => r.Key.Overrides))
{
throw new Exception($"You cannot mix Overriding and non Overriding ModalitySpecificRejectors. Bad Modality was '{message.Modality}'");
}
throw new Exception($"You cannot mix Overriding and non Overriding ModalitySpecificRejectors. Bad Modality was '{message.Modality}'");

// yes we have custom rejection rules for this modality
return applicableRejectors.Select(r => r.Value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
using FAnsi;
using Moq;
using NUnit.Framework;
using Rdmp.Core.Curation.Data;
using Rdmp.Core.Repositories;
using SmiServices.Common;
using SmiServices.Common.Messages.Extraction;
using SmiServices.Common.Options;
using SmiServices.Microservices.CohortExtractor;
using SmiServices.Microservices.CohortExtractor.RequestFulfillers;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -114,12 +118,93 @@ public void GetAllMatchingFiles_NoCatalogueForModality_Throws()

// Act

var call = () => fulfiller.GetAllMatchingFiles(message).ToList();
List<ExtractImageCollection> call() => fulfiller.GetAllMatchingFiles(message).ToList();

// Assert

var exc = Assert.Throws<Exception>(() => call().ToList());
Assert.That(exc!.Message.StartsWith("Couldn't find any compatible Catalogues to run extraction queries against for query"));
Assert.That(exc!.Message, Does.StartWith("Couldn't find any compatible Catalogues to run extraction queries against for query"));
}

[Test]
public void GetAllMatchingFiles_NonMixedOverridingRejectors_Passes()
{
// Arrange

var catalogue = CreateCatalogue("CT");

var message = new ExtractionRequestMessage
{
KeyTag = "SeriesInstanceUID",
Modality = "CT",
};

var fulfiller = new FromCataloguesExtractionRequestFulfiller([catalogue]);
fulfiller.ModalitySpecificRejectors.Add(
new ModalitySpecificRejectorOptions
{
Overrides = true,
Modalities = "CT",
},
new RejectNone()
);
fulfiller.ModalitySpecificRejectors.Add(
new ModalitySpecificRejectorOptions
{
Overrides = true,
Modalities = "CT",
},
new RejectNone()
);

// Act

List<ExtractImageCollection> call() => fulfiller.GetAllMatchingFiles(message).ToList();

// Assert

Assert.DoesNotThrow(() => call().ToList());
}

[Test]
public void GetAllMatchingFiles_MixedOverridingRejectors_Throws()
{
// Arrange

var catalogue = CreateCatalogue("CT");

var message = new ExtractionRequestMessage
{
KeyTag = "SeriesInstanceUID",
Modality = "CT",
};

var fulfiller = new FromCataloguesExtractionRequestFulfiller([catalogue]);
fulfiller.ModalitySpecificRejectors.Add(
new ModalitySpecificRejectorOptions
{
Overrides = true,
Modalities = "CT",
},
new RejectNone()
);
fulfiller.ModalitySpecificRejectors.Add(
new ModalitySpecificRejectorOptions
{
Overrides = false,
Modalities = "CT",
},
new RejectNone()
);

// Act

List<ExtractImageCollection> call() => fulfiller.GetAllMatchingFiles(message).ToList();

// Assert

var exc = Assert.Throws<Exception>(() => call().ToList());
Assert.That(exc!.Message, Is.EqualTo("You cannot mix Overriding and non Overriding ModalitySpecificRejectors. Bad Modality was 'CT'"));
}

private static ICatalogue CreateCatalogue(string modality)
Expand All @@ -144,5 +229,14 @@ private static void Add(ICatalogue c, string col)
};
_ = new ExtractionInformation(repo, ci, new ColumnInfo(repo, col, "varchar(10)", ti), col);
}

private class RejectNone : IRejector
{
public bool Reject(IDataRecord row, [NotNullWhen(true)] out string? reason)
{
reason = null;
return false;
}
}
}
}

0 comments on commit d5bf0be

Please sign in to comment.