public void CreateFileImporter_Always_ReturnFileImporter() { // Setup var mocks = new MockRepository(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var importTarget = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call IFileImporter importer = updateInfo.CreateFileImporter(importTarget, "test"); // Assert Assert.IsInstanceOf <ProfilesImporter <ForeshoreProfileCollection> >(importer); } mocks.VerifyAll(); }
public void IsEnabled_SourcePathNotSet_ReturnFalse() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call bool isEnabled = updateInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void CurrentPath_ForeshoreProfileCollectionHasPathSet_ReturnsExpectedPath() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); const string expectedFilePath = "some/path"; var foreshoreProfiles = new ForeshoreProfileCollection(); foreshoreProfiles.AddRange(new[] { new TestForeshoreProfile() }, expectedFilePath); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call string currentFilePath = updateInfo.CurrentPath(context); // Assert Assert.AreEqual(expectedFilePath, currentFilePath); mocks.VerifyAll(); } }
public void IsEnabled_ReferenceLineWithoutGeometry_ReturnFalse() { // Setup var mocks = new MockRepository(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); var assessmentSection = mocks.Stub <IAssessmentSection>(); assessmentSection.Stub(a => a.ReferenceLine).Return(new ReferenceLine()); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { ImportInfo importInfo = GetImportInfo(plugin); // Call bool isEnabled = importInfo.IsEnabled(context); // Assert Assert.IsFalse(isEnabled); } mocks.VerifyAll(); }
public void ForeColor_CollectionHasElements_ReturnControlText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var collection = new ForeshoreProfileCollection(); collection.AddRange(new[] { new TestForeshoreProfile() }, "path"); var context = new ForeshoreProfilesContext(collection, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.ControlText), color); mocks.ReplayAll(); }
public void ForeColor_CollectionIsEmpty_ReturnGrayText() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var emptyCollection = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(emptyCollection, failureMechanism, assessmentSection); // Call Color color = info.ForeColor(context); // Assert Assert.AreEqual(Color.FromKnownColor(KnownColor.GrayText), color); mocks.ReplayAll(); }
public void VerifyUpdates_CalculationWithoutOutputs_ReturnsTrue() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var mainWindow = mocks.Stub <IMainWindow>(); IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(g => g.MainWindow).Return(mainWindow); var calculationWithoutOutput = mocks.Stub <ICalculation>(); calculationWithoutOutput.Stub(calc => calc.HasOutput).Return(false); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); failureMechanism.Stub(fm => fm.Calculations).Return(new[] { calculationWithoutOutput }); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); using (var plugin = new RiskeerPlugin()) { plugin.Gui = gui; UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert Assert.IsTrue(updatesVerified); } mocks.VerifyAll(); }
public void Constructor_ValidValues_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); var foreshoresList = new ForeshoreProfileCollection(); // Call var context = new ForeshoreProfilesContext(foreshoresList, failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <WrappedObjectContextBase <ForeshoreProfileCollection> >(context); Assert.AreSame(foreshoresList, context.WrappedData); Assert.AreSame(failureMechanism, context.ParentFailureMechanism); Assert.AreSame(assessmentSection, context.ParentAssessmentSection); mocks.VerifyAll(); }
public void ContextMenuStrip_Always_ReturnContextMenuStrip() { // Setup var mocks = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); var emptyCollection = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(emptyCollection, failureMechanism, assessmentSection); var contextMenuBuilder = mocks.StrictMock <IContextMenuBuilder>(); using (mocks.Ordered()) { contextMenuBuilder.Expect(b => b.AddImportItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddUpdateItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddSeparator()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddCollapseAllItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddExpandAllItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddSeparator()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.AddPropertiesItem()).Return(contextMenuBuilder); contextMenuBuilder.Expect(b => b.Build()).Return(null); } IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(g => g.Get(context, treeViewControl)).Return(contextMenuBuilder); mocks.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(context, null, treeViewControl); // Assert plugin.Dispose(); mocks.VerifyAll(); } }
public void ChildNodeObjects_Always_ReturnChildrenOfCollection() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); mocks.ReplayAll(); ForeshoreProfile profile1 = new TestForeshoreProfile("A", "ID A"); ForeshoreProfile profile2 = new TestForeshoreProfile("B", "ID B"); ForeshoreProfile profile3 = new TestForeshoreProfile("C", "ID C"); var collection = new ForeshoreProfileCollection(); collection.AddRange(new[] { profile1, profile2, profile3 }, "path"); var context = new ForeshoreProfilesContext(collection, failureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(context); // Assert ForeshoreProfile[] expectedChildren = { profile1, profile2, profile3 }; CollectionAssert.AreEqual(expectedChildren, children); mocks.ReplayAll(); }
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 }
public void Import_AllOkTestData_CorrectForeshoreProfileProperties() { // Setup string filePath = TestHelper.GetTestDataPath(TestDataPath.Riskeer.Common.IO, Path.Combine("DikeProfiles", "AllOkTestData", "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 strategy = mockRepository.StrictMock <IForeshoreProfileUpdateDataStrategy>(); var foreshoreProfiles = new ForeshoreProfileCollection(); strategy.Expect(strat => strat.UpdateForeshoreProfilesWithImportedData(null, null)) .IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(filePath, invocation.Arguments[1]); var readForeshoreProfiles = (IEnumerable <ForeshoreProfile>)invocation.Arguments[0]; ForeshoreProfile[] readForeshoreProfilesArray = readForeshoreProfiles.ToArray(); Assert.AreEqual(5, readForeshoreProfilesArray.Length); ForeshoreProfile foreshoreProfile1 = readForeshoreProfilesArray[0]; Assert.AreEqual("profiel001", foreshoreProfile1.Id); Assert.AreEqual("profiel001", foreshoreProfile1.Name); ForeshoreProfile foreshoreProfile2 = readForeshoreProfilesArray[1]; Assert.AreEqual("profiel002", foreshoreProfile2.Id); Assert.AreEqual("profiel002", foreshoreProfile2.Name); ForeshoreProfile foreshoreProfile3 = readForeshoreProfilesArray[2]; Assert.AreEqual("profiel003", foreshoreProfile3.Id); Assert.AreEqual("profiel003", foreshoreProfile3.Name); ForeshoreProfile foreshoreProfile4 = readForeshoreProfilesArray[3]; Assert.AreEqual(new Point2D(136432.12250000238, 538235.26300000318), foreshoreProfile4.WorldReferencePoint); Assert.AreEqual("profiel004", foreshoreProfile4.Id); Assert.AreEqual("Valide naam", foreshoreProfile4.Name); Assert.AreEqual(-17.93475471, foreshoreProfile4.X0); Assert.AreEqual(330.0, foreshoreProfile4.Orientation, foreshoreProfile4.Orientation.GetAccuracy()); Assert.IsFalse(foreshoreProfile4.HasBreakWater); ForeshoreProfile foreshoreProfile5 = readForeshoreProfilesArray[4]; Assert.AreEqual(new Point2D(136039.49100000039, 533920.28050000477), foreshoreProfile5.WorldReferencePoint); Assert.AreEqual("profiel005", foreshoreProfile5.Id); Assert.AreEqual("Heeeeeeeeeeeeeeeeeeeeeeeele laaaaaaaaaaaaaaaaaaaange naaaaaaaaaaam", foreshoreProfile5.Name); Assert.AreEqual(15.56165507, foreshoreProfile5.X0); Assert.AreEqual(330.0, foreshoreProfile5.Orientation, foreshoreProfile5.Orientation.GetAccuracy()); Assert.IsTrue(foreshoreProfile5.HasBreakWater); }); var messageProvider = mockRepository.Stub <IImporterMessageProvider>(); mockRepository.ReplayAll(); var foreshoreProfilesImporter = new ForeshoreProfilesImporter(foreshoreProfiles, referenceLine, filePath, strategy, messageProvider); var targetContext = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); targetContext.Attach(observer); // Call foreshoreProfilesImporter.Import(); // Assert // Assertions are handled in the TearDown // 'observer' should not be notified }
public void VerifyUpdates_CalculationWithOutputs_AlwaysReturnInquiryMessage(bool isActionConfirmed) { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); var mainWindow = mocks.Stub <IMainWindow>(); IGui gui = StubFactory.CreateGuiStub(mocks); gui.Stub(g => g.MainWindow).Return(mainWindow); var calculationWithoutOutput = mocks.Stub <ICalculation>(); calculationWithoutOutput.Stub(calc => calc.HasOutput).Return(true); var failureMechanism = mocks.Stub <ICalculatableFailureMechanism>(); failureMechanism.Stub(fm => fm.Calculations).Return(new[] { calculationWithoutOutput }); mocks.ReplayAll(); var foreshoreProfiles = new ForeshoreProfileCollection(); var context = new ForeshoreProfilesContext(foreshoreProfiles, failureMechanism, assessmentSection); string textBoxMessage = null; DialogBoxHandler = (name, wnd) => { var helper = new MessageBoxTester(wnd); textBoxMessage = helper.Text; if (isActionConfirmed) { helper.ClickOk(); } else { helper.ClickCancel(); } }; using (var plugin = new RiskeerPlugin()) { plugin.Gui = gui; UpdateInfo updateInfo = GetUpdateInfo(plugin); // Call bool updatesVerified = updateInfo.VerifyUpdates(context); // Assert Assert.AreEqual(isActionConfirmed, updatesVerified); string expectedInquiryMessage = "Als voorlandprofielen wijzigen door het bijwerken, " + "dan worden de resultaten van berekeningen die deze voorlandprofielen gebruiken verwijderd." + $"{Environment.NewLine}{Environment.NewLine}Weet u zeker dat u wilt doorgaan?"; Assert.AreEqual(expectedInquiryMessage, textBoxMessage); } mocks.VerifyAll(); }