public void CalculateForSelectedButton_OneSelected_CallsCalculateWaveHeights() { // Setup IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations(); WaveHeightCalculationsView view = ShowFullyConfiguredWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, testForm); DataGridViewControl calculationsDataGridViewControl = GetCalculationsDataGridViewControl(); DataGridViewRowCollection rows = calculationsDataGridViewControl.Rows; rows[0].Cells[calculateColumnIndex].Value = true; var guiService = mockRepository.StrictMock <IHydraulicBoundaryLocationCalculationGuiService>(); HydraulicBoundaryLocationCalculation[] performedCalculations = null; guiService.Expect(ch => ch.CalculateWaveHeights(null, null, int.MinValue, null)).IgnoreArguments().WhenCalled( invocation => { performedCalculations = ((IEnumerable <HydraulicBoundaryLocationCalculation>)invocation.Arguments[0]).ToArray(); }); mockRepository.ReplayAll(); view.CalculationGuiService = guiService; var buttonTester = new ButtonTester("CalculateForSelectedButton", testForm); // Call buttonTester.Click(); // Assert Assert.AreEqual(1, performedCalculations.Length); Assert.AreSame(hydraulicBoundaryLocationCalculations.First(), performedCalculations.First()); }
public void WaveHeightCalculationsView_CalculationUpdated_DataGridViewCorrectlyUpdated() { // Setup IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations(); ShowFullyConfiguredWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, testForm); // Precondition DataGridViewControl calculationsDataGridViewControl = GetCalculationsDataGridViewControl(); DataGridViewRowCollection rows = calculationsDataGridViewControl.Rows; DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(6, cells.Count); Assert.AreEqual(false, cells[includeIllustrationPointsColumnIndex].FormattedValue); HydraulicBoundaryLocationCalculation calculation = hydraulicBoundaryLocationCalculations.First(); // Call calculation.InputParameters.ShouldIllustrationPointsBeCalculated = true; calculation.NotifyObservers(); // Assert Assert.AreEqual(true, cells[includeIllustrationPointsColumnIndex].FormattedValue); }
public void UpdateSectionsWithImportedData_WithValidData_SetsSectionsToFailureMechanismAndCopiesPropertiesOfEqualSectionsAndReturnsAffectedObjects() { // Setup string sourcePath = TestHelper.GetScratchPadPath(); var failureMechanism = new TestFailureMechanism(); FailureMechanismSection failureMechanismSection1 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 5.0) }); FailureMechanismSection failureMechanismSection2 = FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(5.0, 5.0), new Point2D(10.0, 10.0) }); failureMechanism.SetSections(new[] { failureMechanismSection1, failureMechanismSection2 }, sourcePath); IObservableEnumerable <FailureMechanismSectionResult> failureMechanismSectionResults = failureMechanism.SectionResults; FailureMechanismSectionResult oldSectionResult = failureMechanismSectionResults.First(); var sectionResultUpdateStrategy = new TestUpdateFailureMechanismSectionResultUpdateStrategy(); var failureMechanismSectionUpdateStrategy = new FailureMechanismSectionUpdateStrategy <FailureMechanismSectionResult>(failureMechanism, sectionResultUpdateStrategy); FailureMechanismSection[] sections = { FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(0.0, 0.0), new Point2D(5.0, 5.0) }), FailureMechanismSectionTestFactory.CreateFailureMechanismSection(new[] { new Point2D(5.0, 5.0), new Point2D(15.0, 15.0) }) }; // Call IEnumerable <IObservable> affectedObjects = failureMechanismSectionUpdateStrategy.UpdateSectionsWithImportedData(sections, sourcePath); // Assert Assert.AreEqual(sourcePath, failureMechanism.FailureMechanismSectionSourcePath); IEnumerable <FailureMechanismSection> failureMechanismSections = failureMechanism.Sections; Assert.AreEqual(2, failureMechanismSections.Count()); CollectionAssert.AreEqual(sections, failureMechanismSections); Assert.AreSame(oldSectionResult, sectionResultUpdateStrategy.Origin); Assert.AreSame(failureMechanismSectionResults.First(), sectionResultUpdateStrategy.Target); CollectionAssert.AreEqual(new IObservable[] { failureMechanism, failureMechanism.SectionResults }, affectedObjects); }
public void CalculateForSelectedButton_Always_CalculateWaveHeightsCalledAsExpected() { // Setup const string databaseFilePath = "DatabaseFilePath"; const double targetProbability = 0.01; const string calculationIdentifier = "1/100"; var assessmentSection = mockRepository.Stub <IAssessmentSection>(); var hydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { FilePath = databaseFilePath }; assessmentSection.Stub(a => a.HydraulicBoundaryDatabase).Return(hydraulicBoundaryDatabase); assessmentSection.Stub(a => a.Id).Return(string.Empty); assessmentSection.Stub(a => a.FailureMechanismContribution) .Return(FailureMechanismContributionTestFactory.CreateFailureMechanismContribution()); assessmentSection.Stub(a => a.Attach(null)).IgnoreArguments(); assessmentSection.Stub(a => a.Detach(null)).IgnoreArguments(); var guiService = mockRepository.StrictMock <IHydraulicBoundaryLocationCalculationGuiService>(); IAssessmentSection assessmentSectionValue = null; HydraulicBoundaryLocationCalculation[] performedCalculations = null; double targetProbabilityValue = double.NaN; string calculationIdentifierValue = null; guiService.Expect(ch => ch.CalculateWaveHeights(null, null, int.MinValue, null)).IgnoreArguments().WhenCalled( invocation => { performedCalculations = ((IEnumerable <HydraulicBoundaryLocationCalculation>)invocation.Arguments[0]).ToArray(); assessmentSectionValue = (IAssessmentSection)invocation.Arguments[1]; targetProbabilityValue = (double)invocation.Arguments[2]; calculationIdentifierValue = (string)invocation.Arguments[3]; }); mockRepository.ReplayAll(); IObservableEnumerable <HydraulicBoundaryLocationCalculation> hydraulicBoundaryLocationCalculations = GetTestHydraulicBoundaryLocationCalculations(); WaveHeightCalculationsView view = ShowWaveHeightCalculationsView(hydraulicBoundaryLocationCalculations, assessmentSection, targetProbability, calculationIdentifier, testForm); DataGridView calculationsDataGridView = GetCalculationsDataGridView(); DataGridViewRowCollection rows = calculationsDataGridView.Rows; rows[0].Cells[calculateColumnIndex].Value = true; view.CalculationGuiService = guiService; var button = new ButtonTester("CalculateForSelectedButton", testForm); // Call button.Click(); // Assert Assert.AreEqual(calculationIdentifier, calculationIdentifierValue); Assert.AreSame(assessmentSection, assessmentSectionValue); Assert.AreEqual(targetProbability, targetProbabilityValue); Assert.AreEqual(1, performedCalculations.Length); Assert.AreSame(hydraulicBoundaryLocationCalculations.First(), performedCalculations.First()); }