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

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

            assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine);

            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());
                }
            });

            var messageProvider = mockRepository.Stub <IImporterMessageProvider>();

            mockRepository.ReplayAll();

            var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath,
                                                                          strategy, messageProvider);

            foreshoreProfilesImporter.SetProgressChanged((description, step, steps) => foreshoreProfilesImporter.Cancel());

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

            Assert.IsFalse(importResult);
            CollectionAssert.IsEmpty(foreshoreProfiles);

            foreshoreProfilesImporter.SetProgressChanged(null);

            // Call
            importResult = foreshoreProfilesImporter.Import();

            // Assert
            Assert.IsTrue(importResult);
        }
        public void Import_CancelOfImportWhileReadingProfileLocations_CancelsImportAndLogs()
        {
            // Setup
            string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO,
                                                         Path.Combine("DikeProfiles", "AllOkTestData", "Voorlanden 12-2.shp"));

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

            assessmentSection.Stub(a => a.ReferenceLine).Return(referenceLine);

            const string cancelledLogMessage = "Operation cancelled";
            var          messageProvider     = mockRepository.StrictMock <IImporterMessageProvider>();

            messageProvider.Expect(mp => mp.GetCancelledLogMessageText("Voorlandprofielen")).Return(cancelledLogMessage);

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

            mockRepository.ReplayAll();

            var foreshoreProfiles         = new ForeshoreProfileCollection();
            var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine,
                                                                          filePath, strategy, messageProvider);

            foreshoreProfilesImporter.SetProgressChanged((description, step, steps) =>
            {
                if (description.Contains("Inlezen van profiellocaties uit een shapebestand."))
                {
                    foreshoreProfilesImporter.Cancel();
                }
            });

            var importResult = true;

            // Call
            Action call = () => importResult = foreshoreProfilesImporter.Import();

            // Assert
            Tuple <string, LogLevelConstant> expectedLogMessage = Tuple.Create(cancelledLogMessage,
                                                                               LogLevelConstant.Info);

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, expectedLogMessage, 1);
            Assert.IsFalse(importResult);
        }
        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
        }