-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
142 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,98 +1,168 @@ | ||
using System.Data; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Threading; | ||
using FAnsi; | ||
using NPOI.HPSF; | ||
using NUnit.Framework; | ||
using Rdmp.Core.Curation.Data; | ||
using Rdmp.Core.Curation.Data.DataLoad; | ||
using Rdmp.Core.ReusableLibraryCode.Progress; | ||
using Rdmp.Dicom.Extraction.FoDicomBased; | ||
using Rdmp.Dicom.PipelineComponents; | ||
using Rdmp.Dicom.PipelineComponents.CFind; | ||
using Rdmp.Dicom.PipelineComponents.DicomSources; | ||
using Tests.Common; | ||
|
||
namespace Rdmp.Dicom.Tests; | ||
|
||
class IsolationReviewTests : DatabaseTests | ||
class IsolationReviewTests //: DatabaseTests | ||
{ | ||
|
||
[TestCase(DatabaseType.MicrosoftSQLServer)] | ||
[TestCase(DatabaseType.Oracle)] | ||
[TestCase(DatabaseType.PostgreSql)] | ||
[TestCase(DatabaseType.MySql)] | ||
public void TestFindTables(DatabaseType dbType) | ||
[Test] | ||
public void pathTest() | ||
{ | ||
var db = GetCleanedServer(dbType); | ||
var ArchiveRootIfAny = "C:"; | ||
//var filePath = "GoFUSION/2018/01/03/T101H05957407.7z"; | ||
var filePath = "C:/temp/testdicoms/1969.7z"; | ||
var source = new DicomFileCollectionSource(); | ||
source.ArchiveRoot = ArchiveRootIfAny; | ||
|
||
var a = new DicomFileCollectionSource(); | ||
a.ArchiveRoot = ArchiveRootIfAny; | ||
var x = source.ApplyArchiveRootToMakeRelativePath(filePath); | ||
var filepaths = new List<(string, string)> | ||
{ | ||
(filePath, filePath) | ||
}; | ||
var y = new AmbiguousFilePath(ArchiveRootIfAny, filepaths).GetDataset(); | ||
List<string> z = new(); | ||
foreach(var dicomFile in y) | ||
{ | ||
|
||
using var dt = new DataTable(); | ||
dt.Columns.Add("A"); | ||
dt.Columns.Add("B"); | ||
dt.Columns.Add("C"); | ||
var t = a.ApplyArchiveRootToMakeRelativePath(dicomFile.Item1); | ||
z.Add(t); | ||
} | ||
Assert.Pass(); | ||
} | ||
|
||
// 'pk' 1 differs on col B AND col C | ||
dt.Rows.Add(1, 2, 3); | ||
dt.Rows.Add(1, 3, 2); | ||
[Test] | ||
public void pathTest2() | ||
{ | ||
var toProcess = new DataTable(); | ||
toProcess.Columns.Add("RelativeArchiveColumnName"); | ||
toProcess.Columns.Add("GetRuntimeName"); | ||
toProcess.Rows.Add(new Object[]{ "./temp/testdicoms/1969.7z", "Name"}); | ||
var ArchiveRootIfAny = "C:"; | ||
var fileRows = new Dictionary<string, DataRow>(); | ||
var releaseIDs = new Dictionary<string, string>(); | ||
var dicomFiles = new List<(string, string)>(); | ||
foreach (DataRow processRow in toProcess.Rows) | ||
{ | ||
var file = (string)processRow["RelativeArchiveColumnName"]; | ||
if (file.StartsWith("./")) | ||
{ | ||
file = file.Substring(2); | ||
} | ||
fileRows.Add(file, processRow); | ||
dicomFiles.Add((file, file)); | ||
releaseIDs.Add(file, processRow["GetRuntimeName"].ToString()); | ||
} | ||
foreach (var dicomFile in new AmbiguousFilePath(ArchiveRootIfAny, dicomFiles).GetDataset()) | ||
{ | ||
var x = 1 + 1; | ||
Check warning on line 75 in Rdmp.Dicom.Tests/IsolationReviewTests.cs
|
||
//if (_errors > 0 && _errors > ErrorThreshold) | ||
// throw new Exception($"Number of errors reported ({_errors}) reached the threshold ({ErrorThreshold})"); | ||
//cancellationToken.ThrowIfAbortRequested(); | ||
//ProcessFile(dicomFile.Item2, listener, releaseIDs[dicomFile.Item1], _putter, fileRows[dicomFile.Item1]); | ||
} | ||
|
||
Assert.Pass(); | ||
} | ||
|
||
//novel (should not appear in diff table) | ||
dt.Rows.Add(4, 1, 1); | ||
//[TestCase(DatabaseType.MicrosoftSQLServer)] | ||
//[TestCase(DatabaseType.Oracle)] | ||
//[TestCase(DatabaseType.PostgreSql)] | ||
//[TestCase(DatabaseType.MySql)] | ||
//public void TestFindTables(DatabaseType dbType) | ||
//{ | ||
// var db = GetCleanedServer(dbType); | ||
|
||
//novel (should not appear in diff table) | ||
dt.Rows.Add(5, 1, 1); | ||
// using var dt = new DataTable(); | ||
// dt.Columns.Add("A"); | ||
// dt.Columns.Add("B"); | ||
// dt.Columns.Add("C"); | ||
|
||
// 'pk' 2 differs on col C | ||
dt.Rows.Add(2, 1, 1); | ||
dt.Rows.Add(2, 1, 2); | ||
// // 'pk' 1 differs on col B AND col C | ||
// dt.Rows.Add(1, 2, 3); | ||
// dt.Rows.Add(1, 3, 2); | ||
|
||
//novel (should not appear in diff table) | ||
dt.Rows.Add(6, 1, 1); | ||
// //novel (should not appear in diff table) | ||
// dt.Rows.Add(4, 1, 1); | ||
|
||
// 'pk' 3 differs on col B | ||
dt.Rows.Add(3, 1, 1); | ||
dt.Rows.Add(3, 2, 1); | ||
// //novel (should not appear in diff table) | ||
// dt.Rows.Add(5, 1, 1); | ||
|
||
// // 'pk' 2 differs on col C | ||
// dt.Rows.Add(2, 1, 1); | ||
// dt.Rows.Add(2, 1, 2); | ||
|
||
db.CreateTable("mytbl_Isolation", dt); | ||
// //novel (should not appear in diff table) | ||
// dt.Rows.Add(6, 1, 1); | ||
|
||
var lmd = new LoadMetadata(CatalogueRepository, "ExampleLoad"); | ||
var pt = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustRaw) | ||
{ | ||
ProcessTaskType = ProcessTaskType.MutilateDataTable, | ||
Path = typeof(PrimaryKeyCollisionIsolationMutilation).FullName | ||
}; | ||
pt.SaveToDatabase(); | ||
// // 'pk' 3 differs on col B | ||
// dt.Rows.Add(3, 1, 1); | ||
// dt.Rows.Add(3, 2, 1); | ||
|
||
//make an isolation db that is the | ||
var eds = new ExternalDatabaseServer(CatalogueRepository, "Isolation db", null); | ||
eds.SetProperties(db); | ||
|
||
var args = pt.CreateArgumentsForClassIfNotExists(typeof(PrimaryKeyCollisionIsolationMutilation)); | ||
// db.CreateTable("mytbl_Isolation", dt); | ||
|
||
var ti = new TableInfo(CatalogueRepository, "mytbl"); | ||
var ci = new ColumnInfo(CatalogueRepository, "A", "varchar(1)", ti) { IsPrimaryKey = true }; | ||
ci.SaveToDatabase(); | ||
// var lmd = new LoadMetadata(CatalogueRepository, "ExampleLoad"); | ||
// var pt = new ProcessTask(CatalogueRepository, lmd, LoadStage.AdjustRaw) | ||
// { | ||
// ProcessTaskType = ProcessTaskType.MutilateDataTable, | ||
// Path = typeof(PrimaryKeyCollisionIsolationMutilation).FullName | ||
// }; | ||
// pt.SaveToDatabase(); | ||
|
||
SetArg(args, "IsolationDatabase", eds); | ||
SetArg(args, "TablesToIsolate", new[] { ti }); | ||
// //make an isolation db that is the | ||
// var eds = new ExternalDatabaseServer(CatalogueRepository, "Isolation db", null); | ||
// eds.SetProperties(db); | ||
|
||
var reviewer = new IsolationReview(pt); | ||
// var args = pt.CreateArgumentsForClassIfNotExists(typeof(PrimaryKeyCollisionIsolationMutilation)); | ||
|
||
//no error since it is configured correctly | ||
Assert.That(reviewer.Error, Is.Null); | ||
// var ti = new TableInfo(CatalogueRepository, "mytbl"); | ||
// var ci = new ColumnInfo(CatalogueRepository, "A", "varchar(1)", ti) { IsPrimaryKey = true }; | ||
// ci.SaveToDatabase(); | ||
|
||
//tables should exist | ||
var isolationTables = reviewer.GetIsolationTables(); | ||
Assert.That(isolationTables.Single().Value.Exists()); | ||
// SetArg(args, "IsolationDatabase", eds); | ||
// SetArg(args, "TablesToIsolate", new[] { ti }); | ||
|
||
// var reviewer = new IsolationReview(pt); | ||
|
||
var diffDataTable = reviewer.GetDifferences(isolationTables.Single(), out var diffs); | ||
// //no error since it is configured correctly | ||
// Assert.That(reviewer.Error, Is.Null); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.That(diffDataTable.Rows, Has.Count.EqualTo(6)); | ||
Assert.That(diffs, Has.Count.EqualTo(6)); | ||
}); | ||
} | ||
// //tables should exist | ||
// var isolationTables = reviewer.GetIsolationTables(); | ||
// Assert.That(isolationTables.Single().Value.Exists()); | ||
|
||
private static void SetArg(IArgument[] args, string argName, object value) | ||
{ | ||
var arg = args.Single(a => a.Name.Equals(argName)); | ||
arg.SetValue(value); | ||
arg.SaveToDatabase(); | ||
} | ||
|
||
// var diffDataTable = reviewer.GetDifferences(isolationTables.Single(), out var diffs); | ||
|
||
// Assert.Multiple(() => | ||
// { | ||
// Assert.That(diffDataTable.Rows, Has.Count.EqualTo(6)); | ||
// Assert.That(diffs, Has.Count.EqualTo(6)); | ||
// }); | ||
//} | ||
|
||
//private static void SetArg(IArgument[] args, string argName, object value) | ||
//{ | ||
// var arg = args.Single(a => a.Name.Equals(argName)); | ||
// arg.SetValue(value); | ||
// arg.SaveToDatabase(); | ||
//} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters