public void CalculateWaveHeights_ValidPathOneCalculation_LogsMessages() { // Setup const string hydraulicLocationName = "name"; const string calculationIdentifier = "1/100"; var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); var calculatorFactory = mocks.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveHeightCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(new TestWaveHeightCalculator()); mocks.ReplayAll(); assessmentSection.HydraulicBoundaryDatabase.FilePath = validFilePath; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (var viewParent = new TestViewParentForm()) using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); // Call void Call() => guiService.CalculateWaveHeights(new[] { new HydraulicBoundaryLocationCalculation(new TestHydraulicBoundaryLocation(hydraulicLocationName)) }, assessmentSection, 0.01, calculationIdentifier); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(8, msgs.Length); string activityDescription = GetWaveHeightCalculationActivityDescription(hydraulicLocationName, calculationIdentifier); Assert.AreEqual($"{activityDescription} is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[2]); CalculationServiceTestHelper.AssertCalculationStartMessage(msgs[3]); Assert.AreEqual($"Golfhoogte berekening voor locatie 'name' ({calculationIdentifier}) is niet geconvergeerd.", msgs[4]); StringAssert.StartsWith("Golfhoogte berekening is uitgevoerd op de tijdelijke locatie", msgs[5]); CalculationServiceTestHelper.AssertCalculationEndMessage(msgs[6]); Assert.AreEqual($"{activityDescription} is gelukt.", msgs[7]); }); } mocks.VerifyAll(); }
public void CalculateWaveHeights_HydraulicDatabaseDoesNotExist_LogsError() { // Setup var mocks = new MockRepository(); var viewParent = mocks.Stub <IViewParent>(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); mocks.ReplayAll(); assessmentSection.HydraulicBoundaryDatabase.FilePath = "Does not exist"; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); // Call void Call() => guiService.CalculateWaveHeights(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100"); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(1, msgs.Length); StringAssert.StartsWith("Berekeningen konden niet worden gestart. ", msgs.First()); }); mocks.VerifyAll(); }
public void CalculateWaveHeights_ValidPathEmptyCalculationList_NoLog() { // Setup var mocks = new MockRepository(); IAssessmentSection assessmentSection = AssessmentSectionTestHelper.CreateAssessmentSectionStub(mocks); mocks.ReplayAll(); assessmentSection.HydraulicBoundaryDatabase.FilePath = validFilePath; HydraulicBoundaryDatabaseTestHelper.SetHydraulicBoundaryLocationConfigurationSettings(assessmentSection.HydraulicBoundaryDatabase); DialogBoxHandler = (name, wnd) => { // Expect an activity dialog which is automatically closed }; using (var viewParent = new TestViewParentForm()) { var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); // Call void Call() => guiService.CalculateWaveHeights(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), assessmentSection, 0.01, "1/100"); // Assert TestHelper.AssertLogMessagesCount(Call, 0); } mocks.VerifyAll(); }
public void CalculateWaveHeights_AssessmentSectionNull_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var viewParent = mocks.Stub <IViewParent>(); mocks.ReplayAll(); var guiService = new HydraulicBoundaryLocationCalculationGuiService(viewParent); // Call void Call() => guiService.CalculateWaveHeights(Enumerable.Empty <HydraulicBoundaryLocationCalculation>(), null, 0.01, "1/100"); // Assert var exception = Assert.Throws <ArgumentNullException>(Call); Assert.AreEqual("assessmentSection", exception.ParamName); mocks.VerifyAll(); }