public void Run_HydraulicBoundaryDatabaseWithCanUsePreprocessorFalse_CreateWaveConditionsCosineCalculatorAsExpected() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(GetWaterLevels(calculation, assessmentSection).Count()); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); } // Assert mockRepository.VerifyAll(); }
public void CreateCalculationActivitiesForFailureMechanism_WithValidData_ExpectedInputSetToActivities() { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(); WaveImpactAsphaltCoverFailureMechanism failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation("locationName 1"); SetHydraulicBoundaryLocationToAssessmentSection(assessmentSection, hydraulicBoundaryLocation); WaveImpactAsphaltCoverWaveConditionsCalculation calculation1 = CreateValidCalculation(hydraulicBoundaryLocation); WaveImpactAsphaltCoverWaveConditionsCalculation calculation2 = CreateValidCalculation(hydraulicBoundaryLocation); failureMechanism.CalculationsGroup.Children.AddRange(new[] { calculation1, calculation2 }); // Call IEnumerable <CalculatableActivity> activities = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivities( failureMechanism, assessmentSection); // Assert CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(WaveImpactAsphaltCoverWaveConditionsCalculationActivity)); Assert.AreEqual(2, activities.Count()); RoundedDouble assessmentLevel = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result; HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; AssertWaveImpactAsphaltCoverWaveConditionsCalculationActivity(activities.ElementAt(0), calculation1, assessmentLevel, hydraulicBoundaryDatabase); AssertWaveImpactAsphaltCoverWaveConditionsCalculationActivity(activities.ElementAt(1), calculation2, assessmentLevel, hydraulicBoundaryDatabase); }
public void IsEnabled_CalculationWithOrWithoutOutput_ReturnExpectedEnabledState(bool hasOutput) { // Setup var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var calculationGroup = new CalculationGroup(); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); if (hasOutput) { var output = new[] { new TestWaveConditionsOutput() }; calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(output); } calculationGroup.Children.Add(calculation); var context = new WaveImpactAsphaltCoverCalculationGroupContext(calculationGroup, null, failureMechanism, assessmentSection); // Call bool isEnabled = info.IsEnabled(context); // Assert Assert.AreEqual(hasOutput, isEnabled); }
private ContextMenuStrip WaveConditionsCalculationContextContextMenuStrip(WaveImpactAsphaltCoverWaveConditionsCalculationContext nodeData, object parentData, TreeViewControl treeViewControl) { var builder = new RiskeerContextMenuBuilder(Gui.Get(nodeData, treeViewControl)); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = nodeData.WrappedData; return(builder.AddExportItem() .AddSeparator() .AddDuplicateCalculationItem(calculation, nodeData) .AddSeparator() .AddRenameItem() .AddUpdateForeshoreProfileOfCalculationItem(calculation, GetInquiryHelper(), SynchronizeCalculationWithForeshoreProfileHelper.UpdateForeshoreProfileDerivedCalculationInput) .AddSeparator() .AddValidateCalculationItem(nodeData, Validate, EnableValidateAndCalculateMenuItemForCalculation) .AddPerformCalculationItem <WaveImpactAsphaltCoverWaveConditionsCalculation, WaveImpactAsphaltCoverWaveConditionsCalculationContext>( nodeData, Calculate, EnableValidateAndCalculateMenuItemForCalculation) .AddSeparator() .AddClearCalculationOutputItem(calculation) .AddDeleteItem() .AddSeparator() .AddCollapseAllItem() .AddExpandAllItem() .AddSeparator() .AddPropertiesItem() .Build()); }
public void RevetmentType_SetNewValue_ThrowsInvalidOperationException() { // Setup var mockRepository = new MockRepository(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); var handler = mockRepository.Stub <IObservablePropertyChangeHandler>(); mockRepository.ReplayAll(); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); var context = new WaveImpactAsphaltCoverWaveConditionsInputContext( calculation.InputParameters, calculation, assessmentSection, Enumerable.Empty <ForeshoreProfile>()); var properties = new WaveImpactAsphaltCoverWaveConditionsInputContextProperties( context, AssessmentSectionTestHelper.GetTestAssessmentLevel, handler); // Call TestDelegate test = () => properties.RevetmentType = string.Empty; // Assert Assert.Throws <InvalidOperationException>(test); mockRepository.VerifyAll(); }
public void Run_CalculationPerformed_SetsOutput() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = CreateValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); CalculatableActivity activity = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(GetWaterLevels(calculation, assessmentSection).Count()); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call activity.Run(); // Assert Assert.IsNotNull(calculation.Output); Assert.AreEqual(3, calculation.Output.Items.Count()); } mockRepository.VerifyAll(); }
public void Create_HasHydraulicLocationCalculationsForTargetProbability_EntityHasHydraulicLocationCalculationForTargetProbabilityCollectionEntity() { // Setup var random = new Random(21); var hydraulicCalculations = new HydraulicBoundaryLocationCalculationsForTargetProbability(random.NextDouble(0, 0.1)); var hydraulicCalculationsEntity = new HydraulicLocationCalculationForTargetProbabilityCollectionEntity(); var registry = new PersistenceRegistry(); registry.Register(hydraulicCalculationsEntity, hydraulicCalculations); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { InputParameters = { CalculationsTargetProbability = hydraulicCalculations } }; // Call WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 0); // Assert Assert.AreSame(hydraulicCalculationsEntity, entity.HydraulicLocationCalculationForTargetProbabilityCollectionEntity); }
public void Calculate_WithValidInput_SetsOutput() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(3); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate( calculation, assessmentSection, waveImpactAsphaltCoverFailureMechanism.GeneralInput); // Assert Assert.IsNotNull(calculation.Output); Assert.AreEqual(3, calculation.Output.Items.Count()); } mockRepository.VerifyAll(); }
public void Calculate_Canceled_HasNoOutput() { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetDefaultCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { var waveImpactAsphaltCoverWaveConditionsCalculationService = new WaveImpactAsphaltCoverWaveConditionsCalculationService(); waveImpactAsphaltCoverWaveConditionsCalculationService.Cancel(); // Call waveImpactAsphaltCoverWaveConditionsCalculationService.Calculate( calculation, assessmentSection, waveImpactAsphaltCoverFailureMechanism.GeneralInput); // Assert Assert.IsFalse(calculation.HasOutput); } mockRepository.VerifyAll(); }
public void CreateCalculationActivitiesForCalculationGroup_WithValidCalculations_ReturnsWaveImpactAsphaltCoverWaveConditionsCalculationActivitiesWithParametersSet() { // Setup WaveImpactAsphaltCoverFailureMechanism failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); AssessmentSectionStub assessmentSection = CreateAssessmentSection(); var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); SetHydraulicBoundaryLocationToAssessmentSection(assessmentSection, hydraulicBoundaryLocation); WaveImpactAsphaltCoverWaveConditionsCalculation calculation1 = CreateValidCalculation(hydraulicBoundaryLocation); WaveImpactAsphaltCoverWaveConditionsCalculation calculation2 = CreateValidCalculation(hydraulicBoundaryLocation); var calculations = new CalculationGroup { Children = { calculation1, calculation2 } }; // Call IEnumerable <CalculatableActivity> activities = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivities( calculations, failureMechanism, assessmentSection); // Assert CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(WaveImpactAsphaltCoverWaveConditionsCalculationActivity)); Assert.AreEqual(2, activities.Count()); RoundedDouble assessmentLevel = assessmentSection.WaterLevelCalculationsForSignalFloodingProbability.Single().Output.Result; HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; AssertWaveImpactAsphaltCoverWaveConditionsCalculationActivity(activities.First(), calculation1, assessmentLevel, hydraulicBoundaryDatabase); AssertWaveImpactAsphaltCoverWaveConditionsCalculationActivity(activities.ElementAt(1), calculation2, assessmentLevel, hydraulicBoundaryDatabase); }
/// <summary> /// Method that asserts whether <paramref name="original"/> and <paramref name="clone"/> /// are clones. /// </summary> /// <param name="original">The original object.</param> /// <param name="clone">The cloned object.</param> /// <exception cref="AssertionException">Thrown when <paramref name="original"/> and /// <paramref name="clone"/> are not clones.</exception> public static void AreClones(WaveImpactAsphaltCoverWaveConditionsCalculation original, WaveImpactAsphaltCoverWaveConditionsCalculation clone) { Assert.AreEqual(original.Name, clone.Name); CoreCloneAssert.AreObjectClones(original.Comments, clone.Comments, CommonCloneAssert.AreClones); CoreCloneAssert.AreObjectClones(original.InputParameters, clone.InputParameters, WaveConditionsCloneAssert.AreClones); CoreCloneAssert.AreObjectClones(original.Output, clone.Output, AreClones); }
public void CreateInstance_WaveImpactAsphaltCoverWaveConditionsInputContext_ReturnViewWithStylingApplied() { // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); var context = new WaveImpactAsphaltCoverWaveConditionsInputContext( new WaveConditionsInput(), calculation, new AssessmentSectionStub(), Array.Empty <ForeshoreProfile>()); // Call var view = (WaveConditionsInputView)info.CreateInstance(context); // Assert ChartDataCollection chartData = view.Chart.Data; var lowerBoundaryRevetmentChartData = (ChartLineData)chartData.Collection.ElementAt(lowerBoundaryRevetmentChartDataIndex); var upperBoundaryRevetmentChartData = (ChartLineData)chartData.Collection.ElementAt(upperBoundaryRevetmentChartDataIndex); var revetmentBaseChartData = (ChartLineData)chartData.Collection.ElementAt(revetmentBaseChartDataIndex); var revetmentChartData = (ChartLineData)chartData.Collection.ElementAt(revetmentChartDataIndex); Color revetmentLineColor = Color.Gray; Assert.AreEqual(revetmentLineColor, lowerBoundaryRevetmentChartData.Style.Color); Assert.AreEqual(revetmentLineColor, upperBoundaryRevetmentChartData.Style.Color); Assert.AreEqual(Color.FromArgb(120, revetmentLineColor), revetmentBaseChartData.Style.Color); Assert.AreEqual(revetmentLineColor, revetmentChartData.Style.Color); }
/// <summary> /// Creates a <see cref="WaveImpactAsphaltCoverWaveConditionsCalculationEntity"/> based on the information of the /// <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/>. /// </summary> /// <param name="calculation">The calculation to create a database entity for.</param> /// <param name="registry">The object keeping track of create operations.</param> /// <param name="order">The index at which <paramref name="calculation"/> resides within its parent.</param> /// <returns>A new <see cref="WaveImpactAsphaltCoverWaveConditionsCalculationEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> internal static WaveImpactAsphaltCoverWaveConditionsCalculationEntity Create(this WaveImpactAsphaltCoverWaveConditionsCalculation calculation, PersistenceRegistry registry, int order) { if (calculation == null) { throw new ArgumentNullException(nameof(calculation)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity { Order = order, Name = calculation.Name.DeepClone(), Comments = calculation.Comments.Body.DeepClone() }; SetInputParameters(entity, calculation.InputParameters, registry); AddEntityForWaveImpactAsphaltCoverWaveConditionsOutput(calculation, entity); return(entity); }
private static WaveImpactAsphaltCoverFailureMechanism CreateWaveImpactAsphaltCoverFailureMechanismWithAllUpdateForeshoreProfileScenarios( ForeshoreProfile unaffectedForeshoreProfile) { WaveImpactAsphaltCoverFailureMechanism waveImpactAsphaltCoverFailureMechanism = TestDataGenerator.GetWaveImpactAsphaltCoverFailureMechanismWithAllCalculationConfigurations(); waveImpactAsphaltCoverFailureMechanism.ForeshoreProfiles.AddRange(new[] { unaffectedForeshoreProfile }, sourceFilePath); var unaffectedCalculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { InputParameters = { ForeshoreProfile = unaffectedForeshoreProfile }, Output = new WaveImpactAsphaltCoverWaveConditionsOutput(new[] { new TestWaveConditionsOutput() }) }; waveImpactAsphaltCoverFailureMechanism.CalculationsGroup.Children.Add(unaffectedCalculation); return(waveImpactAsphaltCoverFailureMechanism); }
public void CreateInstance_WithContextThatHasInputWithSpecificWaterLevelType_ReturnViewWithCorrespondingAssessmentLevel( IAssessmentSection assessmentSection, Action <WaveConditionsInput> configureInputAction, RoundedDouble expectedAssessmentLevel) { // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); configureInputAction(calculation.InputParameters); var context = new WaveImpactAsphaltCoverWaveConditionsInputContext( calculation.InputParameters, calculation, assessmentSection, Array.Empty <ForeshoreProfile>()); // Call var view = (WaveConditionsInputView)info.CreateInstance(context); // Assert ChartDataCollection chartData = view.Chart.Data; var designWaterLevelChartData = (ChartLineData)chartData.Collection.ElementAt(designWaterLevelChartDataIndex); if (expectedAssessmentLevel != RoundedDouble.NaN) { Assert.AreEqual(expectedAssessmentLevel, designWaterLevelChartData.Points.First().Y); } else { Assert.IsEmpty(designWaterLevelChartData.Points); } }
/// <summary> /// Reads the <see cref="WaveImpactAsphaltCoverWaveConditionsCalculationEntity"/> and use the /// information to update a <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/>. /// </summary> /// <param name="entity"> /// The <see cref="WaveImpactAsphaltCoverWaveConditionsCalculationEntity"/> /// to create <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/> for. /// </param> /// <param name="collector">The object keeping track of read operations.</param> /// <returns>A new <see cref="WaveImpactAsphaltCoverWaveConditionsCalculation"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> internal static WaveImpactAsphaltCoverWaveConditionsCalculation Read(this WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity, ReadConversionCollector collector) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (collector == null) { throw new ArgumentNullException(nameof(collector)); } var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { Name = entity.Name, Comments = { Body = entity.Comments } }; ReadInputParameters(calculation.InputParameters, entity, collector); ReadOutput(calculation, entity); return(calculation); }
public void CreateInstance_WithContextThatHasInputWithSpecificWaterLevelType_ExpectedProperties( IAssessmentSection assessmentSection, Action <WaveConditionsInput> configureInputAction, RoundedDouble expectedAssessmentLevel) { // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); configureInputAction(calculation.InputParameters); var context = new WaveImpactAsphaltCoverWaveConditionsInputContext(calculation.InputParameters, calculation, assessmentSection, Array.Empty <ForeshoreProfile>()); using (var plugin = new WaveImpactAsphaltCoverPlugin()) { PropertyInfo info = GetInfo(plugin); // Call IObjectProperties objectProperties = info.CreateInstance(context); // Assert Assert.IsInstanceOf <WaveImpactAsphaltCoverWaveConditionsInputContextProperties>(objectProperties); Assert.AreSame(context, objectProperties.Data); Assert.AreEqual(expectedAssessmentLevel, ((WaveImpactAsphaltCoverWaveConditionsInputContextProperties)objectProperties).AssessmentLevel); } }
public void Constructor_ExpectedValues() { // Setup var mockRepository = new MockRepository(); var assessmentSection = mockRepository.Stub <IAssessmentSection>(); var handler = mockRepository.Stub <IObservablePropertyChangeHandler>(); mockRepository.ReplayAll(); var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation(); var context = new WaveImpactAsphaltCoverWaveConditionsInputContext( calculation.InputParameters, calculation, assessmentSection, Enumerable.Empty <ForeshoreProfile>()); // Call var properties = new WaveImpactAsphaltCoverWaveConditionsInputContextProperties( context, AssessmentSectionTestHelper.GetTestAssessmentLevel, handler); // Assert Assert.IsInstanceOf <WaveConditionsInputContextProperties <WaveImpactAsphaltCoverWaveConditionsInputContext, WaveConditionsInput, string> >(properties); Assert.AreSame(context, properties.Data); Assert.AreEqual("Asfalt", properties.RevetmentType); mockRepository.VerifyAll(); }
public void CreateCalculationFeatures_GivenCalculations_ReturnsCalculationFeaturesCollection() { // Setup var calculationA = new WaveImpactAsphaltCoverWaveConditionsCalculation(); var calculationB = new WaveImpactAsphaltCoverWaveConditionsCalculation(); calculationA.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.0, 3.0)); calculationB.InputParameters.ForeshoreProfile = new TestForeshoreProfile(new Point2D(1.0, 4.0)); calculationA.InputParameters.HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 5.0, 4.0); calculationB.InputParameters.HydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, string.Empty, 2.2, 3.8); // Call IEnumerable <MapFeature> features = WaveImpactAsphaltCoverMapDataFeaturesFactory.CreateCalculationFeatures(new[] { calculationA, calculationB }); // Assert Assert.AreEqual(2, features.Count()); Assert.AreEqual(1, features.ElementAt(0).MapGeometries.Count()); Assert.AreEqual(1, features.ElementAt(1).MapGeometries.Count()); AssertEqualPointCollections(new[] { new Point2D(1.0, 3.0), new Point2D(5.0, 4.0) }, features.ElementAt(0).MapGeometries.ElementAt(0)); AssertEqualPointCollections(new[] { new Point2D(1.0, 4.0), new Point2D(2.2, 3.8) }, features.ElementAt(1).MapGeometries.ElementAt(0)); }
public void Create_CalculationWithNaNProperties_ReturnCalculationEntity() { // Setup var calculation = new WaveImpactAsphaltCoverWaveConditionsCalculation { InputParameters = { Orientation = RoundedDouble.NaN, UpperBoundaryRevetment = RoundedDouble.NaN, LowerBoundaryRevetment = RoundedDouble.NaN, UpperBoundaryWaterLevels = RoundedDouble.NaN, LowerBoundaryWaterLevels = RoundedDouble.NaN, BreakWater = { Height = RoundedDouble.NaN } } }; var registry = new PersistenceRegistry(); // Call WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity = calculation.Create(registry, 1234); // Assert Assert.IsNull(entity.Orientation); Assert.IsNull(entity.UpperBoundaryRevetment); Assert.IsNull(entity.LowerBoundaryRevetment); Assert.IsNull(entity.UpperBoundaryWaterLevels); Assert.IsNull(entity.LowerBoundaryWaterLevels); Assert.IsNull(entity.BreakWaterHeight); }
public void Read_EntityWithNullValues_ReturnCalculationWithNaNValues() { // Setup var entity = new WaveImpactAsphaltCoverWaveConditionsCalculationEntity(); var collector = new ReadConversionCollector(); // Call WaveImpactAsphaltCoverWaveConditionsCalculation calculation = entity.Read(collector); // Assert Assert.IsNull(calculation.Name); Assert.IsNull(calculation.Comments.Body); WaveConditionsInput calculationInput = calculation.InputParameters; Assert.IsNaN(calculationInput.BreakWater.Height); Assert.IsNaN(calculationInput.Orientation); Assert.IsNaN(calculationInput.UpperBoundaryRevetment); Assert.IsNaN(calculationInput.LowerBoundaryRevetment); Assert.IsNaN(calculationInput.UpperBoundaryWaterLevels); Assert.IsNaN(calculationInput.LowerBoundaryWaterLevels); Assert.IsNull(calculationInput.HydraulicBoundaryLocation); Assert.IsNull(calculationInput.ForeshoreProfile); Assert.IsNull(calculation.Output); }
public DerivedWaveImpactAsphaltCoverWaveConditionsCalculationContext(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, CalculationGroup parent, WaveImpactAsphaltCoverFailureMechanism failureMechanism, IAssessmentSection assessmentSection) : base(calculation, parent, failureMechanism, assessmentSection) { }
public void Calculate_Always_InputPropertiesCorrectlySentToCalculator(BreakWaterType breakWaterType) { // Setup IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(assessmentSection.HydraulicBoundaryDatabase.Locations.First()); calculation.InputParameters.BreakWater.Type = breakWaterType; var waveImpactAsphaltCoverFailureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); var calculator = new TestWaveConditionsCosineCalculator(); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(null)) .IgnoreArguments() .Return(calculator) .Repeat .Times(3); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new WaveImpactAsphaltCoverWaveConditionsCalculationService().Calculate( calculation, assessmentSection, waveImpactAsphaltCoverFailureMechanism.GeneralInput); // Assert WaveConditionsCosineCalculationInput[] waveConditionsInputs = calculator.ReceivedInputs.ToArray(); Assert.AreEqual(3, waveConditionsInputs.Length); var waterLevelIndex = 0; foreach (WaveConditionsCosineCalculationInput actualInput in waveConditionsInputs) { GeneralWaveConditionsInput generalInput = waveImpactAsphaltCoverFailureMechanism.GeneralInput; WaveConditionsInput input = calculation.InputParameters; var expectedInput = new WaveConditionsCosineCalculationInput(1, input.Orientation, input.HydraulicBoundaryLocation.Id, assessmentSection.FailureMechanismContribution.MaximumAllowableFloodingProbability, input.ForeshoreProfile.Geometry.Select(c => new HydraRingForelandPoint(c.X, c.Y)), new HydraRingBreakWater(BreakWaterTypeHelper.GetHydraRingBreakWaterType(breakWaterType), input.BreakWater.Height), GetWaterLevels(calculation, assessmentSection).ElementAt(waterLevelIndex++), generalInput.A, generalInput.B, generalInput.C); HydraRingDataEqualityHelper.AreEqual(expectedInput, actualInput); } } mockRepository.VerifyAll(); }
private static WaveImpactAsphaltCoverWaveConditionsCalculation GetDefaultCalculation(HydraulicBoundaryLocation hydraulicBoundaryLocation) { WaveImpactAsphaltCoverWaveConditionsCalculation calculation = GetValidCalculation(hydraulicBoundaryLocation); calculation.InputParameters.LowerBoundaryWaterLevels = (RoundedDouble)5; calculation.InputParameters.UpperBoundaryWaterLevels = (RoundedDouble)5.4; return(calculation); }
private static void Validate(WaveImpactAsphaltCoverWaveConditionsCalculationContext context) { IAssessmentSection assessmentSection = context.AssessmentSection; WaveImpactAsphaltCoverWaveConditionsCalculation calculation = context.WrappedData; WaveConditionsCalculationServiceBase.Validate(calculation.InputParameters, WaveConditionsInputHelper.GetAssessmentLevel(calculation.InputParameters, context.AssessmentSection), assessmentSection.HydraulicBoundaryDatabase); }
private static void ReadOutput(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity) { if (entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities.Any()) { calculation.Output = new WaveImpactAsphaltCoverWaveConditionsOutput(entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities .OrderBy(oe => oe.Order) .Select(oe => oe.Read()) .ToArray()); } }
public void GivenValidCalculations_WhenCalculatingAllFromContextMenu_ThenAllCalculationsScheduled() { // Given var failureMechanism = new WaveImpactAsphaltCoverFailureMechanism(); IAssessmentSection assessmentSection = CreateAssessmentSectionWithHydraulicBoundaryOutput(); HydraulicBoundaryLocation hydraulicBoundaryLocation = assessmentSection.HydraulicBoundaryDatabase.Locations.First(); WaveImpactAsphaltCoverWaveConditionsCalculation calculationA = GetValidCalculation(hydraulicBoundaryLocation); WaveImpactAsphaltCoverWaveConditionsCalculation calculationB = GetValidCalculation(hydraulicBoundaryLocation); List <ICalculationBase> calculations = failureMechanism.CalculationsGroup.Children; calculations.AddRange(new[] { calculationA, calculationB }); var nodeData = new WaveImpactAsphaltCoverFailureMechanismContext(failureMechanism, assessmentSection); using (var treeViewControl = new TreeViewControl()) { IMainWindow mainWindow = MainWindowTestHelper.CreateMainWindowStub(mocks); var gui = mocks.Stub <IGui>(); gui.Stub(g => g.Get(nodeData, treeViewControl)).Return(new CustomItemsOnlyContextMenuBuilder()); gui.Stub(g => g.MainWindow).Return(mainWindow); var calculatorFactory = mocks.Stub <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateWaveConditionsCosineCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( HydraulicBoundaryCalculationSettingsFactory.CreateSettings(assessmentSection.HydraulicBoundaryDatabase), (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(new TestWaveConditionsCosineCalculator()) .Repeat .Times(6); mocks.ReplayAll(); plugin.Gui = gui; using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) using (ContextMenuStrip contextMenu = info.ContextMenuStrip(nodeData, null, treeViewControl)) { // When contextMenu.Items[contextMenuCalculateAllIndex].PerformClick(); // Then Assert.AreEqual(3, calculationA.Output.Items.Count()); Assert.AreEqual(3, calculationB.Output.Items.Count()); } } }
public void Clone_NotAllPropertiesSet_ReturnNewInstanceWithCopiedValues() { // Setup var original = new WaveImpactAsphaltCoverWaveConditionsCalculation(); // Call object clone = original.Clone(); // Assert CoreCloneAssert.AreObjectClones(original, clone, WaveImpactAsphaltCoverCloneAssert.AreClones); }
private static void AddEntityForWaveImpactAsphaltCoverWaveConditionsOutput(WaveImpactAsphaltCoverWaveConditionsCalculation calculation, WaveImpactAsphaltCoverWaveConditionsCalculationEntity entity) { if (calculation.HasOutput) { var i = 0; foreach (WaveConditionsOutput waveConditionsOutput in calculation.Output.Items) { entity.WaveImpactAsphaltCoverWaveConditionsOutputEntities.Add(waveConditionsOutput.CreateWaveImpactAsphaltCoverWaveConditionsOutputEntity(i++)); } } }
public void Run_CalculationWithInvalidHydraulicBoundaryDatabaseFilePath_DoesNotPerformCalculationAndLogsError() { // Setup string invalidFilePath = Path.Combine(testDataPath, "NonExisting.sqlite"); var assessmentSection = new AssessmentSectionStub { HydraulicBoundaryDatabase = { FilePath = invalidFilePath } }; var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); assessmentSection.SetHydraulicBoundaryLocationCalculations(new[] { hydraulicBoundaryLocation }); WaveImpactAsphaltCoverWaveConditionsCalculation calculation = CreateValidCalculation(hydraulicBoundaryLocation); CalculatableActivity activity = WaveImpactAsphaltCoverWaveConditionsCalculationActivityFactory.CreateCalculationActivity( calculation, new WaveImpactAsphaltCoverFailureMechanism(), assessmentSection); var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); mockRepository.ReplayAll(); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call void Call() => activity.Run(); // Assert TestHelper.AssertLogMessages(Call, messages => { string[] msgs = messages.ToArray(); Assert.AreEqual(4, msgs.Length); Assert.AreEqual($"Golfcondities berekenen voor '{calculation.Name}' is gestart.", msgs[0]); CalculationServiceTestHelper.AssertValidationStartMessage(msgs[1]); Assert.AreEqual("Herstellen van de verbinding met de hydraulische belastingendatabase is mislukt. " + $"Fout bij het lezen van bestand '{invalidFilePath}': het bestand bestaat niet.", msgs[2]); CalculationServiceTestHelper.AssertValidationEndMessage(msgs[3]); }); Assert.AreEqual(ActivityState.Failed, activity.State); } mockRepository.VerifyAll(); }