public void ContextMenuStrip_HydraulicBoundaryDatabaseNotLinked_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup var duneLocation = new TestDuneLocation("Test"); var failureMechanism = new DuneErosionFailureMechanism(); var assessmentSection = new AssessmentSectionStub(); failureMechanism.SetDuneLocations(new[] { duneLocation }); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.ViewHost).Return(mocksRepository.Stub <IViewHost>()); mocksRepository.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex, "Alles be&rekenen", "Er is geen hydraulische belastingendatabase geïmporteerd.", RiskeerCommonFormsResources.CalculateAllIcon, false); } } }
public void CreateInstance_WithContext_SetsFailureMechanismAsData() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var plugin = new DuneErosionPlugin()) { PropertyInfo info = GetInfo(plugin); // Call IObjectProperties objectProperties = info.CreateInstance(context); // Assert Assert.IsInstanceOf <DuneErosionFailureMechanismProperties>(objectProperties); Assert.AreSame(failureMechanism, objectProperties.Data); } mocks.VerifyAll(); }
public void ChildNodeObjects_WithContext_ReturnChildDataNodes() { // Setup var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); // Call object[] children = info.ChildNodeObjects(context).ToArray(); // Assert Assert.AreEqual(2, children.Length); var inputsFolder = (CategoryTreeFolder)children[0]; Assert.AreEqual("Invoer", inputsFolder.Name); Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); Assert.AreEqual(1, inputsFolder.Contents.Count()); var calculationsInputComments = (Comment)inputsFolder.Contents.ElementAt(0); Assert.AreSame(failureMechanism.CalculationsInputComments, calculationsInputComments); var targetProbabilitiesGroupContext = (DuneLocationCalculationsForUserDefinedTargetProbabilitiesGroupContext)children[1]; Assert.AreSame(failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities, targetProbabilitiesGroupContext.WrappedData); Assert.AreSame(failureMechanism, targetProbabilitiesGroupContext.FailureMechanism); Assert.AreSame(assessmentSection, targetProbabilitiesGroupContext.AssessmentSection); }
public void ChildNodeObjects_FailureMechanismInAssemblyFalse_ReturnChildDataNodes() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism { InAssembly = false }; var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call object[] children = info.ChildNodeObjects(context).ToArray(); // Assert Assert.AreEqual(1, children.Length); var comment = (Comment)children[0]; Assert.AreSame(failureMechanism.NotInAssemblyComments, comment); } mocks.VerifyAll(); }
public void CreateInstance_WithContext_ReturnDuneFailureMechanismView() { // Setup var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); // Call var view = (DuneErosionFailureMechanismView)info.CreateInstance(context); // Assert Assert.AreSame(failureMechanism, view.FailureMechanism); Assert.AreSame(assessmentSection, view.AssessmentSection); }
public void GetViewName_WithContext_ReturnsNameOfFailureMechanism() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); // Call string viewName = info.GetViewName(null, context); // Assert Assert.AreEqual(failureMechanism.Name, viewName); mocks.VerifyAll(); }
public void ContextMenuStrip_FailureMechanismInAssemblyFalse_CallsContextMenuBuilderMethods() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); using (var treeViewControl = new TreeViewControl()) { var failureMechanism = new DuneErosionFailureMechanism { InAssembly = false }; var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); var menuBuilder = mocks.StrictMock <IContextMenuBuilder>(); using (mocks.Ordered()) { menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } var gui = mocks.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.ViewHost).Return(mocks.Stub <IViewHost>()); mocks.ReplayAll(); using (var plugin = new DuneErosionPlugin()) { plugin.Gui = gui; TreeNodeInfo info = GetInfo(plugin); // Call info.ContextMenuStrip(context, null, treeViewControl); } } // Assert mocks.VerifyAll(); }
public void Constructor_ExpectedValues() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism(); // Call var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); // Assert Assert.IsInstanceOf <FailureMechanismContext <DuneErosionFailureMechanism> >(context); Assert.AreSame(failureMechanism, context.WrappedData); Assert.AreSame(assessmentSection, context.Parent); mocks.VerifyAll(); }
public void ChildNodeObjects_FailureMechanismInAssemblyTrue_ReturnChildDataNodes() { // Setup var assessmentSection = new AssessmentSectionStub(); var failureMechanism = new DuneErosionFailureMechanism(); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call object[] children = info.ChildNodeObjects(context).ToArray(); // Assert Assert.AreEqual(2, children.Length); var inputsFolder = (CategoryTreeFolder)children[0]; Assert.AreEqual("Invoer", inputsFolder.Name); Assert.AreEqual(TreeFolderCategory.Input, inputsFolder.Category); Assert.AreEqual(2, inputsFolder.Contents.Count()); var failureMechanismSectionsContext = (FailureMechanismSectionsContext)inputsFolder.Contents.ElementAt(0); Assert.AreSame(failureMechanism, failureMechanismSectionsContext.WrappedData); Assert.AreSame(assessmentSection, failureMechanismSectionsContext.AssessmentSection); var inAssemblyInputComments = (Comment)inputsFolder.Contents.ElementAt(1); Assert.AreSame(failureMechanism.InAssemblyInputComments, inAssemblyInputComments); var outputsFolder = (CategoryTreeFolder)children[1]; Assert.AreEqual("Oordeel", outputsFolder.Name); Assert.AreEqual(TreeFolderCategory.Output, outputsFolder.Category); Assert.AreEqual(2, outputsFolder.Contents.Count()); var failureMechanismResultsContext = (DuneErosionFailureMechanismSectionResultContext)outputsFolder.Contents.ElementAt(0); Assert.AreSame(failureMechanism, failureMechanismResultsContext.FailureMechanism); Assert.AreSame(assessmentSection, failureMechanismResultsContext.AssessmentSection); Assert.AreSame(failureMechanism.SectionResults, failureMechanismResultsContext.WrappedData); var inAssemblyOutputComments = (Comment)outputsFolder.Contents.ElementAt(1); Assert.AreSame(failureMechanism.InAssemblyOutputComments, inAssemblyOutputComments); } }
public void ContextMenuStrip_NoDuneLocationsPresent_ContextMenuItemCalculateAllDisabledAndTooltipSet() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite") } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); var mocks = new MockRepository(); using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.ViewHost).Return(mocksRepository.Stub <IViewHost>()); mocksRepository.ReplayAll(); plugin.Gui = gui; // Call using (ContextMenuStrip contextMenu = info.ContextMenuStrip(context, null, treeViewControl)) { // Assert TestHelper.AssertContextMenuStripContainsItem(contextMenu, contextMenuCalculateAllIndex, "Alles be&rekenen", "Geen van de locaties is geschikt voor een hydraulische belastingenberekening.", RiskeerCommonFormsResources.CalculateAllIcon, false); } } mocks.VerifyAll(); }
public void ContextMenuStrip_WithContext_CallsContextMenuBuilderMethods() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocksRepository); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); var orderMocksRepository = new MockRepository(); var menuBuilder = orderMocksRepository.StrictMock <IContextMenuBuilder>(); using (orderMocksRepository.Ordered()) { menuBuilder.Expect(mb => mb.AddOpenItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCustomItem(null)).IgnoreArguments().Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddCollapseAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddExpandAllItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddSeparator()).Return(menuBuilder); menuBuilder.Expect(mb => mb.AddPropertiesItem()).Return(menuBuilder); menuBuilder.Expect(mb => mb.Build()).Return(null); } orderMocksRepository.ReplayAll(); using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub <IGui>(); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(menuBuilder); gui.Stub(g => g.ViewHost).Return(mocksRepository.Stub <IViewHost>()); mocksRepository.ReplayAll(); plugin.Gui = gui; // Call info.ContextMenuStrip(context, null, treeViewControl); } // Assert orderMocksRepository.VerifyAll(); }
public void AdditionalDataCheck_Always_ReturnTrueOnlyIfFailureMechanismInAssembly(bool inAssembly) { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new DuneErosionFailureMechanism { InAssembly = inAssembly }; var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); // Call bool result = info.AdditionalDataCheck(context); // Assert Assert.AreEqual(inAssembly, result); mocks.VerifyAll(); }
public void CloseForData_ViewNotCorrespondingToRemovedFailureMechanismContext_ReturnsFalse() { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var context = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), assessmentSection); var failureMechanism = new DuneErosionFailureMechanism(); using (var view = new NonAdoptableFailureMechanismResultView <DuneErosionFailureMechanism>( failureMechanism.SectionResults, failureMechanism, assessmentSection, (fm, ass) => new FailureMechanismAssemblyResultWrapper(double.NaN, AssemblyMethod.Manual))) { // Call bool closeForData = info.CloseForData(view, context); // Assert Assert.IsFalse(closeForData); mocks.VerifyAll(); } }
public void Text_WithContext_ReturnsName() { // Setup var mocks = new MockRepository(); var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var context = new DuneErosionFailureMechanismContext(new DuneErosionFailureMechanism(), assessmentSection); using (var plugin = new DuneErosionPlugin()) { TreeNodeInfo info = GetInfo(plugin); // Call string text = info.Text(context); // Assert Assert.AreEqual("Duinafslag", text); } mocks.VerifyAll(); }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled() { // Given var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = Path.Combine(testDataPath, "HRD dutch coast south.sqlite") } }; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(0.1), new DuneLocationCalculationsForTargetProbability(0.01) } }; var duneLocation = new TestDuneLocation("Test"); failureMechanism.SetDuneLocations(new[] { duneLocation }); var context = new DuneErosionFailureMechanismContext(failureMechanism, assessmentSection); using (var treeViewControl = new TreeViewControl()) { var gui = mocksRepository.Stub <IGui>(); IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocksRepository); gui.Stub(g => g.MainWindow).Return(mainWindow); gui.Stub(cmp => cmp.Get(context, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.DocumentViewController).Return(mocksRepository.Stub <IDocumentViewController>()); gui.Stub(g => g.ViewHost).Return(mocksRepository.Stub <IViewHost>()); var calculatorFactory = mocksRepository.Stub <IHydraRingCalculatorFactory>(); var dunesBoundaryConditionsCalculator = new TestDunesBoundaryConditionsCalculator { Converged = false }; calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(dunesBoundaryConditionsCalculator).Repeat.Times(2); mocksRepository.ReplayAll(); plugin.Gui = gui; plugin.Activate(); using (ContextMenuStrip contextMenuAdapter = info.ContextMenuStrip(context, null, treeViewControl)) using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // When void Call() => contextMenuAdapter.Items[contextMenuCalculateAllIndex].PerformClick(); // Then TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(16, msgs.Length); const string calculationTypeDisplayName = "Hydraulische belastingen"; const string calculationDisplayName = "Hydraulische belastingenberekening"; HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/10", msgs, 0); HydraulicBoundaryLocationCalculationActivityLogTestHelper.AssertHydraulicBoundaryLocationCalculationMessages( duneLocation.Name, calculationTypeDisplayName, calculationDisplayName, "1/100", msgs, 8); }); } } }