Example #1
0
        public void Import_ValidFiles_ExpectedProgressNotifications()
        {
            // Setup
            var mocks   = new MockRepository();
            var handler = mocks.Stub <IHydraulicBoundaryDatabaseUpdateHandler>();

            handler.Stub(h => h.IsConfirmationRequired(null, null)).IgnoreArguments().Return(false);
            handler.Stub(h => h.Update(null, null, null, null, null, null)).IgnoreArguments().Return(Enumerable.Empty <IObservable>());
            mocks.ReplayAll();

            var progressChangeNotifications = new List <ProgressNotification>();

            var importer = new HydraulicBoundaryDatabaseImporter(new HydraulicBoundaryDatabase(), handler, validFilePath);

            importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            bool importResult = importer.Import();

            // Assert
            Assert.IsTrue(importResult);
            var expectedProgressNotifications = new[]
            {
                new ProgressNotification("Inlezen van het hydraulische belastingen bestand.", 1, totalNumberOfSteps),
                new ProgressNotification("Inlezen van het hydraulische locatie configuratie bestand.", 2, totalNumberOfSteps),
                new ProgressNotification("Inlezen van het rekeninstellingen bestand.", 3, totalNumberOfSteps),
                new ProgressNotification("Geïmporteerde data toevoegen aan het traject.", 4, totalNumberOfSteps)
            };

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications);
            mocks.VerifyAll();
        }
Example #2
0
        public void Import_WhenSuccessful_GeneratedExpectedProgressMessages()
        {
            // Setup
            var mocks   = new MockRepository();
            var handler = mocks.Stub <IReferenceLineUpdateHandler>();

            handler.Expect(h => h.Update(Arg <ReferenceLine> .Is.NotNull,
                                         Arg <ReferenceLine> .Is.NotNull))
            .Return(Enumerable.Empty <IObservable>());
            mocks.ReplayAll();

            string path = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                     Path.Combine("ReferenceLine", "traject_10-2.shp"));

            var progressChangeNotifications = new List <ProgressNotification>();

            var importer = new ReferenceLineImporter(new ReferenceLine(), handler, path);

            importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            importer.Import();

            // Assert
            var expectedProgressNotifications = new[]
            {
                new ProgressNotification("Inlezen referentielijn.", 1, 2),
                new ProgressNotification("Geïmporteerde data toevoegen aan het traject.", 2, 2)
            };

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications);
            mocks.VerifyAll();
        }
Example #3
0
        public void Import_ImportingFailureMechanismTypeNotInDatabase_ShowProgressAndDoesNotUpdateCollection()
        {
            // Setup
            string    validFilePath = Path.Combine(testDataPath, "complete.soil");
            const int totalNrOfStochasticSoilModelInDatabase = 6;

            var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>();

            filter.Expect(f => f.IsValidForFailureMechanism(null))
            .IgnoreArguments()
            .Return(false)
            .WhenCalled(invocation =>
            {
                FilterFailureMechanismSpecificModel(invocation, FailureMechanismType.None);
            })
            .Repeat
            .Times(totalNrOfStochasticSoilModelInDatabase);
            var messageProvider = mocks.StrictMock <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >();

            mocks.ReplayAll();

            var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>(
                new TestStochasticSoilModelCollection(),
                validFilePath,
                messageProvider,
                new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>(
                    transformer,
                    filter,
                    updateStrategy));

            var progressChangeNotifications = new List <ProgressNotification>();

            importer.SetProgressChanged((description, step, steps) =>
                                        progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            bool importResult = importer.Import();

            // Assert
            Assert.IsFalse(importResult);

            var expectedProgressMessages = new List <ProgressNotification>
            {
                new ProgressNotification("Inlezen van de D-Soil Model database.", 1, 1)
            };

            for (var i = 1; i <= totalNrOfStochasticSoilModelInDatabase; i++)
            {
                expectedProgressMessages.Add(new ProgressNotification(
                                                 "Inlezen van de stochastische ondergrondmodellen.", i, totalNrOfStochasticSoilModelInDatabase));
            }

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);
        }
        public void Import_AllOkTestData_TrueAndLogMessagesAndFiveDikeProfiles()
        {
            // Setup
            const string expectedAddDataToModelProgressText = "Adding data";
            var          messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText);
            mocks.ReplayAll();

            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

            ReferenceLine referenceLine = CreateMatchingReferenceLine();

            var progressChangeNotifications = new List <ProgressNotification>();

            var updateDataStrategy   = new TestDikeProfileUpdateStrategy();
            var dikeProfilesImporter = new DikeProfilesImporter(new DikeProfileCollection(), referenceLine, filePath, updateDataStrategy, messageProvider);

            dikeProfilesImporter.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            var    importResult = false;
            Action call         = () => importResult = dikeProfilesImporter.Import();

            // Assert
            TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{filePath}'.", 1);

            Assert.IsTrue(importResult);
            var expectedProgressMessages = new List <ProgressNotification>
            {
                new ProgressNotification("Inlezen van profiellocaties uit een shapebestand.", 1, 1),
                new ProgressNotification("Inlezen van profiellocatie.", 1, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 2, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 3, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 4, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 5, 5),
                new ProgressNotification("Inlezen van profielgegevens uit een prfl bestand.", 1, 1),
                new ProgressNotification("Inlezen van profielgegevens.", 1, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 2, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 3, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 4, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 5, 5),
                new ProgressNotification(expectedAddDataToModelProgressText, 1, 1)
            };

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);

            Assert.IsTrue(updateDataStrategy.Updated);
            Assert.AreEqual(5, updateDataStrategy.ReadDikeProfiles.Length);
        }
        public void Import_ValidImport_GenerateExpectedProgressMessages()
        {
            // Setup
            var mocks            = new MockRepository();
            var failureMechanism = mocks.Stub <IFailureMechanism>();
            var updateStrategy   = mocks.Stub <IFailureMechanismSectionUpdateStrategy>();

            updateStrategy.Stub(us => us.UpdateSectionsWithImportedData(null, null))
            .IgnoreArguments()
            .Return(Enumerable.Empty <IObservable>());
            var messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddDataToModelProgressText);
            mocks.ReplayAll();

            string referenceLineFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                      Path.Combine("ReferenceLine", "Artificial_referencelijn_testA.shp"));
            string sectionsFilePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                                 Path.Combine("FailureMechanismSections", "Artificial_referencelijn_testA_ValidVakken.shp"));

            ReferenceLine importReferenceLine = ImportReferenceLine(referenceLineFilePath);

            var progressChangeNotifications = new List <ProgressNotification>();

            var importer = new FailureMechanismSectionsImporter(failureMechanism, importReferenceLine, sectionsFilePath, updateStrategy, messageProvider);

            importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            bool importSuccessful = importer.Import();

            // Assert
            Assert.IsTrue(importSuccessful);
            var expectedProgressMessages = new[]
            {
                new ProgressNotification("Inlezen vakindeling.", 1, 3),
                new ProgressNotification("Valideren ingelezen vakindeling.", 2, 3),
                new ProgressNotification(expectedAddDataToModelProgressText, 3, 3)
            };

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);
            mocks.VerifyAll();
        }
        public void GivenImport_WhenImporting_ThenExpectedProgressMessagesGenerated()
        {
            // Given
            string filePath = Path.Combine(readerPath, "validConfiguration.xml");
            var progressChangeNotifications = new List<ProgressNotification>();

            var importer = new CalculationConfigurationImporter(filePath, new CalculationGroup());
            importer.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(
                                            new ProgressNotification(description, step, steps)));

            // When
            importer.Import();

            // Then
            var expectedProgressNotifications = new[]
            {
                new ProgressNotification("Inlezen berekeningenconfiguratie.", 1, 3),
                new ProgressNotification("Valideren berekeningenconfiguratie.", 2, 3),
                new ProgressNotification("Geïmporteerde data toevoegen aan het faalmechanisme.", 3, 3)
            };
            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressNotifications, progressChangeNotifications);
        }
        public void Import_AllDamTypes_TrueAndLogMessagesAndFiveForeshoreProfiles()
        {
            // Setup
            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllDamTypes", "Voorlanden 12-2.shp"));

            var           observer          = mockRepository.StrictMock <IObserver>();
            ReferenceLine referenceLine     = CreateMatchingReferenceLine();
            var           assessmentSection = mockRepository.Stub <IAssessmentSection>();

            assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine);
            var failureMechanism = mockRepository.Stub <ICalculatableFailureMechanism>();

            var foreshoreProfiles = new ForeshoreProfileCollection();
            var strategy          = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>();

            strategy.Expect(strat => strat.UpdateForeshoreProfilesWithImportedData(null, null))
            .IgnoreArguments()
            .WhenCalled(invocation =>
            {
                Assert.AreSame(filePath, invocation.Arguments[1]);

                var readForeshoreProfiles = (IEnumerable <ForeshoreProfile>)invocation.Arguments[0];
                Assert.AreEqual(5, readForeshoreProfiles.Count());
            });

            const string expectedAddingDataToModelMessage = "Adding data to model";
            var          messageProvider = mockRepository.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(expectedAddingDataToModelMessage);
            mockRepository.ReplayAll();

            var progressChangeNotifications = new List <ProgressNotification>();
            var foreshoreProfilesImporter   = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider);

            foreshoreProfilesImporter.SetProgressChanged((description, step, steps) => progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            var targetContext = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection);

            targetContext.Attach(observer);

            // Call
            bool importResult = foreshoreProfilesImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
            var expectedProgressMessages = new List <ProgressNotification>
            {
                new ProgressNotification("Inlezen van profiellocaties uit een shapebestand.", 1, 1),
                new ProgressNotification("Inlezen van profiellocatie.", 1, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 2, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 3, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 4, 5),
                new ProgressNotification("Inlezen van profiellocatie.", 5, 5),
                new ProgressNotification("Inlezen van profielgegevens uit een prfl bestand.", 1, 1),
                new ProgressNotification("Inlezen van profielgegevens.", 1, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 2, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 3, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 4, 5),
                new ProgressNotification("Inlezen van profielgegevens.", 5, 5),
                new ProgressNotification(expectedAddingDataToModelMessage, 1, 1)
            };

            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);
            // 'observer' should not be notified
        }
Example #8
0
        public void Import_VariousFailureMechanismTypes_ShowProgressAndUpdatesCollection(FailureMechanismType failureMechanismType,
                                                                                         int nrOfFailureMechanismSpecificModelsInDatabase)
        {
            // Setup
            string    validFilePath = Path.Combine(testDataPath, "complete.soil");
            const int totalNrOfStochasticSoilModelInDatabase = 6;

            const string expectedAddDataText = "Adding Data";

            var filter = mocks.StrictMock <IStochasticSoilModelMechanismFilter>();

            filter.Expect(f => f.IsValidForFailureMechanism(null))
            .IgnoreArguments()
            .Return(false)
            .WhenCalled(invocation =>
            {
                FilterFailureMechanismSpecificModel(invocation, failureMechanismType);
            })
            .Repeat
            .Times(totalNrOfStochasticSoilModelInDatabase);

            var messageProvider = mocks.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetAddDataToModelProgressText())
            .Return(expectedAddDataText);

            var updateStrategy = mocks.StrictMock <IStochasticSoilModelUpdateModelStrategy <IMechanismStochasticSoilModel> >();

            updateStrategy.Expect(u => u.UpdateModelWithImportedData(null, null))
            .IgnoreArguments()
            .WhenCalled(invocation =>
            {
                var soilModels = (IEnumerable <IMechanismStochasticSoilModel>)invocation.Arguments[0];
                var filePath   = (string)invocation.Arguments[1];

                Assert.AreEqual(nrOfFailureMechanismSpecificModelsInDatabase, soilModels.Count());
                Assert.AreEqual(validFilePath, filePath);
            });

            mocks.ReplayAll();

            var importer = new StochasticSoilModelImporter <IMechanismStochasticSoilModel>(
                new TestStochasticSoilModelCollection(),
                validFilePath,
                messageProvider,
                new StochasticSoilModelImporterConfiguration <IMechanismStochasticSoilModel>(
                    transformer,
                    filter,
                    updateStrategy));

            var progressChangeNotifications = new List <ProgressNotification>();

            importer.SetProgressChanged((description, step, steps) =>
                                        progressChangeNotifications.Add(new ProgressNotification(description, step, steps)));

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{validFilePath}'.", 1);
            Assert.IsTrue(importResult);

            var expectedProgressMessages = new List <ProgressNotification>
            {
                new ProgressNotification("Inlezen van de D-Soil Model database.", 1, 1)
            };

            for (var i = 1; i <= totalNrOfStochasticSoilModelInDatabase; i++)
            {
                expectedProgressMessages.Add(new ProgressNotification(
                                                 "Inlezen van de stochastische ondergrondmodellen.", i, totalNrOfStochasticSoilModelInDatabase));
            }

            for (var i = 1; i <= nrOfFailureMechanismSpecificModelsInDatabase; i++)
            {
                expectedProgressMessages.Add(new ProgressNotification(
                                                 "Valideren van ingelezen data.", i, nrOfFailureMechanismSpecificModelsInDatabase));
            }

            expectedProgressMessages.Add(new ProgressNotification(expectedAddDataText, 1, 1));
            ProgressNotificationTestHelper.AssertProgressNotificationsAreEqual(expectedProgressMessages,
                                                                               progressChangeNotifications);
        }