Example #1
0
        public void Test_DodgyTagNames()
        {
            _helper.TruncateTablesIfExists();

            DirectoryInfo d = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(Test_DodgyTagNames)));

            d.Create();

            var fi  = TestData.Create(new FileInfo(Path.Combine(d.FullName, "MyTestFile.dcm")));
            var fi2 = TestData.Create(new FileInfo(Path.Combine(d.FullName, "MyTestFile2.dcm")));

            DicomFile dcm;

            using (var stream = File.OpenRead(fi.FullName))
            {
                dcm = DicomFile.Open(stream);
                dcm.Dataset.AddOrUpdate(DicomTag.PrintRETIRED, "FISH");
                dcm.Dataset.AddOrUpdate(DicomTag.Date, new DateTime(2001, 01, 01));
                dcm.Save(fi2.FullName);
            }

            var adder = new TagColumnAdder(DicomTypeTranslaterReader.GetColumnNameForTag(DicomTag.Date, false), "datetime2", _helper.ImageTableInfo, new AcceptAllCheckNotifier());

            adder.Execute();

            adder = new TagColumnAdder(DicomTypeTranslaterReader.GetColumnNameForTag(DicomTag.PrintRETIRED, false), "datetime2", _helper.ImageTableInfo, new AcceptAllCheckNotifier());
            adder.Execute();

            fi.Delete();
            File.Move(fi2.FullName, fi.FullName);

            //creates the queues, exchanges and bindings
            var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions);

            tester.CreateExchange(_globals.RabbitOptions.FatalLoggingExchange, null);

            using (var host = new DicomRelationalMapperHost(_globals))
            {
                host.Start();

                using (var timeline = new TestTimeline(tester))
                {
                    timeline.SendMessage(_globals.DicomRelationalMapperOptions, _helper.GetDicomFileMessage(_globals.FileSystemOptions.FileSystemRoot, fi));

                    //start the timeline
                    timeline.StartTimeline();

                    Thread.Sleep(TimeSpan.FromSeconds(10));
                    new TestTimelineAwaiter().Await(() => host.Consumer.AckCount >= 1, null, 30000, () => host.Consumer.DleErrors);

                    Assert.AreEqual(1, _helper.SeriesTable.GetRowCount(), "SeriesTable did not have the expected number of rows in LIVE");
                    Assert.AreEqual(1, _helper.StudyTable.GetRowCount(), "StudyTable did not have the expected number of rows in LIVE");
                    Assert.AreEqual(1, _helper.ImageTable.GetRowCount(), "ImageTable did not have the expected number of rows in LIVE");

                    host.Stop("Test end");
                }
            }

            tester.Shutdown();
        }
Example #2
0
        public void TestLoadingOneImage_SingleFileMessage(int numberOfMessagesToSend, bool mixInATextFile)
        {
            _helper.TruncateTablesIfExists();

            DirectoryInfo d = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(TestLoadingOneImage_SingleFileMessage)));

            d.Create();

            var fi = TestData.Create(new FileInfo(Path.Combine(d.FullName, "MyTestFile.dcm")));

            if (mixInATextFile)
            {
                var randomText = new FileInfo(Path.Combine(d.FullName, "RandomTextFile.dcm"));
                File.WriteAllLines(randomText.FullName, new[] { "I love dancing", "all around the world", "boy the world is a big place eh?" });
            }

            //creates the queues, exchanges and bindings
            var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions);

            tester.CreateExchange(_globals.RabbitOptions.FatalLoggingExchange, null);

            using (var host = new DicomRelationalMapperHost(_globals))
            {
                host.Start();

                using (var timeline = new TestTimeline(tester))
                {
                    //send the message 10 times over a 10 second period
                    for (int i = 0; i < numberOfMessagesToSend; i++)
                    {
                        timeline
                        .SendMessage(_globals.DicomRelationalMapperOptions, _helper.GetDicomFileMessage(_globals.FileSystemOptions.FileSystemRoot, fi))
                        .Wait(1000);
                    }

                    //start the timeline
                    timeline.StartTimeline();

                    Thread.Sleep(TimeSpan.FromSeconds(10));
                    new TestTimelineAwaiter().Await(() => host.Consumer.AckCount >= numberOfMessagesToSend, null, 30000, () => host.Consumer.DleErrors);

                    Assert.AreEqual(1, _helper.SeriesTable.GetRowCount(), "SeriesTable did not have the expected number of rows in LIVE");
                    Assert.AreEqual(1, _helper.StudyTable.GetRowCount(), "StudyTable did not have the expected number of rows in LIVE");
                    Assert.AreEqual(1, _helper.ImageTable.GetRowCount(), "ImageTable did not have the expected number of rows in LIVE");

                    host.Stop("Test end");
                }
            }

            tester.Shutdown();
        }
Example #3
0
        public void TestPopulatorBasic(int nMessages)
        {
            // Arrange

            string currentCollectionName = MongoDbPopulatorTestHelper.GetCollectionNameForTest(string.Format("TestPopulatorBasic({0})", nMessages));

            _helper.Globals.MongoDbPopulatorOptions.SeriesCollection = currentCollectionName;

            var tester = new MicroserviceTester(_helper.Globals.RabbitOptions, _helper.Globals.MongoDbPopulatorOptions.SeriesQueueConsumerOptions, _helper.Globals.MongoDbPopulatorOptions.ImageQueueConsumerOptions);
            var host   = new MongoDbPopulatorHost(_helper.Globals);

            host.Start();

            using (var timeline = new TestTimeline(tester))
            {
                var ds = new DicomDataset
                {
                    new DicomUniqueIdentifier(DicomTag.SOPInstanceUID, "1.2.3.4")
                };

                var message = new SeriesMessage
                {
                    NationalPACSAccessionNumber = "NationalPACSAccessionNumber-test",
                    DirectoryPath     = "DirectoryPath-test",
                    StudyInstanceUID  = "StudyInstanceUID-test",
                    SeriesInstanceUID = "SeriesInstanceUID-test",
                    ImagesInSeries    = 123,
                    DicomDataset      = DicomTypeTranslater.SerializeDatasetToJson(ds)
                };

                // Act

                for (var i = 0; i < nMessages; i++)
                {
                    timeline.SendMessage(_helper.Globals.MongoDbPopulatorOptions.SeriesQueueConsumerOptions, message);
                }

                timeline.StartTimeline();

                var       timeout  = 30000;
                const int stepSize = 500;

                if (Debugger.IsAttached)
                {
                    timeout = int.MaxValue;
                }

                var nWritten = 0L;

                while (nWritten < nMessages && timeout > 0)
                {
                    nWritten = _helper.TestDatabase.GetCollection <BsonDocument>(currentCollectionName).CountDocuments(new BsonDocument());

                    Thread.Sleep(stepSize);
                    timeout -= stepSize;
                }

                // Assert

                if (timeout <= 0)
                {
                    Assert.Fail("Failed to process expected number of messages within the timeout");
                }

                host.Stop("Test end");
                tester.Shutdown();
            }
        }
Example #4
0
        public void TestLoadingOneImage_MileWideTest()
        {
            _helper.TruncateTablesIfExists();

            DirectoryInfo d = new DirectoryInfo(Path.Combine(TestContext.CurrentContext.TestDirectory, nameof(TestLoadingOneImage_MileWideTest)));

            d.Create();

            var r = new Random(5000);

            FileInfo[] files;

            using (var g = new DicomDataGenerator(r, d, "CT"))
                files = g.GenerateImageFiles(1, r).ToArray();

            Assert.AreEqual(1, files.Length);

            var existingColumns = _helper.ImageTable.DiscoverColumns();

            //Add 200 random tags
            foreach (string tag in TagColumnAdder.GetAvailableTags().OrderBy(a => r.Next()).Take(200))
            {
                string dataType;

                try
                {
                    dataType = TagColumnAdder.GetDataTypeForTag(tag, new MicrosoftSQLTypeTranslater());
                }
                catch (Exception)
                {
                    continue;
                }

                if (existingColumns.Any(c => c.GetRuntimeName().Equals(tag)))
                {
                    continue;
                }

                var adder = new TagColumnAdder(tag, dataType, _helper.ImageTableInfo, new AcceptAllCheckNotifier());
                adder.SkipChecksAndSynchronization = true;
                adder.Execute();
            }

            new TableInfoSynchronizer(_helper.ImageTableInfo).Synchronize(new AcceptAllCheckNotifier());

            //creates the queues, exchanges and bindings
            var tester = new MicroserviceTester(_globals.RabbitOptions, _globals.DicomRelationalMapperOptions);

            tester.CreateExchange(_globals.RabbitOptions.FatalLoggingExchange, null);

            using (var host = new DicomRelationalMapperHost(_globals))
            {
                host.Start();

                using (var timeline = new TestTimeline(tester))
                {
                    foreach (var f in files)
                    {
                        timeline.SendMessage(_globals.DicomRelationalMapperOptions,
                                             _helper.GetDicomFileMessage(_globals.FileSystemOptions.FileSystemRoot, f));
                    }

                    //start the timeline
                    timeline.StartTimeline();

                    new TestTimelineAwaiter().Await(() => host.Consumer.MessagesProcessed == 1, null, 30000, () => host.Consumer.DleErrors);

                    Assert.GreaterOrEqual(1, _helper.SeriesTable.GetRowCount(), "SeriesTable did not have the expected number of rows in LIVE");
                    Assert.GreaterOrEqual(1, _helper.StudyTable.GetRowCount(), "StudyTable did not have the expected number of rows in LIVE");
                    Assert.AreEqual(1, _helper.ImageTable.GetRowCount(), "ImageTable did not have the expected number of rows in LIVE");

                    host.Stop("Test end");
                }
            }

            tester.Shutdown();
        }