Skip to content

Commit

Permalink
NUnit API fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
jas88 committed Nov 27, 2023
1 parent 24a78c3 commit f7ffbc2
Show file tree
Hide file tree
Showing 75 changed files with 926 additions and 862 deletions.
1 change: 1 addition & 0 deletions Packages.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
| ------- | ------------| ------- | ------- | -------------------------- |
| HIC.DicomTypeTranslation | [GitHub](https://github.com/SMI/DicomTypeTranslation) | [GPL 3.0](https://www.gnu.org/licenses/gpl-3.0.html) | Translate dicom types into C# / database types | |
| LibArchive.Net | [GitHub](https://github.com/jas88/libarchive.net) | [BSD] | Access archive formats without the LZMA bugs of SharpCompress | |
| [NUnit.Analyzers](https://nunit.org/) |[GitHub](https://github.com/nunit/nunit.analyzers) | [MIT](https://opensource.org/licenses/MIT) | Unit testing support code |
53 changes: 28 additions & 25 deletions Rdmp.Dicom.Tests/Integration/ExecuteCommandAddTagTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,18 @@ public void TestAddTag_WithArchive(DatabaseType type)

// use it to create a table
var tbl = db.ExpectTable(template.TableName);
IAtomicCommand cmd = new ExecuteCommandCreateNewImagingDataset(RepositoryLocator,tbl , template);
Assert.IsFalse(cmd.IsImpossible);
IAtomicCommand cmd = new ExecuteCommandCreateNewImagingDataset(RepositoryLocator, tbl, template);
Assert.That(cmd.IsImpossible, Is.False);
cmd.Execute();

Assert.IsTrue(tbl.Exists());
Assert.That(tbl.Exists());

// import RDMP reference to the table
var importer = new TableInfoImporter(CatalogueRepository,tbl);
importer.DoImport(out var ti,out var cols);
var forward = new ForwardEngineerCatalogue(ti,cols);
forward.ExecuteForwardEngineering(out var catalogue,out _,out _);
var importer = new TableInfoImporter(CatalogueRepository, tbl);
importer.DoImport(out var ti, out var cols);

var forward = new ForwardEngineerCatalogue(ti, cols);
forward.ExecuteForwardEngineering(out var catalogue, out _, out _);

// Create an archive table and backup trigger like we would have if this were the target of a data load
var triggerImplementerFactory = new TriggerImplementerFactory(type);
Expand All @@ -60,36 +60,39 @@ public void TestAddTag_WithArchive(DatabaseType type)

var archive = tbl.Database.ExpectTable($"{tbl.GetRuntimeName()}_Archive");

Assert.IsTrue(archive.Exists());
Assert.That(archive.Exists());

var activator = new ConsoleInputManager(RepositoryLocator,ThrowImmediatelyCheckNotifier.Quiet)
var activator = new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet)
{
DisallowInput = true
};

// Test the actual commands
cmd = new ExecuteCommandAddTag(activator,catalogue,"ffffff","int");
Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible);
cmd = new ExecuteCommandAddTag(activator, catalogue, "ffffff", "int");
Assert.That(cmd.IsImpossible, Is.False, cmd.ReasonCommandImpossible);
cmd.Execute();

cmd = new ExecuteCommandAddTag(activator,catalogue,"EchoTime",null);
Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible);
cmd = new ExecuteCommandAddTag(activator, catalogue, "EchoTime", null);
Assert.That(cmd.IsImpossible, Is.False, cmd.ReasonCommandImpossible);
cmd.Execute();

// attempting to add something that is already there is not a problem and just gets skipped
Assert.DoesNotThrow(()=>new ExecuteCommandAddTag(activator,catalogue,"StudyDate",null).Execute());

cmd = new ExecuteCommandAddTag(activator,catalogue,"SeriesDate",null);
Assert.IsFalse(cmd.IsImpossible,cmd.ReasonCommandImpossible);
cmd.Execute();
Assert.DoesNotThrow(() => new ExecuteCommandAddTag(activator, catalogue, "StudyDate", null).Execute());

Assert.AreEqual("int",tbl.DiscoverColumn("ffffff").DataType.SQLType);
Assert.AreEqual("decimal(38,19)",tbl.DiscoverColumn("EchoTime").DataType.SQLType);
Assert.AreEqual(typeof(DateTime),tbl.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType());
cmd = new ExecuteCommandAddTag(activator, catalogue, "SeriesDate", null);
Assert.That(cmd.IsImpossible, Is.False, cmd.ReasonCommandImpossible);
cmd.Execute();

Assert.AreEqual("int",archive.DiscoverColumn("ffffff").DataType.SQLType);
Assert.AreEqual("decimal(38,19)",archive.DiscoverColumn("EchoTime").DataType.SQLType);
Assert.AreEqual(typeof(DateTime),archive.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType());
Assert.Multiple(() =>
{
Assert.That(tbl.DiscoverColumn("ffffff").DataType.SQLType, Is.EqualTo("int"));
Assert.That(tbl.DiscoverColumn("EchoTime").DataType.SQLType, Is.EqualTo("decimal(38,19)"));
Assert.That(tbl.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType(), Is.EqualTo(typeof(DateTime)));
Assert.That(archive.DiscoverColumn("ffffff").DataType.SQLType, Is.EqualTo("int"));
Assert.That(archive.DiscoverColumn("EchoTime").DataType.SQLType, Is.EqualTo("decimal(38,19)"));
Assert.That(archive.DiscoverColumn("SeriesDate").DataType.GetCSharpDataType(), Is.EqualTo(typeof(DateTime)));
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ namespace Rdmp.Dicom.Tests.Integration;
class ExecuteCommandCreateNewImagingDatasetSuiteTests : DatabaseTests
{

#region Template
#region Template

const string TemplateYaml = @"
const string TemplateYaml = @"
#Last Modified: 2020-04-07
Tables:
- TableName: StudyTable
Expand Down Expand Up @@ -140,38 +140,41 @@ class ExecuteCommandCreateNewImagingDatasetSuiteTests : DatabaseTests
- ColumnName: ScanOptions
AllowNulls: true
";
#endregion
#endregion

[TestCase(DatabaseType.MicrosoftSQLServer)]
[TestCase(DatabaseType.MySql)]
public void TestSuiteCreation(DatabaseType dbType)
{
var db = GetCleanedServer(dbType);
[TestCase(DatabaseType.MicrosoftSQLServer)]
[TestCase(DatabaseType.MySql)]
public void TestSuiteCreation(DatabaseType dbType)
{
var db = GetCleanedServer(dbType);

var template = Path.Combine(TestContext.CurrentContext.WorkDirectory,"CT.it");
File.WriteAllText(template,TemplateYaml);
var template = Path.Combine(TestContext.CurrentContext.WorkDirectory, "CT.it");
File.WriteAllText(template, TemplateYaml);

var cmd = new ExecuteCommandCreateNewImagingDatasetSuite(RepositoryLocator,db,
new(TestContext.CurrentContext.WorkDirectory),
typeof(DicomFileCollectionSource),
"CT_",
new(template),
persistentRaw: false,
createLoad: true);
var cmd = new ExecuteCommandCreateNewImagingDatasetSuite(RepositoryLocator, db,
new(TestContext.CurrentContext.WorkDirectory),
typeof(DicomFileCollectionSource),
"CT_",
new(template),
persistentRaw: false,
createLoad: true);

Assert.IsFalse(cmd.IsImpossible);
Assert.That(cmd.IsImpossible, Is.False);

cmd.Execute();
cmd.Execute();

Assert.IsNotNull(cmd.NewLoadMetadata);

var pipelineCreated = RepositoryLocator.CatalogueRepository.GetAllObjects<Pipeline>().OrderByDescending(p=>p.ID).First();

Assert.AreEqual(typeof(DicomFileCollectionSource),pipelineCreated.Source.GetClassAsSystemType());

var argFieldMap = pipelineCreated.Source.GetAllArguments().Single(a=>a.Name.Equals(nameof(DicomSource.UseAllTableInfoInLoadAsFieldMap)));

Assert.IsNotNull(argFieldMap);
Assert.AreEqual(argFieldMap.GetValueAsSystemType(),cmd.NewLoadMetadata);
}
Assert.That(cmd.NewLoadMetadata, Is.Not.Null);

var pipelineCreated = RepositoryLocator.CatalogueRepository.GetAllObjects<Pipeline>().OrderByDescending(p => p.ID).First();

Assert.That(pipelineCreated.Source.GetClassAsSystemType(), Is.EqualTo(typeof(DicomFileCollectionSource)));

var argFieldMap = pipelineCreated.Source.GetAllArguments().Single(a => a.Name.Equals(nameof(DicomSource.UseAllTableInfoInLoadAsFieldMap)));

Assert.Multiple(() =>
{
Assert.That(argFieldMap, Is.Not.Null);
Assert.That(cmd.NewLoadMetadata, Is.EqualTo(argFieldMap.GetValueAsSystemType()));
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ExecuteCommandPacsFetchTest : DatabaseTests
[Test]
public void TestLocal()
{
var cmd = new ExecuteCommandPacsFetch(new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet){DisallowInput= true},"2013-01-01","2014-01-01","www.dicomserver.co.uk",11112,"you","localhost",11112,"me",TestContext.CurrentContext.WorkDirectory,0);
var cmd = new ExecuteCommandPacsFetch(new ConsoleInputManager(RepositoryLocator, ThrowImmediatelyCheckNotifier.Quiet) { DisallowInput = true }, "2013-01-01", "2014-01-01", "www.dicomserver.co.uk", 11112, "you", "localhost", 11112, "me", TestContext.CurrentContext.WorkDirectory, 0);
cmd.Execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void TestAnonymiseAFile()

var inPath = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "in"));
var outPath = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.WorkDirectory, "out"));

if (inPath.Exists)
inPath.Delete(true);
inPath.Create();
Expand All @@ -27,9 +27,9 @@ public void TestAnonymiseAFile()

// put a dicom file in the in dir
var testFile = new FileInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData/IM-0001-0013.dcm"));
testFile.CopyTo(Path.Combine(inPath.FullName, "blah.dcm"),true);
testFile.CopyTo(Path.Combine(inPath.FullName, "blah.dcm"), true);

anon.Initialize(1, outPath,null /*no UID mapping*/);
anon.Initialize(1, outPath, null /*no UID mapping*/);

var putter = new PutInRoot();

Expand All @@ -39,5 +39,5 @@ public void TestAnonymiseAFile()
"fffff",
putter, null);
}

}
Loading

0 comments on commit f7ffbc2

Please sign in to comment.