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 SetDuneLocations_DuneLocationsMatchNameNotAccordingFormat_DuneLocationNotAddedLogMessage(double offset) { // Setup var locationName = $"Location_{offset}"; var failureMechanism = new DuneErosionFailureMechanism(); var readDuneLocation = new ReadDuneLocation("dune location 1", new Point2D(1.0, 5.3), 8, offset, 2.2, 3.3); var hydraulicBoundaryLocation = new HydraulicBoundaryLocation(1, locationName, 1.0, 5.3); // Precondition CollectionAssert.IsEmpty(failureMechanism.DuneLocations); // Call void Call() => DuneErosionDataSynchronizationService.SetDuneLocations(failureMechanism, new[] { hydraulicBoundaryLocation }, new[] { readDuneLocation }); // Assert string expectedMessage = $"Locatie '{locationName}' moet voldoen aan het formaat 'Naam_Vaknummer_Metrering'. " + "Deze locatie is niet toegevoegd aan de hydraulische belastingen voor het faalmechanisme duinen."; TestHelper.AssertLogMessageIsGenerated(Call, expectedMessage, 1); CollectionAssert.IsEmpty(failureMechanism.DuneLocations); }
private static bool DoesHydraulicBoundaryLocationMatchWithDuneLocation(HydraulicBoundaryLocation hydraulicBoundaryLocation, ReadDuneLocation readDuneLocation) { if (!Math2D.AreEqualPoints(hydraulicBoundaryLocation.Location, readDuneLocation.Location)) { return(false); } // Regex to search for a pattern like "<Some text without white spaces>_<integer>_<decimal>" // Only the last number is captured in a group called "Offset" // The last number can also contain decimals. var regex = new Regex(@"^(?:\S+)_(?:\d+)_(?<Offset>(?:\d+\.)?\d+$)"); Match match = regex.Match(hydraulicBoundaryLocation.Name); if (!match.Success) { log.ErrorFormat(Resources.DuneErosionDataSynchronizationService_SetDuneLocations_Location_0_is_dune_location_but_name_is_not_according_format, hydraulicBoundaryLocation.Name); return(false); } string duneLocationOffset = readDuneLocation.Offset.ToString(DuneErosionDataResources.DuneLocation_Offset_format, CultureInfo.InvariantCulture); return(match.Groups["Offset"].Value == duneLocationOffset); }
public void Constructor_WithD50_D50Rounded() { // Call var duneLocation = new ReadDuneLocation("dune", new Point2D(0.0, 0.0), 0, 0.0, 0.0, 0.1234567); // Assert Assert.AreEqual(6, duneLocation.D50.NumberOfDecimalPlaces); Assert.AreEqual(0.123457, duneLocation.D50, duneLocation.D50.GetAccuracy()); }
public void Constructor_WithOrientation_OrientationRounded() { // Call var duneLocation = new ReadDuneLocation("dune", new Point2D(0.0, 0.0), 0, 0.0, 8.214, 0.0); // 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 ReadDuneLocation("dune", new Point2D(0.0, 0.0), 0, 4.298, 0.0, 0.0); // Assert Assert.AreEqual(2, duneLocation.Offset.NumberOfDecimalPlaces); Assert.AreEqual(4.30, duneLocation.Offset, duneLocation.Offset.GetAccuracy()); }
public void Constructor_ExpectedValues() { // Setup const string name = "Dune location"; var location = new Point2D(10.0, 12.0); const int coastalAreaId = 3; const double offset = 4.29; const double orientation = 4.2; const double d50 = 0.123456; // Call var duneLocation = new ReadDuneLocation(name, location, coastalAreaId, offset, orientation, d50); // Assert 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 SetDuneLocation_DuneLocationNoMatchWithHydraulicBoundaryLocation_DuneLocationNotAddedToFailureMechanism(ReadDuneLocation readDuneLocation, HydraulicBoundaryLocation hydraulicBoundaryLocation) { // Setup var failureMechanism = new DuneErosionFailureMechanism(); // Precondition CollectionAssert.IsEmpty(failureMechanism.DuneLocations); // Call DuneErosionDataSynchronizationService.SetDuneLocations(failureMechanism, new[] { hydraulicBoundaryLocation }, new[] { readDuneLocation }); // Assert CollectionAssert.IsEmpty(failureMechanism.DuneLocations); }