Ejemplo n.º 1
0
        public void TestSwapCache()
        {
            var mappingDataTable = new DataTable("IdMap");

            mappingDataTable.Columns.Add("priv");
            mappingDataTable.Columns.Add("pub");

            mappingDataTable.Rows.Add("CHI-1", "REP-1");
            mappingDataTable.Rows.Add("CHI-2", "REP-2");

            DiscoveredDatabase db = GetCleanedServer(DatabaseType.MicrosoftSQLServer);

            GlobalOptions options = new GlobalOptionsFactory().Load();

            options.IdentifierMapperOptions = new IdentifierMapperOptions
            {
                MappingConnectionString = db.Server.Builder.ConnectionString,
                MappingTableName        = db.CreateTable("IdMap", mappingDataTable).GetFullyQualifiedName(),
                SwapColumnName          = "priv",
                ReplacementColumnName   = "pub",
                MappingDatabaseType     = DatabaseType.MicrosoftSQLServer,
                TimeoutInSeconds        = 500
            };

            var swapper = new TableLookupSwapper();

            swapper.Setup(options.IdentifierMapperOptions);

            string _;
            string swapped = swapper.GetSubstitutionFor("CHI-1", out _);

            Assert.AreEqual("REP-1", swapped);
            swapped = swapper.GetSubstitutionFor("CHI-1", out _);
            Assert.AreEqual("REP-1", swapped);

            Assert.AreEqual(2, swapper.Success);
            Assert.AreEqual(1, swapper.CacheHit);

            swapped = swapper.GetSubstitutionFor("CHI-2", out _);
            Assert.AreEqual("REP-2", swapped);
            swapped = swapper.GetSubstitutionFor("CHI-2", out _);
            Assert.AreEqual("REP-2", swapped);

            Assert.AreEqual(4, swapper.Success);
            Assert.AreEqual(2, swapper.CacheHit);

            // Just to make sure...

            swapped = swapper.GetSubstitutionFor("CHI-1", out _);
            Assert.AreEqual("REP-1", swapped);

            Assert.AreEqual(5, swapper.Success);
            Assert.AreEqual(2, swapper.CacheHit);
        }
Ejemplo n.º 2
0
        public void TestIdentifierSwap_NoCache(DatabaseType type, Test test)
        {
            var mappingDataTable = new DataTable("IdMap");

            mappingDataTable.Columns.Add("priv");
            mappingDataTable.Columns.Add("pub");
            mappingDataTable.Rows.Add("010101", "020202");
            mappingDataTable.Rows.Add("0101010101", "0202020202");

            var db = GetCleanedServer(type);

            var options = new IdentifierMapperOptions();

            options.MappingConnectionString = db.Server.Builder.ConnectionString;
            options.MappingTableName        = db.CreateTable("IdMap", mappingDataTable).GetFullyQualifiedName();
            options.SwapColumnName          = "priv";
            options.ReplacementColumnName   = "pub";
            options.MappingDatabaseType     = type;
            options.TimeoutInSeconds        = 500;

            var swapper = new TableLookupSwapper();

            swapper.Setup(options);

            var consumer = new IdentifierMapperQueueConsumer(Mock.Of <IProducerModel>(), swapper);

            consumer.AllowRegexMatching = true;

            var msg = GetTestDicomFileMessage(test);

            string reason;

            consumer.SwapIdentifier(msg, out reason);

            if (test == Test.Normal)
            {
                AssertDicomFileMessageHasPatientID(msg, "020202");
            }
            else if (test == Test.ProperlyFormatedChi)
            {
                AssertDicomFileMessageHasPatientID(msg, "0202020202");
            }
            else
            {
                Assert.Fail("Wrong test case?");
            }
        }