public void SynchronizeStructureInput_ChangedStructure_ExpectedValues() { // Setup var differentStructure = new HeightStructure(new HeightStructure.ConstructionProperties { Id = "Test id", Name = "Test name", Location = new Point2D(-1, -1) }); var input = new HeightStructuresInput { Structure = new TestHeightStructure() }; input.Structure.CopyProperties(differentStructure); // Precondition AssertHeightStructureInput(new TestHeightStructure(), input); // Call input.SynchronizeStructureInput(); // Assert AssertHeightStructureInput(differentStructure, input); }
private static void AssertHeightStructureInput(HeightStructure expectedHeightStructure, HeightStructuresInput input) { if (expectedHeightStructure == null) { Assert.IsNull(input.Structure); var defaultInput = new HeightStructuresInput(); AssertAreEqual(defaultInput.StructureNormalOrientation, input.StructureNormalOrientation); DistributionAssert.AreEqual(defaultInput.LevelCrestStructure, input.LevelCrestStructure); DistributionAssert.AreEqual(defaultInput.CriticalOvertoppingDischarge, input.CriticalOvertoppingDischarge); DistributionAssert.AreEqual(defaultInput.WidthFlowApertures, input.WidthFlowApertures); Assert.AreEqual(defaultInput.FailureProbabilityStructureWithErosion, input.FailureProbabilityStructureWithErosion); DistributionAssert.AreEqual(defaultInput.StorageStructureArea, input.StorageStructureArea); DistributionAssert.AreEqual(defaultInput.AllowedLevelIncreaseStorage, input.AllowedLevelIncreaseStorage); } else { AssertAreEqual(expectedHeightStructure.StructureNormalOrientation, input.StructureNormalOrientation); DistributionAssert.AreEqual(expectedHeightStructure.LevelCrestStructure, input.LevelCrestStructure); DistributionAssert.AreEqual(expectedHeightStructure.CriticalOvertoppingDischarge, input.CriticalOvertoppingDischarge); DistributionAssert.AreEqual(expectedHeightStructure.WidthFlowApertures, input.WidthFlowApertures); Assert.AreEqual(expectedHeightStructure.FailureProbabilityStructureWithErosion, input.FailureProbabilityStructureWithErosion); DistributionAssert.AreEqual(expectedHeightStructure.StorageStructureArea, input.StorageStructureArea); DistributionAssert.AreEqual(expectedHeightStructure.AllowedLevelIncreaseStorage, input.AllowedLevelIncreaseStorage); } }
private static void AssertHeightStructures(HeightStructure readStructure, HeightStructure structure) { Assert.AreEqual(readStructure.Name, structure.Name); Assert.AreEqual(readStructure.Location, structure.Location); Assert.AreEqual(readStructure.StructureNormalOrientation, structure.StructureNormalOrientation); Assert.AreEqual(readStructure.AllowedLevelIncreaseStorage.Mean, structure.AllowedLevelIncreaseStorage.Mean); Assert.AreEqual(readStructure.AllowedLevelIncreaseStorage.StandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation); Assert.AreEqual(readStructure.AllowedLevelIncreaseStorage.Shift, structure.AllowedLevelIncreaseStorage.Shift); Assert.AreEqual(readStructure.CriticalOvertoppingDischarge.Mean, structure.CriticalOvertoppingDischarge.Mean); Assert.AreEqual(readStructure.CriticalOvertoppingDischarge.CoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation); Assert.AreEqual(readStructure.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); Assert.AreEqual(readStructure.FlowWidthAtBottomProtection.Mean, structure.FlowWidthAtBottomProtection.Mean); Assert.AreEqual(readStructure.FlowWidthAtBottomProtection.StandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation); Assert.AreEqual(readStructure.FlowWidthAtBottomProtection.Shift, structure.FlowWidthAtBottomProtection.Shift); Assert.AreEqual(readStructure.LevelCrestStructure.Mean, structure.LevelCrestStructure.Mean); Assert.AreEqual(readStructure.LevelCrestStructure.StandardDeviation, structure.LevelCrestStructure.StandardDeviation); Assert.AreEqual(readStructure.StorageStructureArea.Mean, structure.StorageStructureArea.Mean); Assert.AreEqual(readStructure.StorageStructureArea.CoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation); Assert.AreEqual(readStructure.WidthFlowApertures.Mean, structure.WidthFlowApertures.Mean); Assert.AreEqual(readStructure.WidthFlowApertures.StandardDeviation, structure.WidthFlowApertures.StandardDeviation); }
/// <summary> /// Removes the <paramref name="structure"/> and clears all dependent data, either directly or indirectly. /// </summary> /// <param name="structure">The structure to be removed.</param> /// <param name="failureMechanism">The <see cref="HeightStructuresFailureMechanism"/> /// to clear the data from.</param> /// <returns>All objects affected by the removal.</returns> /// <exception cref="ArgumentNullException">Thrown when any parameter is <c>null</c>.</exception> public static IEnumerable <IObservable> RemoveStructure(HeightStructure structure, HeightStructuresFailureMechanism failureMechanism) { if (structure == null) { throw new ArgumentNullException(nameof(structure)); } if (failureMechanism == null) { throw new ArgumentNullException(nameof(failureMechanism)); } IEnumerable <StructuresCalculation <HeightStructuresInput> > calculations = failureMechanism.Calculations.Cast <StructuresCalculation <HeightStructuresInput> >(); StructuresCalculation <HeightStructuresInput>[] calculationWithRemovedStructure = calculations .Where(c => ReferenceEquals(c.InputParameters.Structure, structure)) .ToArray(); List <IObservable> changedObservables = ClearStructureDependentData(calculationWithRemovedStructure); StructureCollection <HeightStructure> structures = failureMechanism.HeightStructures; structures.Remove(structure); changedObservables.Add(structures); return(changedObservables); }
public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImport() { // Setup var importTarget = new StructureCollection <HeightStructure>(); string filePath = Path.Combine(testDataPath, nameof(HeightStructuresImporter), "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp"); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var strategy = mocks.StrictMock <IStructureUpdateStrategy <HeightStructure> >(); strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(invocation.Arguments[1], filePath); var readStructures = (IEnumerable <HeightStructure>)invocation.Arguments[0]; Assert.AreEqual(1, readStructures.Count()); HeightStructure structure = readStructures.First(); var defaultStructure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "test", Location = new Point2D(0, 0), Id = "id" }); Assert.AreEqual(defaultStructure.StructureNormalOrientation, structure.StructureNormalOrientation); DistributionAssert.AreEqual(defaultStructure.FlowWidthAtBottomProtection, structure.FlowWidthAtBottomProtection); Assert.AreEqual(defaultStructure.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); }) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); ReferenceLine referenceLine = CreateReferenceLine(); var importer = new HeightStructuresImporter(importTarget, referenceLine, filePath, messageProvider, strategy); var importResult = false; // Call Action call = () => importResult = importer.Import(); // Assert TestHelper.AssertLogMessages(call, msgs => { string[] messages = msgs.ToArray(); Assert.AreEqual(5, messages.Length); const string structure = "'Coupure Den Oever (90k1)' (KUNST1)"; Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE1' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE3' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[1]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_HOOGTE6' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[2]); // Don't care about the other message. }); Assert.IsTrue(importResult); }
/// <summary> /// Reads the <see cref="HeightStructureEntity"/> and use the information to update a /// <see cref="HeightStructure"/>. /// </summary> /// <param name="entity">The <see cref="HeightStructureEntity"/> to create <see cref="HeightStructure"/> for.</param> /// <param name="collector">The object keeping track of read operations.</param> /// <returns>A new <see cref="HeightStructure"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="collector"/> is <c>null</c>.</exception> internal static HeightStructure Read(this HeightStructureEntity entity, ReadConversionCollector collector) { if (collector == null) { throw new ArgumentNullException(nameof(collector)); } if (collector.Contains(entity)) { return(collector.Get(entity)); } var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = entity.Name, Id = entity.Id, Location = new Point2D(entity.X.ToNullAsNaN(), entity.Y.ToNullAsNaN()), StructureNormalOrientation = (RoundedDouble)entity.StructureNormalOrientation.ToNullAsNaN(), LevelCrestStructure = { Mean = (RoundedDouble)entity.LevelCrestStructureMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.LevelCrestStructureStandardDeviation.ToNullAsNaN() }, FlowWidthAtBottomProtection = { Mean = (RoundedDouble)entity.FlowWidthAtBottomProtectionMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.FlowWidthAtBottomProtectionStandardDeviation.ToNullAsNaN() }, CriticalOvertoppingDischarge = { Mean = (RoundedDouble)entity.CriticalOvertoppingDischargeMean.ToNullAsNaN(), CoefficientOfVariation = (RoundedDouble)entity.CriticalOvertoppingDischargeCoefficientOfVariation.ToNullAsNaN() }, WidthFlowApertures = { Mean = (RoundedDouble)entity.WidthFlowAperturesMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.WidthFlowAperturesStandardDeviation.ToNullAsNaN() }, FailureProbabilityStructureWithErosion = entity.FailureProbabilityStructureWithErosion.ToNullAsNaN(), StorageStructureArea = { Mean = (RoundedDouble)entity.StorageStructureAreaMean.ToNullAsNaN(), CoefficientOfVariation = (RoundedDouble)entity.StorageStructureAreaCoefficientOfVariation.ToNullAsNaN() }, AllowedLevelIncreaseStorage = { Mean = (RoundedDouble)entity.AllowedLevelIncreaseStorageMean.ToNullAsNaN(), StandardDeviation = (RoundedDouble)entity.AllowedLevelIncreaseStorageStandardDeviation.ToNullAsNaN() } }); collector.Read(entity, structure); return(structure); }
public void Read_ValidEntity_ReturnHeightStructure() { // Setup var entity = new HeightStructureEntity { Name = "A", Id = "B", X = 1.1, Y = 2.2, StructureNormalOrientation = 3.3, LevelCrestStructureMean = 4.4, LevelCrestStructureStandardDeviation = 5.5, FlowWidthAtBottomProtectionMean = 6.6, FlowWidthAtBottomProtectionStandardDeviation = 7.7, CriticalOvertoppingDischargeMean = 8.8, CriticalOvertoppingDischargeCoefficientOfVariation = 9.9, WidthFlowAperturesMean = 10.10, WidthFlowAperturesStandardDeviation = 11.11, FailureProbabilityStructureWithErosion = 12.12, StorageStructureAreaMean = 13.13, StorageStructureAreaCoefficientOfVariation = 14.14, AllowedLevelIncreaseStorageMean = 15.15, AllowedLevelIncreaseStorageStandardDeviation = 16.16 }; var collector = new ReadConversionCollector(); // Call HeightStructure structure = entity.Read(collector); // Assert Assert.AreEqual(entity.Name, structure.Name); Assert.AreEqual(entity.Id, structure.Id); Assert.AreEqual(entity.X, structure.Location.X); Assert.AreEqual(entity.Y, structure.Location.Y); Assert.AreEqual(entity.StructureNormalOrientation, structure.StructureNormalOrientation.Value); Assert.AreEqual(entity.LevelCrestStructureMean, structure.LevelCrestStructure.Mean.Value); Assert.AreEqual(entity.LevelCrestStructureStandardDeviation, structure.LevelCrestStructure.StandardDeviation.Value); Assert.AreEqual(entity.FlowWidthAtBottomProtectionMean, structure.FlowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(entity.FlowWidthAtBottomProtectionStandardDeviation, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.AreEqual(entity.CriticalOvertoppingDischargeMean, structure.CriticalOvertoppingDischarge.Mean.Value); Assert.AreEqual(entity.CriticalOvertoppingDischargeCoefficientOfVariation, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.AreEqual(entity.WidthFlowAperturesMean, structure.WidthFlowApertures.Mean.Value); Assert.AreEqual(entity.WidthFlowAperturesStandardDeviation, structure.WidthFlowApertures.StandardDeviation.Value); Assert.AreEqual(entity.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); Assert.AreEqual(entity.StorageStructureAreaMean, structure.StorageStructureArea.Mean.Value); Assert.AreEqual(entity.StorageStructureAreaCoefficientOfVariation, structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.AreEqual(entity.AllowedLevelIncreaseStorageMean, structure.AllowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(entity.AllowedLevelIncreaseStorageStandardDeviation, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); }
public void Import_ValidFileWithConversionsBetweenVarianceTypes_WarnUserAboutConversion() { // Setup var importTarget = new StructureCollection <HeightStructure>(); string filePath = Path.Combine(testDataPath, "HeightStructuresVarianceConvert", "StructureNeedVarianceValueConversion.shp"); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var strategy = mocks.StrictMock <IStructureUpdateStrategy <HeightStructure> >(); strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(invocation.Arguments[1], filePath); var readStructures = (IEnumerable <HeightStructure>)invocation.Arguments[0]; Assert.AreEqual(1, readStructures.Count()); HeightStructure structure = readStructures.First(); Assert.AreEqual(0.12, structure.LevelCrestStructure.StandardDeviation.Value); Assert.AreEqual(0.24, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.AreEqual(1.0, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.AreEqual(0.97, structure.WidthFlowApertures.StandardDeviation.Value); Assert.AreEqual(1.84, structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.AreEqual(2.18, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); }) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); ReferenceLine referenceLine = CreateReferenceLine(); var importer = new HeightStructuresImporter(importTarget, referenceLine, filePath, messageProvider, strategy); var importResult = false; // Call Action call = () => importResult = importer.Import(); // Assert string[] expectedMessages = { "De variatie voor parameter 'KW_HOOGTE2' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 3).", "De variatie voor parameter 'KW_HOOGTE3' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 4).", "De variatie voor parameter 'KW_HOOGTE4' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 5).", "De variatie voor parameter 'KW_HOOGTE5' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 6).", "De variatie voor parameter 'KW_HOOGTE7' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 8).", "De variatie voor parameter 'KW_HOOGTE8' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 9)." }; TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); Assert.IsTrue(importResult); }
public void Read_NullValues_ReturnHeightStructureWithNaN() { // Setup var entity = new HeightStructureEntity { Name = "A", Id = "B", X = null, Y = null, StructureNormalOrientation = null, LevelCrestStructureMean = null, LevelCrestStructureStandardDeviation = null, FlowWidthAtBottomProtectionMean = null, FlowWidthAtBottomProtectionStandardDeviation = null, CriticalOvertoppingDischargeMean = null, CriticalOvertoppingDischargeCoefficientOfVariation = null, WidthFlowAperturesMean = null, WidthFlowAperturesStandardDeviation = null, FailureProbabilityStructureWithErosion = null, StorageStructureAreaMean = null, StorageStructureAreaCoefficientOfVariation = null, AllowedLevelIncreaseStorageMean = null, AllowedLevelIncreaseStorageStandardDeviation = null }; var collector = new ReadConversionCollector(); // Call HeightStructure structure = entity.Read(collector); // Assert Assert.IsNaN(structure.Location.X); Assert.IsNaN(structure.Location.Y); Assert.IsNaN(structure.StructureNormalOrientation); Assert.IsNaN(structure.LevelCrestStructure.Mean.Value); Assert.IsNaN(structure.LevelCrestStructure.StandardDeviation.Value); Assert.IsNaN(structure.FlowWidthAtBottomProtection.Mean.Value); Assert.IsNaN(structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.IsNaN(structure.CriticalOvertoppingDischarge.Mean.Value); Assert.IsNaN(structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.IsNaN(structure.WidthFlowApertures.Mean.Value); Assert.IsNaN(structure.WidthFlowApertures.StandardDeviation.Value); Assert.IsNaN(structure.FailureProbabilityStructureWithErosion); Assert.IsNaN(structure.StorageStructureArea.Mean.Value); Assert.IsNaN(structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.IsNaN(structure.AllowedLevelIncreaseStorage.Mean.Value); Assert.IsNaN(structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); }
public void Read_EntityRegistered_ReturnRegisteredStructure() { // Setup var entity = new HeightStructureEntity(); HeightStructure registeredStructure = new TestHeightStructure(); var collector = new ReadConversionCollector(); collector.Read(entity, registeredStructure); // Call HeightStructure readStructure = entity.Read(collector); // Assert Assert.AreSame(registeredStructure, readStructure); }
public void CopyProperties_FromStructureNull_ThrowsArgumentNullException() { // Setup var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "aName", Id = "anId", Location = new Point2D(0, 0) }); // Call TestDelegate call = () => structure.CopyProperties(null); // Assert string paramName = Assert.Throws <ArgumentNullException>(call).ParamName; Assert.AreEqual("fromStructure", paramName); }
public void Read_EntityNotReadBefore_RegisterEntity() { // Setup var entity = new HeightStructureEntity { Name = "name", Id = "id" }; var collector = new ReadConversionCollector(); // Precondition Assert.IsFalse(collector.Contains(entity)); // Call HeightStructure calculation = entity.Read(collector); // Assert Assert.IsTrue(collector.Contains(entity)); Assert.AreSame(calculation, collector.Get(entity)); }
/// <summary> /// Creates a <see cref="HeightStructureEntity"/> based on the information of the <see cref="HeightStructure"/>. /// </summary> /// <param name="structure">The structure 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="structure"/> resides within its parent.</param> /// <returns>A new <see cref="HeightStructureEntity"/>.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="registry"/> is <c>null</c>.</exception> internal static HeightStructureEntity Create(this HeightStructure structure, PersistenceRegistry registry, int order) { if (registry == null) { throw new ArgumentNullException(nameof(registry)); } if (registry.Contains(structure)) { return(registry.Get(structure)); } var entity = new HeightStructureEntity { Name = structure.Name.DeepClone(), Id = structure.Id.DeepClone(), X = structure.Location.X.ToNaNAsNull(), Y = structure.Location.Y.ToNaNAsNull(), StructureNormalOrientation = structure.StructureNormalOrientation.ToNaNAsNull(), AllowedLevelIncreaseStorageMean = structure.AllowedLevelIncreaseStorage.Mean.ToNaNAsNull(), AllowedLevelIncreaseStorageStandardDeviation = structure.AllowedLevelIncreaseStorage.StandardDeviation.ToNaNAsNull(), CriticalOvertoppingDischargeMean = structure.CriticalOvertoppingDischarge.Mean.ToNaNAsNull(), CriticalOvertoppingDischargeCoefficientOfVariation = structure.CriticalOvertoppingDischarge.CoefficientOfVariation.ToNaNAsNull(), FailureProbabilityStructureWithErosion = structure.FailureProbabilityStructureWithErosion.ToNaNAsNull(), FlowWidthAtBottomProtectionMean = structure.FlowWidthAtBottomProtection.Mean.ToNaNAsNull(), FlowWidthAtBottomProtectionStandardDeviation = structure.FlowWidthAtBottomProtection.StandardDeviation.ToNaNAsNull(), LevelCrestStructureMean = structure.LevelCrestStructure.Mean.ToNaNAsNull(), LevelCrestStructureStandardDeviation = structure.LevelCrestStructure.StandardDeviation.ToNaNAsNull(), StorageStructureAreaMean = structure.StorageStructureArea.Mean.ToNaNAsNull(), StorageStructureAreaCoefficientOfVariation = structure.StorageStructureArea.CoefficientOfVariation.ToNaNAsNull(), WidthFlowAperturesMean = structure.WidthFlowApertures.Mean.ToNaNAsNull(), WidthFlowAperturesStandardDeviation = structure.WidthFlowApertures.StandardDeviation.ToNaNAsNull(), Order = order }; registry.Register(entity, structure); return(entity); }
/// <summary> /// Registers a create operation for <paramref name="model"/> and the <paramref name="entity"/> /// that was constructed with the information. /// </summary> /// <param name="entity">The <see cref="HeightStructureEntity"/> to be registered.</param> /// <param name="model">The <see cref="HeightStructure"/> to be registered.</param> /// <exception cref="ArgumentNullException">Thrown when any of the input parameters is <c>null</c>.</exception> internal void Register(HeightStructureEntity entity, HeightStructure model) { Register(heightStructures, entity, model); }
public void UpdateStructuresWithImportedData_MultipleCalculationWithStructuresOneWithRemovedStructure_OnlyUpdatesCalculationWithRemovedStructure() { // Setup const string removedId = "affectedId"; const string unaffectedId = "unaffectedId"; const string unaffectedStructureName = "unaffectedStructure"; var removedStructure = new TestHeightStructure(removedId, "Old name"); var unaffectedStructure = new TestHeightStructure(unaffectedId, unaffectedStructureName); var affectedCalculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = removedStructure }, Output = new TestStructuresOutput() }; var unaffectedCalculation = new TestHeightStructuresCalculationScenario { InputParameters = { Structure = unaffectedStructure }, Output = new TestStructuresOutput() }; var failureMechanism = new HeightStructuresFailureMechanism { CalculationsGroup = { Children = { affectedCalculation, unaffectedCalculation } } }; StructureCollection <HeightStructure> targetDataCollection = failureMechanism.HeightStructures; targetDataCollection.AddRange(new[] { removedStructure, unaffectedStructure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); HeightStructure readUnaffectedStructure = new TestHeightStructure(unaffectedId, unaffectedStructureName); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readUnaffectedStructure }, sourceFilePath); // Assert Assert.IsFalse(affectedCalculation.HasOutput); Assert.IsNull(affectedCalculation.InputParameters.Structure); Assert.IsTrue(unaffectedCalculation.HasOutput); HeightStructure inputParametersUnaffectedStructure = unaffectedCalculation.InputParameters.Structure; Assert.AreSame(unaffectedStructure, inputParametersUnaffectedStructure); AssertHeightStructures(readUnaffectedStructure, inputParametersUnaffectedStructure); CollectionAssert.AreEquivalent(new IObservable[] { affectedCalculation, affectedCalculation.InputParameters, targetDataCollection }, affectedObjects); }
public void Create_NaNValue_ReturnEntityWithNullValue() { // Setup var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "A", Id = "B", Location = new Point2D(double.NaN, double.NaN), StructureNormalOrientation = RoundedDouble.NaN, AllowedLevelIncreaseStorage = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, CriticalOvertoppingDischarge = { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }, FailureProbabilityStructureWithErosion = double.NaN, FlowWidthAtBottomProtection = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, LevelCrestStructure = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN }, StorageStructureArea = { Mean = RoundedDouble.NaN, CoefficientOfVariation = RoundedDouble.NaN }, WidthFlowApertures = { Mean = RoundedDouble.NaN, StandardDeviation = RoundedDouble.NaN } }); var registry = new PersistenceRegistry(); // Call HeightStructureEntity entity = structure.Create(registry, 0); // Assert Assert.IsNull(entity.X); Assert.IsNull(entity.Y); Assert.IsNull(entity.StructureNormalOrientation); Assert.IsNull(entity.AllowedLevelIncreaseStorageMean); Assert.IsNull(entity.AllowedLevelIncreaseStorageStandardDeviation); Assert.IsNull(entity.CriticalOvertoppingDischargeMean); Assert.IsNull(entity.CriticalOvertoppingDischargeCoefficientOfVariation); Assert.IsNull(entity.FailureProbabilityStructureWithErosion); Assert.IsNull(entity.FlowWidthAtBottomProtectionMean); Assert.IsNull(entity.FlowWidthAtBottomProtectionStandardDeviation); Assert.IsNull(entity.LevelCrestStructureMean); Assert.IsNull(entity.LevelCrestStructureStandardDeviation); Assert.IsNull(entity.StorageStructureAreaMean); Assert.IsNull(entity.StorageStructureAreaCoefficientOfVariation); Assert.IsNull(entity.WidthFlowAperturesMean); Assert.IsNull(entity.WidthFlowAperturesStandardDeviation); }
public void Constructor_ValidData_ExpectedValues() { // Setup var location = new Point2D(1.22, 2.333); // Call var heightStructure = new HeightStructure( new HeightStructure.ConstructionProperties { Name = "aName", Id = "anId", Location = location, StructureNormalOrientation = (RoundedDouble)0.12345, LevelCrestStructure = { Mean = (RoundedDouble)234.567, StandardDeviation = (RoundedDouble)0.23456 }, FlowWidthAtBottomProtection = { Mean = (RoundedDouble)345.678, StandardDeviation = (RoundedDouble)0.34567 }, CriticalOvertoppingDischarge = { Mean = (RoundedDouble)456.789, CoefficientOfVariation = (RoundedDouble)0.45678 }, WidthFlowApertures = { Mean = (RoundedDouble)567.890, StandardDeviation = (RoundedDouble)0.56789 }, FailureProbabilityStructureWithErosion = 0.67890, StorageStructureArea = { Mean = (RoundedDouble)112.223, CoefficientOfVariation = (RoundedDouble)0.11222 }, AllowedLevelIncreaseStorage = { Mean = (RoundedDouble)225.336, StandardDeviation = (RoundedDouble)0.22533 } }); // Assert Assert.IsInstanceOf <StructureBase>(heightStructure); Assert.AreEqual("aName", heightStructure.Name); Assert.AreEqual("anId", heightStructure.Id); Assert.IsInstanceOf <Point2D>(heightStructure.Location); Assert.AreEqual(location.X, heightStructure.Location.X); Assert.AreEqual(location.Y, heightStructure.Location.Y); Assert.AreEqual(2, heightStructure.StructureNormalOrientation.NumberOfDecimalPlaces); Assert.AreEqual(0.12, heightStructure.StructureNormalOrientation.Value); NormalDistribution levelCrestStructure = heightStructure.LevelCrestStructure; Assert.AreEqual(2, levelCrestStructure.Mean.NumberOfDecimalPlaces); Assert.AreEqual(234.57, levelCrestStructure.Mean.Value); Assert.AreEqual(2, levelCrestStructure.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.23, levelCrestStructure.StandardDeviation.Value); LogNormalDistribution flowWidthAtBottomProtection = heightStructure.FlowWidthAtBottomProtection; Assert.AreEqual(2, flowWidthAtBottomProtection.Mean.NumberOfDecimalPlaces); Assert.AreEqual(345.68, flowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(2, flowWidthAtBottomProtection.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.35, flowWidthAtBottomProtection.StandardDeviation.Value); VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge = heightStructure.CriticalOvertoppingDischarge; Assert.AreEqual(2, criticalOvertoppingDischarge.Mean.NumberOfDecimalPlaces); Assert.AreEqual(456.79, criticalOvertoppingDischarge.Mean.Value); Assert.AreEqual(2, criticalOvertoppingDischarge.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(0.46, criticalOvertoppingDischarge.CoefficientOfVariation.Value); NormalDistribution widthFlowApertures = heightStructure.WidthFlowApertures; Assert.AreEqual(2, widthFlowApertures.Mean.NumberOfDecimalPlaces); Assert.AreEqual(567.89, widthFlowApertures.Mean.Value); Assert.AreEqual(2, widthFlowApertures.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.57, widthFlowApertures.StandardDeviation.Value); Assert.AreEqual(0.67890, heightStructure.FailureProbabilityStructureWithErosion); VariationCoefficientLogNormalDistribution storageStructureArea = heightStructure.StorageStructureArea; Assert.AreEqual(2, storageStructureArea.Mean.NumberOfDecimalPlaces); Assert.AreEqual(112.22, storageStructureArea.Mean.Value); Assert.AreEqual(2, storageStructureArea.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(0.11, storageStructureArea.CoefficientOfVariation.Value); LogNormalDistribution allowedLevelIncreaseStorage = heightStructure.AllowedLevelIncreaseStorage; Assert.AreEqual(2, allowedLevelIncreaseStorage.Mean.NumberOfDecimalPlaces); Assert.AreEqual(225.34, allowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(2, allowedLevelIncreaseStorage.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.23, allowedLevelIncreaseStorage.StandardDeviation.Value); }
public void CopyProperties_FromStructure_UpdatesProperties() { // Setup var random = new Random(123); var structure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "aName", Id = "anId", Location = new Point2D(0, 0) }); var otherStructure = new HeightStructure(new HeightStructure.ConstructionProperties { Name = "otherName", Id = "otherId", Location = new Point2D(1, 1), StructureNormalOrientation = random.NextRoundedDouble(), AllowedLevelIncreaseStorage = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() }, CriticalOvertoppingDischarge = { Mean = random.NextRoundedDouble(), CoefficientOfVariation = random.NextRoundedDouble() }, FailureProbabilityStructureWithErosion = random.NextDouble(), FlowWidthAtBottomProtection = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() }, LevelCrestStructure = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() }, StorageStructureArea = { Mean = random.NextRoundedDouble(), CoefficientOfVariation = random.NextRoundedDouble() }, WidthFlowApertures = { Mean = random.NextRoundedDouble(), StandardDeviation = random.NextRoundedDouble() } }); // Call structure.CopyProperties(otherStructure); // Assert Assert.AreNotEqual(otherStructure.Id, structure.Id); Assert.AreEqual(otherStructure.Name, structure.Name); TestHelper.AssertAreEqualButNotSame(otherStructure.Location, structure.Location); Assert.AreEqual(otherStructure.StructureNormalOrientation, structure.StructureNormalOrientation); TestHelper.AssertAreEqualButNotSame(otherStructure.AllowedLevelIncreaseStorage, structure.AllowedLevelIncreaseStorage); TestHelper.AssertAreEqualButNotSame(otherStructure.CriticalOvertoppingDischarge, structure.CriticalOvertoppingDischarge); Assert.AreEqual(otherStructure.FailureProbabilityStructureWithErosion, structure.FailureProbabilityStructureWithErosion); TestHelper.AssertAreEqualButNotSame(otherStructure.FlowWidthAtBottomProtection, structure.FlowWidthAtBottomProtection); TestHelper.AssertAreEqualButNotSame(otherStructure.LevelCrestStructure, structure.LevelCrestStructure); TestHelper.AssertAreEqualButNotSame(otherStructure.StorageStructureArea, structure.StorageStructureArea); TestHelper.AssertAreEqualButNotSame(otherStructure.WidthFlowApertures, structure.WidthFlowApertures); }
public void Constructor_DefaultConstructorProperties_ExpectedValues() { // Setup var location = new Point2D(1.22, 2.333); // Call var heightStructure = new HeightStructure( new HeightStructure.ConstructionProperties { Name = "aName", Id = "anId", Location = location }); // Assert Assert.IsInstanceOf <StructureBase>(heightStructure); Assert.AreEqual("aName", heightStructure.Name); Assert.AreEqual("anId", heightStructure.Id); Assert.IsInstanceOf <Point2D>(heightStructure.Location); Assert.AreEqual(location.X, heightStructure.Location.X); Assert.AreEqual(location.Y, heightStructure.Location.Y); Assert.AreEqual(2, heightStructure.StructureNormalOrientation.NumberOfDecimalPlaces); Assert.IsNaN(heightStructure.StructureNormalOrientation); NormalDistribution levelCrestStructure = heightStructure.LevelCrestStructure; Assert.AreEqual(2, levelCrestStructure.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, levelCrestStructure.Mean.Value); Assert.AreEqual(2, levelCrestStructure.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.05, levelCrestStructure.StandardDeviation.Value); LogNormalDistribution flowWidthAtBottomProtection = heightStructure.FlowWidthAtBottomProtection; Assert.AreEqual(2, flowWidthAtBottomProtection.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, flowWidthAtBottomProtection.Mean.Value); Assert.AreEqual(2, flowWidthAtBottomProtection.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.05, flowWidthAtBottomProtection.StandardDeviation.Value); VariationCoefficientLogNormalDistribution criticalOvertoppingDischarge = heightStructure.CriticalOvertoppingDischarge; Assert.AreEqual(2, criticalOvertoppingDischarge.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, criticalOvertoppingDischarge.Mean.Value); Assert.AreEqual(2, criticalOvertoppingDischarge.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(0.15, criticalOvertoppingDischarge.CoefficientOfVariation.Value); NormalDistribution widthFlowApertures = heightStructure.WidthFlowApertures; Assert.AreEqual(2, widthFlowApertures.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, widthFlowApertures.Mean.Value); Assert.AreEqual(2, widthFlowApertures.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.2, widthFlowApertures.StandardDeviation.Value); Assert.AreEqual(1, heightStructure.FailureProbabilityStructureWithErosion); VariationCoefficientLogNormalDistribution storageStructureArea = heightStructure.StorageStructureArea; Assert.AreEqual(2, storageStructureArea.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, storageStructureArea.Mean.Value); Assert.AreEqual(2, storageStructureArea.CoefficientOfVariation.NumberOfDecimalPlaces); Assert.AreEqual(0.1, storageStructureArea.CoefficientOfVariation.Value); LogNormalDistribution allowedLevelIncreaseStorage = heightStructure.AllowedLevelIncreaseStorage; Assert.AreEqual(2, allowedLevelIncreaseStorage.Mean.NumberOfDecimalPlaces); Assert.AreEqual(double.NaN, allowedLevelIncreaseStorage.Mean.Value); Assert.AreEqual(2, allowedLevelIncreaseStorage.StandardDeviation.NumberOfDecimalPlaces); Assert.AreEqual(0.1, allowedLevelIncreaseStorage.StandardDeviation.Value); }
public void UpdateStructuresWithImportedData_SingleChange_UpdatesOnlySingleChange(HeightStructure readStructure) { // Setup HeightStructure structure = new TestHeightStructure(); var failureMechanism = new HeightStructuresFailureMechanism(); StructureCollection <HeightStructure> targetCollection = failureMechanism.HeightStructures; targetCollection.AddRange(new[] { structure }, sourceFilePath); var strategy = new HeightStructureUpdateDataStrategy(failureMechanism); // Call IEnumerable <IObservable> affectedObjects = strategy.UpdateStructuresWithImportedData(new[] { readStructure }, sourceFilePath); // Assert AssertHeightStructures(readStructure, structure); CollectionAssert.AreEqual(new IObservable[] { targetCollection, structure }, affectedObjects); }
/// <summary> /// Checks whether a create operations has been registered for the given <paramref name="model"/>. /// </summary> /// <param name="model">The <see cref="HeightStructure"/> to check for.</param> /// <returns><c>true</c> if the <see cref="model"/> was registered before, <c>false</c> otherwise.</returns> /// <exception cref="ArgumentNullException">Thrown when <paramref name="model"/> is <c>null</c>.</exception> internal bool Contains(HeightStructure model) { return(ContainsValue(heightStructures, model)); }
/// <summary> /// Obtains the <see cref="HeightStructureEntity"/> which was registered for the /// given <paramref name="model"/>. /// </summary> /// <param name="model">The <see cref="HeightStructure"/> for which a read operation has been registered.</param> /// <returns>The constructed <see cref="HeightStructureEntity"/>.</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(HeightStructure)"/> to find out whether a /// create operation has been registered for <paramref name="model"/>.</remarks> internal HeightStructureEntity Get(HeightStructure model) { return(Get(heightStructures, model)); }
public void IsStructureInputSynchronized_StructureAndInputNotInSync_ReturnFalse(HeightStructure modifiedStructure) { // Setup var structure = new TestHeightStructure(); var input = new HeightStructuresInput { Structure = structure }; structure.CopyProperties(modifiedStructure); // Call bool isStructureInputSynchronized = input.IsStructureInputSynchronized; // Assert Assert.IsFalse(isStructureInputSynchronized); }