public void Create_WithNaNValues_ReturnsDuneLocationEntityWithNullPropertiesSet() { // Setup var random = new Random(28); int id = random.Next(0, 150); int order = random.Next(); var registry = new PersistenceRegistry(); var location = new DuneLocation(id, string.Empty, new Point2D(double.NaN, double.NaN), new DuneLocation.ConstructionProperties { Offset = double.NaN, Orientation = double.NaN, D50 = double.NaN }); // Call DuneLocationEntity entity = location.Create(registry, order); // Assert Assert.IsNotNull(entity); Assert.AreEqual(id, entity.LocationId); Assert.IsEmpty(entity.Name); Assert.IsNull(entity.LocationX); Assert.IsNull(entity.LocationY); Assert.IsNull(entity.Offset); Assert.IsNull(entity.Orientation); Assert.IsNull(entity.D50); Assert.AreEqual(order, entity.Order); }
public void Create_WithPersistenceRegistry_ReturnsDuneLocationEntityWithPropertiesSet() { // Setup const string testName = "testName"; var random = new Random(21); double coordinateX = random.NextDouble(); double coordinateY = random.NextDouble(); int id = random.Next(0, 150); int order = random.Next(); var registry = new PersistenceRegistry(); var location = new DuneLocation(id, testName, new Point2D(coordinateX, coordinateY), new DuneLocation.ConstructionProperties { CoastalAreaId = random.Next(), Offset = random.NextDouble(), Orientation = random.NextDouble(), D50 = random.NextDouble() }); // Call DuneLocationEntity entity = location.Create(registry, order); // Assert Assert.IsNotNull(entity); Assert.AreEqual(id, entity.LocationId); Assert.AreEqual(testName, entity.Name); Assert.AreEqual(coordinateX, entity.LocationX); Assert.AreEqual(coordinateY, entity.LocationY); Assert.AreEqual(location.CoastalAreaId, entity.CoastalAreaId); Assert.AreEqual(location.Offset, entity.Offset, location.Offset.GetAccuracy()); Assert.AreEqual(location.Orientation, entity.Orientation, location.Orientation.GetAccuracy()); Assert.AreEqual(location.D50, entity.D50, location.D50.GetAccuracy()); Assert.AreEqual(order, entity.Order); }
public void SetDuneLocations_DuneLocationOffsetMatchesWithHydraulicBoundaryLocationName_DuneLocationAddedToFailureMechanism() { // Setup var failureMechanism = new DuneErosionFailureMechanism(); var readDuneLocation = new ReadDuneLocation("dune location 1", new Point2D(1.0, 5.3), 8, 1.1, 2.2, 3.3); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, "Location_2_1.1", 1.0, 5.3); // Precondition CollectionAssert.IsEmpty(failureMechanism.DuneLocations); // Call DuneErosionDataSynchronizationService.SetDuneLocations( failureMechanism, new[] { hydraulicBoundaryLocation }, new[] { readDuneLocation }); // Assert Assert.AreEqual(1, failureMechanism.DuneLocations.Count()); DuneLocation duneLocation = failureMechanism.DuneLocations.First(); Assert.AreEqual(hydraulicBoundaryLocation.Id, duneLocation.Id); Assert.AreEqual(readDuneLocation.Name, duneLocation.Name); Assert.AreEqual(readDuneLocation.Location, duneLocation.Location); Assert.AreEqual(readDuneLocation.Offset, duneLocation.Offset); Assert.AreEqual(readDuneLocation.Orientation, duneLocation.Orientation); Assert.AreEqual(readDuneLocation.D50, duneLocation.D50); }
public void Constructor_ExpectedValues() { // Setup const long id = 0; const string name = "Dune location"; var location = new Point2D(10.0, 12.0); const int coastalAreaId = 3; const double offset = 4.2; const double orientation = 4.2; const double d50 = 0.123456; // Call var duneLocation = new DuneLocation(id, name, location, new DuneLocation.ConstructionProperties { CoastalAreaId = coastalAreaId, Offset = offset, Orientation = orientation, D50 = d50 }); // Assert Assert.AreEqual(id, duneLocation.Id); Assert.AreEqual(name, duneLocation.Name); Assert.AreSame(location, duneLocation.Location); Assert.AreEqual(coastalAreaId, duneLocation.CoastalAreaId); Assert.AreEqual(offset, duneLocation.Offset.Value); Assert.AreEqual(orientation, duneLocation.Orientation.Value); Assert.AreEqual(d50, duneLocation.D50.Value); }
public void CreateCalculationActivitiesForCalculations_WithValidDataAndUsePreprocessorStates_ReturnsExpectedActivities(bool usePreprocessor) { // Setup const double targetProbability = 0.01; const string calculationIdentifier = "1/100"; AssessmentSectionStub assessmentSection = CreateAssessmentSection(usePreprocessor); var duneLocation1 = new DuneLocation(1, "locationName1", new Point2D(1, 1), new DuneLocation.ConstructionProperties()); var duneLocation2 = new DuneLocation(2, "locationName2", new Point2D(2, 2), new DuneLocation.ConstructionProperties()); // Call CalculatableActivity[] activities = DuneLocationCalculationActivityFactory.CreateCalculationActivities( new[] { new DuneLocationCalculation(duneLocation1), new DuneLocationCalculation(duneLocation2) }, assessmentSection, targetProbability, calculationIdentifier).ToArray(); // Assert CollectionAssert.AllItemsAreInstancesOfType(activities, typeof(DuneLocationCalculationActivity)); Assert.AreEqual(2, activities.Length); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; AssertDuneLocationCalculationActivity(activities[0], calculationIdentifier, duneLocation1.Name, duneLocation1.Id, targetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[1], calculationIdentifier, duneLocation2.Name, duneLocation2.Id, targetProbability, hydraulicBoundaryDatabase); }
public void CreateCalculationActivitiesForFailureMechanism_WithValidDataAndUsePreprocessorStates_ReturnsExpectedActivities(bool usePreprocessor) { // Setup AssessmentSectionStub assessmentSection = CreateAssessmentSection(usePreprocessor); var duneLocationCalculationsForTargetProbability1 = new DuneLocationCalculationsForTargetProbability(0.1); var duneLocationCalculationsForTargetProbability2 = new DuneLocationCalculationsForTargetProbability(0.01); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { duneLocationCalculationsForTargetProbability1, duneLocationCalculationsForTargetProbability2 } }; var duneLocation1 = new DuneLocation(1, "locationName1", new Point2D(1, 1), new DuneLocation.ConstructionProperties()); var duneLocation2 = new DuneLocation(2, "locationName2", new Point2D(2, 2), new DuneLocation.ConstructionProperties()); failureMechanism.SetDuneLocations(new[] { duneLocation1, duneLocation2 }); // Call CalculatableActivity[] activities = DuneLocationCalculationActivityFactory.CreateCalculationActivities(failureMechanism, assessmentSection).ToArray(); // Assert Assert.AreEqual(4, activities.Length); HydraulicBoundaryDatabase hydraulicBoundaryDatabase = assessmentSection.HydraulicBoundaryDatabase; AssertDuneLocationCalculationActivity(activities[0], "1/10", duneLocation1.Name, duneLocation1.Id, duneLocationCalculationsForTargetProbability1.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[1], "1/10", duneLocation2.Name, duneLocation2.Id, duneLocationCalculationsForTargetProbability1.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[2], "1/100", duneLocation1.Name, duneLocation1.Id, duneLocationCalculationsForTargetProbability2.TargetProbability, hydraulicBoundaryDatabase); AssertDuneLocationCalculationActivity(activities[3], "1/100", duneLocation2.Name, duneLocation2.Id, duneLocationCalculationsForTargetProbability2.TargetProbability, hydraulicBoundaryDatabase); }
/// <summary> /// Read the <see cref="DuneLocationEntity"/> and use the information to construct a <see cref="DuneLocation"/>. /// </summary> /// <param name="entity">The <see cref="DuneLocationEntity"/> to create <see cref="DuneLocation"/> for.</param> /// <param name="collector">The object keeping track of read operations.</param> /// <returns>A new <see cref="DuneLocation"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any input parameter is <c>null</c>.</exception> internal static DuneLocation Read(this DuneLocationEntity entity, ReadConversionCollector collector) { if (entity == null) { throw new ArgumentNullException(nameof(entity)); } if (collector == null) { throw new ArgumentNullException(nameof(collector)); } if (collector.Contains(entity)) { return(collector.Get(entity)); } var duneLocation = new DuneLocation(entity.LocationId, entity.Name, new Point2D(entity.LocationX.ToNullAsNaN(), entity.LocationY.ToNullAsNaN()), new DuneLocation.ConstructionProperties { CoastalAreaId = entity.CoastalAreaId, Offset = entity.Offset.ToNullAsNaN(), Orientation = entity.Orientation.ToNullAsNaN(), D50 = entity.D50.ToNullAsNaN() }); collector.Read(entity, duneLocation); return(duneLocation); }
/// <summary> /// Creates a <see cref="DuneLocationEntity"/> based on the information of the <see cref="DuneLocation"/>. /// </summary> /// <param name="location">The location to create a database entity for.</param> /// <param name="registry">The object keeping track of create operations.</param> /// <param name="order">Index at which this instance resides inside its parent container.</param> /// <returns>A new <see cref="DuneLocationEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> internal static DuneLocationEntity Create(this DuneLocation location, PersistenceRegistry registry, int order) { if (location == null) { throw new ArgumentNullException(nameof(location)); } if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (registry.Contains(location)) { return(registry.Get(location)); } var entity = new DuneLocationEntity { LocationId = location.Id, Name = location.Name.DeepClone(), LocationX = location.Location.X.ToNaNAsNull(), LocationY = location.Location.Y.ToNaNAsNull(), CoastalAreaId = location.CoastalAreaId, Offset = location.Offset.ToNaNAsNull(), Orientation = location.Orientation.ToNaNAsNull(), D50 = location.D50.ToNaNAsNull(), Order = order }; registry.Register(entity, location); return(entity); }
public void GivenFullyConfiguredDuneLocationCalculationsView_WhenDuneLocationCalculationsUpdatedAndNotified_ThenDataGridCorrectlyUpdated() { // Given var assessmentSection = mocks.Stub <IAssessmentSection>(); mocks.ReplayAll(); var calculations = new ObservableList <DuneLocationCalculation>(); using (DuneLocationCalculationsView view = ShowDuneLocationCalculationsView(calculations, new DuneErosionFailureMechanism(), assessmentSection)) { // Precondition var dataGridView = (DataGridView)view.Controls.Find("dataGridView", true)[0]; object originalDataSource = dataGridView.DataSource; DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(0, rows.Count); // When var duneLocation = new DuneLocation(10, "10", new Point2D(10.0, 10.0), new DuneLocation.ConstructionProperties { CoastalAreaId = 3, Offset = 80, D50 = 0.000321 }); var duneLocationCalculation = new DuneLocationCalculation(duneLocation) { Output = new DuneLocationCalculationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationCalculationOutput.ConstructionProperties { WaterLevel = 3.21, WaveHeight = 4.32, WavePeriod = 5.43 }) }; calculations.Add(duneLocationCalculation); calculations.NotifyObservers(); // Then Assert.AreNotSame(originalDataSource, dataGridView.DataSource); var expectedRowValues = new object[] { false, "10", "10", new Point2D(10, 10).ToString(), "3", "80", 3.21.ToString(CultureInfo.CurrentCulture), 4.32.ToString(CultureInfo.CurrentCulture), 5.43.ToString(CultureInfo.CurrentCulture), 0.000321.ToString(CultureInfo.CurrentCulture) }; DataGridViewTestHelper.AssertExpectedRowFormattedValues(expectedRowValues, rows[0]); } }
private static string GetExpectedWavePeriod(IEnumerable <DuneLocationCalculation> calculations, DuneLocation duneLocation) { RoundedDouble result = calculations .Single(calculation => calculation.DuneLocation.Equals(duneLocation)) .Output?.WavePeriod ?? RoundedDouble.NaN; return(result.ToString()); }
public void Calculate_ValidData_CalculationStartedWithRightParameters(bool usePreprocessor) { // Setup const double targetProbability = 1.0 / 30; string preprocessorDirectory = usePreprocessor ? validPreprocessorDirectory : string.Empty; var calculationSettings = new HydraulicBoundaryCalculationSettings(validHydraulicBoundaryDatabaseFilePath, validHlcdFilePath, false, preprocessorDirectory); var calculator = new TestDunesBoundaryConditionsCalculator { Converged = true }; var mockRepository = new MockRepository(); var calculatorFactory = mockRepository.StrictMock <IHydraRingCalculatorFactory>(); calculatorFactory.Expect(cf => cf.CreateDunesBoundaryConditionsCalculator(Arg <HydraRingCalculationSettings> .Is.NotNull)) .WhenCalled(invocation => { HydraRingCalculationSettingsTestHelper.AssertHydraRingCalculationSettings( calculationSettings, (HydraRingCalculationSettings)invocation.Arguments[0]); }) .Return(calculator); var calculationMessageProvider = mockRepository.StrictMock <ICalculationMessageProvider>(); mockRepository.ReplayAll(); var duneLocation = new DuneLocation(1300001, "test", new Point2D(0, 0), new DuneLocation.ConstructionProperties { CoastalAreaId = 0, Offset = 0, Orientation = 0, D50 = 0.000007 }); using (new HydraRingCalculatorFactoryConfig(calculatorFactory)) { // Call new DuneLocationCalculationService().Calculate(new DuneLocationCalculation(duneLocation), targetProbability, calculationSettings, calculationMessageProvider); // Assert DunesBoundaryConditionsCalculationInput expectedInput = CreateInput(duneLocation, targetProbability); DunesBoundaryConditionsCalculationInput actualInput = calculator.ReceivedInputs.Single(); AssertInput(expectedInput, actualInput); Assert.AreEqual(usePreprocessor, actualInput.PreprocessorSetting.RunPreprocessor); } mockRepository.VerifyAll(); }
private static void AssertDuneLocationCalculations(DuneLocation expectedDuneLocation, DuneErosionFailureMechanism failureMechanism) { ObservableList <DuneLocationCalculationsForTargetProbability> userDefinedTargetProbabilities = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities; foreach (DuneLocationCalculationsForTargetProbability userDefinedTargetProbability in userDefinedTargetProbabilities) { AssertDefaultDuneLocationCalculation(expectedDuneLocation, userDefinedTargetProbability.DuneLocationCalculations.Single()); } }
/// <summary> /// Creates the input used in the calculation. /// </summary> /// <param name="duneLocation">The <see cref="DuneLocation"/> to create the input for.</param> /// <param name="targetProbability">The target probability to use during the calculation.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <returns>A <see cref="DunesBoundaryConditionsCalculationInput"/> with all needed /// input data.</returns> /// <exception cref="ArgumentException">Thrown when the hydraulic boundary database file path. /// contains invalid characters.</exception> /// <exception cref="CriticalFileReadException">Thrown when: /// <list type="bullet"> /// <item>No settings database file could be found at the location of the hydraulic boundary database file path. /// with the same name.</item> /// <item>Unable to open settings database file.</item> /// <item>Unable to read required data from database file.</item> /// </list> /// </exception> private static DunesBoundaryConditionsCalculationInput CreateInput(DuneLocation duneLocation, double targetProbability, HydraulicBoundaryCalculationSettings calculationSettings) { var dunesBoundaryConditionsCalculationInput = new DunesBoundaryConditionsCalculationInput(1, duneLocation.Id, targetProbability); HydraRingSettingsDatabaseHelper.AssignSettingsFromDatabase(dunesBoundaryConditionsCalculationInput, calculationSettings.HydraulicBoundaryDatabaseFilePath, !string.IsNullOrEmpty(calculationSettings.PreprocessorDirectory)); return(dunesBoundaryConditionsCalculationInput); }
public void Replace_NewLocationsIsDune_LocationAndCalculationsAdded() { // Setup var mocks = new MockRepository(); var viewCommands = mocks.Stub <IViewCommands>(); mocks.ReplayAll(); var random = new Random(21); var failureMechanism = new DuneErosionFailureMechanism { DuneLocationCalculationsForUserDefinedTargetProbabilities = { new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)), new DuneLocationCalculationsForTargetProbability(random.NextDouble(0, 0.01)) } }; failureMechanism.SetDuneLocations(new[] { new TestDuneLocation(), new TestDuneLocation() }); var handler = new DuneLocationsReplacementHandler(viewCommands, failureMechanism); // Precondition Assert.AreEqual(2, failureMechanism.DuneLocations.Count()); ObservableList <DuneLocationCalculationsForTargetProbability> calculationsForTargetProbabilities = failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities; Assert.AreEqual(2, calculationsForTargetProbabilities[0].DuneLocationCalculations.Count); Assert.AreEqual(2, calculationsForTargetProbabilities[1].DuneLocationCalculations.Count); // Call handler.Replace(new[] { new HydraulicBoundaryLocation(1, "test_1_100", 205354, 609735) }); // Assert Assert.AreEqual(1, failureMechanism.DuneLocations.Count()); DuneLocation duneLocation = failureMechanism.DuneLocations.First(); Assert.AreEqual(1, duneLocation.Id); Assert.AreEqual(new Point2D(205354, 609735), duneLocation.Location); AssertDuneLocationCalculations(duneLocation, failureMechanism); mocks.VerifyAll(); }
public void Constructor_WithOrientation_OrientationRounded() { // Call var duneLocation = new DuneLocation(0, "dune", new Point2D(0.0, 0.0), new DuneLocation.ConstructionProperties { Orientation = 8.214 }); // Assert Assert.AreEqual(1, duneLocation.Orientation.NumberOfDecimalPlaces); Assert.AreEqual(8.2, duneLocation.Orientation, duneLocation.Orientation.GetAccuracy()); }
public void Constructor_WithOffset_OffsetRounded() { // Call var duneLocation = new DuneLocation(0, "dune", new Point2D(0.0, 0.0), new DuneLocation.ConstructionProperties { Offset = 4.298 }); // Assert Assert.AreEqual(1, duneLocation.Offset.NumberOfDecimalPlaces); Assert.AreEqual(4.3, duneLocation.Offset, duneLocation.Offset.GetAccuracy()); }
public void ToString_Always_ExpectedValue() { // Setup var duneLocation = new DuneLocation(1, "Name", new Point2D(0.0, 1.1), new DuneLocation.ConstructionProperties()); var duneLocationCalculation = new DuneLocationCalculation(duneLocation); var properties = new DuneLocationCalculationProperties(duneLocationCalculation); // Call string result = properties.ToString(); // Assert Assert.AreEqual($"{duneLocation.Name} {duneLocation.Location}", result); }
public void Constructor_WithD50_D50Rounded() { // Call var duneLocation = new DuneLocation(0, "dune", new Point2D(0.0, 0.0), new DuneLocation.ConstructionProperties { D50 = 0.1234567 }); // Assert Assert.AreEqual(6, duneLocation.D50.NumberOfDecimalPlaces); Assert.AreEqual(0.123457, duneLocation.D50, duneLocation.D50.GetAccuracy()); }
/// <summary> /// Sets <see cref="DuneErosionFailureMechanism.DuneLocations"/> based upon /// the <paramref name="hydraulicBoundaryLocations"/>. /// </summary> /// <param name="failureMechanism">The <see cref="DuneErosionFailureMechanism"/> to update.</param> /// <param name="hydraulicBoundaryLocations">The hydraulic boundary locations to use.</param> /// <param name="duneLocations">The dune locations to use.</param> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static void SetDuneLocations(DuneErosionFailureMechanism failureMechanism, IEnumerable <HydraulicBoundaryLocation> hydraulicBoundaryLocations, IEnumerable <ReadDuneLocation> duneLocations) { if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } if (hydraulicBoundaryLocations == null) { throw new ArgumentNullException(nameof(hydraulicBoundaryLocations)); } if (duneLocations == null) { throw new ArgumentNullException(nameof(duneLocations)); } if (!hydraulicBoundaryLocations.Any() || !duneLocations.Any()) { failureMechanism.SetDuneLocations(Enumerable.Empty <DuneLocation>()); return; } var correspondingDuneLocations = new List <DuneLocation>(); foreach (ReadDuneLocation readDuneLocation in duneLocations) { HydraulicBoundaryLocation correspondingHydraulicBoundaryLocation = hydraulicBoundaryLocations .FirstOrDefault(hbl => DoesHydraulicBoundaryLocationMatchWithDuneLocation(hbl, readDuneLocation)); if (correspondingHydraulicBoundaryLocation != null) { var duneLocation = new DuneLocation(correspondingHydraulicBoundaryLocation.Id, readDuneLocation.Name, readDuneLocation.Location, new DuneLocation.ConstructionProperties { CoastalAreaId = readDuneLocation.CoastalAreaId, Offset = readDuneLocation.Offset, Orientation = readDuneLocation.Orientation, D50 = readDuneLocation.D50 }); correspondingDuneLocations.Add(duneLocation); } } failureMechanism.SetDuneLocations(correspondingDuneLocations); }
public void Offset_Always_FormatToString(double offset, string expectedPropertyValue) { var duneLocation = new DuneLocation(1, "test", new Point2D(0, 0), new DuneLocation.ConstructionProperties { Offset = offset }); var duneLocationCalculation = new DuneLocationCalculation(duneLocation); // Call var properties = new DuneLocationCalculationProperties(duneLocationCalculation); // Assert Assert.AreEqual(expectedPropertyValue, properties.Offset); }
private static string CreateCsvLine(ExportableDuneLocationCalculation calculation) { DuneLocation duneLocation = calculation.Calculation.DuneLocation; var stringComponents = new List <string> { duneLocation.CoastalAreaId.ToString(CultureInfo.InvariantCulture), duneLocation.Offset.ToString(DuneErosionDataResources.DuneLocation_Offset_format, CultureInfo.InvariantCulture), Resources.DuneLocationCalculationsWriter_CreateCsvLine_Parameter_without_value, duneLocation.D50.ToString(null, CultureInfo.InvariantCulture), calculation.TargetProbability.ToString(CultureInfo.InvariantCulture) }; stringComponents.InsertRange(2, GetOutputValues(calculation.Calculation.Output)); return(string.Join(separator, stringComponents)); }
public void Create_StringPropertiesDoNotShareReferences() { // Setup const string testName = "original name"; var location = new DuneLocation(1, testName, new Point2D(0, 0), new DuneLocation.ConstructionProperties()); var registry = new PersistenceRegistry(); // Call DuneLocationEntity entity = location.Create(registry, 0); // Assert Assert.IsNotNull(entity); Assert.AreNotSame(testName, entity.Name, "To create stable binary representations/fingerprints, it's really important that strings are not shared."); Assert.AreEqual(testName, entity.Name); }
public void Read_SameDuneLocationEntityTwice_ReturnSameDuneLocation() { // Setup var entity = new DuneLocationEntity { Name = "A" }; var collector = new ReadConversionCollector(); // Call DuneLocation location1 = entity.Read(collector); DuneLocation location2 = entity.Read(collector); // Assert Assert.AreSame(location1, location2); }
public void Constructor_DuneLocationCalculationWithOutput_ExpectedValues(double offSet) { // Setup var duneLocation = new DuneLocation(1, "test location", new Point2D(3.3, 4.4), new DuneLocation.ConstructionProperties { CoastalAreaId = 2, Offset = offSet, D50 = 0.000183 }); var duneLocationCalculation = new DuneLocationCalculation(duneLocation) { Output = new DuneLocationCalculationOutput(CalculationConvergence.CalculatedConverged, new DuneLocationCalculationOutput.ConstructionProperties { WaterLevel = 3.0, WaveHeight = 4.0, WavePeriod = 5.0 }) }; // Call var row = new DuneLocationCalculationRow(duneLocationCalculation); // Assert Assert.IsInstanceOf <CalculatableRow <DuneLocationCalculation> >(row); Assert.AreSame(duneLocationCalculation, row.CalculatableObject); Assert.AreEqual(duneLocation.Id, row.Id); Assert.AreEqual(duneLocation.Name, row.Name); Assert.AreSame(duneLocation.Location, row.Location); Assert.AreEqual(duneLocation.CoastalAreaId, row.CoastalAreaId); Assert.AreEqual(duneLocation.Offset.ToString("0.#", CultureInfo.InvariantCulture), row.Offset); Assert.AreEqual(duneLocation.D50, row.D50); Assert.AreEqual(duneLocationCalculation.Output.WaterLevel, row.WaterLevel); Assert.AreEqual(duneLocationCalculation.Output.WaveHeight, row.WaveHeight); Assert.AreEqual(duneLocationCalculation.Output.WavePeriod, row.WavePeriod); TestHelper.AssertTypeConverter <DuneLocationCalculationRow, NoValueRoundedDoubleConverter>( nameof(DuneLocationCalculationRow.WaterLevel)); TestHelper.AssertTypeConverter <DuneLocationCalculationRow, NoValueRoundedDoubleConverter>( nameof(DuneLocationCalculationRow.WaveHeight)); TestHelper.AssertTypeConverter <DuneLocationCalculationRow, NoValueRoundedDoubleConverter>( nameof(DuneLocationCalculationRow.WavePeriod)); }
public void Read_WithValidData_ReturnsDuneLocationWithPropertiesSetAndEntityRegistered() { // Setup const string testName = "testName"; var random = new Random(21); long locationId = random.Next(0, 400); double x = random.NextDouble(); double y = random.NextDouble(); int coastalAreaId = random.Next(); double offset = random.NextDouble(); double orientation = random.NextDouble(); double d50 = random.NextDouble(); var entity = new DuneLocationEntity { LocationId = locationId, Name = testName, LocationX = x, LocationY = y, CoastalAreaId = coastalAreaId, Offset = offset, Orientation = orientation, D50 = d50 }; var collector = new ReadConversionCollector(); // Call DuneLocation location = entity.Read(collector); // Assert Assert.IsNotNull(location); Assert.AreEqual(locationId, location.Id); Assert.AreEqual(testName, location.Name); Assert.AreEqual(x, location.Location.X, 1e-6); Assert.AreEqual(y, location.Location.Y, 1e-6); Assert.AreEqual(coastalAreaId, location.CoastalAreaId); Assert.AreEqual(offset, location.Offset, location.Offset.GetAccuracy()); Assert.AreEqual(orientation, location.Orientation, location.Orientation.GetAccuracy()); Assert.AreEqual(d50, location.D50, location.D50.GetAccuracy()); Assert.IsTrue(collector.Contains(entity)); }
/// <summary> /// Creates a new instance of <see cref="DuneLocationCalculationActivity"/>. /// </summary> /// <param name="duneLocationCalculation">The <see cref="DuneLocationCalculation"/> to perform.</param> /// <param name="calculationSettings">The <see cref="HydraulicBoundaryCalculationSettings"/> with the /// hydraulic boundary calculation settings.</param> /// <param name="targetProbability">The target probability to use during the calculation.</param> /// <param name="calculationIdentifier">The calculation identifier to use in all messages.</param> /// <remarks>Preprocessing is disabled when the preprocessor directory equals <see cref="string.Empty"/>.</remarks> /// <exception cref="ArgumentNullException">Thrown when <paramref name="duneLocationCalculation"/> /// or <paramref name="calculationSettings"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">Thrown when <paramref name="calculationIdentifier"/> is <c>null</c> or empty.</exception> public DuneLocationCalculationActivity(DuneLocationCalculation duneLocationCalculation, HydraulicBoundaryCalculationSettings calculationSettings, double targetProbability, string calculationIdentifier) : base(duneLocationCalculation) { if (calculationSettings == null) { throw new ArgumentNullException(nameof(calculationSettings)); } messageProvider = new DuneLocationCalculationMessageProvider(calculationIdentifier); this.duneLocationCalculation = duneLocationCalculation; this.calculationSettings = calculationSettings; this.targetProbability = targetProbability; DuneLocation duneLocation = duneLocationCalculation.DuneLocation; Description = messageProvider.GetActivityDescription(duneLocation.Name); calculationService = new DuneLocationCalculationService(); }
public void Read_WithNullData_ReturnsDuneLocationWithNaNPropertiesSet() { // Setup const string testName = "testName"; var random = new Random(22); long locationId = random.Next(0, 400); int coastalAreaId = random.Next(); var entity = new DuneLocationEntity { LocationId = locationId, Name = testName, LocationX = null, LocationY = null, CoastalAreaId = coastalAreaId, Offset = null, Orientation = null, D50 = null }; var collector = new ReadConversionCollector(); // Call DuneLocation location = entity.Read(collector); // Assert Assert.IsNotNull(location); Assert.AreEqual(locationId, location.Id); Assert.AreEqual(testName, location.Name); Assert.IsNaN(location.Location.X); Assert.IsNaN(location.Location.Y); Assert.AreEqual(coastalAreaId, location.CoastalAreaId); Assert.IsNaN(location.Offset); Assert.IsNaN(location.Orientation); Assert.IsNaN(location.D50); Assert.IsTrue(collector.Contains(entity)); }
/// <summary> /// Asserts whether <paramref name="features"/> contains the data that is representative for the data of /// dune locations and calculations in <paramref name="failureMechanism"/>. /// </summary> /// <param name="failureMechanism">The failure mechanism that contains the first part of the original data.</param> /// <param name="features">The collection of <see cref="MapFeature"/> to assert.</param> /// <exception cref="AssertionException">Thrown when: /// <list type="bullet"> /// <item>the number of dune locations and features are not the same;</item> /// <item>the general properties (such as id, name and location) of dune locations and features /// are not the same;</item> /// <item>the water level, wave height or wave period calculation results of a dune location and the /// respective outputs of a corresponding feature are not the same.</item> /// <item>the number of meta data items does not match with the expected number of items.</item> /// </list> /// </exception> public static void AssertDuneLocationFeaturesData(DuneErosionFailureMechanism failureMechanism, IEnumerable <MapFeature> features) { IEnumerable <DuneLocation> expectedDuneLocations = failureMechanism.DuneLocations; Assert.AreEqual(expectedDuneLocations.Count(), features.Count()); for (var i = 0; i < expectedDuneLocations.Count(); i++) { DuneLocation expectedDuneLocation = expectedDuneLocations.ElementAt(i); MapFeature mapFeature = features.ElementAt(i); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Id, mapFeature, "ID"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Name, mapFeature, "Naam"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.CoastalAreaId, mapFeature, "Kustvaknummer"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.Offset.ToString("0.#", CultureInfo.CurrentCulture), mapFeature, "Metrering"); MapFeaturesMetaDataTestHelper.AssertMetaData(expectedDuneLocation.D50.ToString(), mapFeature, "Rekenwaarde d50"); Assert.AreEqual(expectedDuneLocation.Location, mapFeature.MapGeometries.First().PointCollections.First().Single()); var presentedMetaDataItems = new List <string>(); foreach (DuneLocationCalculationsForTargetProbability calculationsForTargetProbability in failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities) { AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWaterLevel, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde h - {0}", presentedMetaDataItems); AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWaveHeight, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde Hs - {0}", presentedMetaDataItems); AssertMetaData(calculationsForTargetProbability.DuneLocationCalculations, expectedDuneLocation, GetExpectedWavePeriod, mapFeature, calculationsForTargetProbability.TargetProbability, "Rekenwaarde Tp - {0}", presentedMetaDataItems); } int expectedMetaDataCount = 5 + (3 * failureMechanism.DuneLocationCalculationsForUserDefinedTargetProbabilities.Count); Assert.AreEqual(expectedMetaDataCount, mapFeature.MetaData.Keys.Count); } }
private static void AssertMetaData(IEnumerable <DuneLocationCalculation> calculations, DuneLocation hydraulicBoundaryLocation, Func <IEnumerable <DuneLocationCalculation>, DuneLocation, string> getExpectedResultFunc, MapFeature mapFeature, double targetProbability, string displayNameFormat, List <string> presentedMetaDataItems) { string uniqueName = NamingHelper.GetUniqueName( presentedMetaDataItems, string.Format(displayNameFormat, ProbabilityFormattingHelper.Format(targetProbability)), v => v); MapFeaturesMetaDataTestHelper.AssertMetaData( getExpectedResultFunc(calculations, hydraulicBoundaryLocation), mapFeature, uniqueName); presentedMetaDataItems.Add(uniqueName); }
/// <summary> /// Obtains the <see cref="DuneLocationEntity"/> which was registered for the /// given <paramref name="model"/>. /// </summary> /// <param name="model">The <see cref="DuneLocation"/> for which a /// read operation has been registered.</param> /// <returns>The constructed <see cref="DuneLocationEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception> /// <exception cref="InvalidOperationException">Thrown when no create operation /// has been registered for <paramref name="model"/>.</exception> /// <remarks>Use <see cref="Contains(DuneLocation)"/> to find out /// whether a create operation has been registered for <paramref name="model"/>.</remarks> internal DuneLocationEntity Get(DuneLocation model) { return(Get(duneLocations, model)); }