public void ScenariosView_ChangeStructureOfCalculation_ChangesCorrectlyObservedAndSynced() { // Setup var mocks = new MockRepository(); var messageProvider = mocks.Stub <IImporterMessageProvider>(); mocks.ReplayAll(); using (var form = new Form()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); StabilityPointStructuresFailureMechanism failureMechanism = assessmentSection.StabilityPointStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); var view = new StabilityPointStructuresScenariosView(assessmentSection.StabilityPointStructures.CalculationsGroup, assessmentSection.StabilityPointStructures); form.Controls.Add(view); form.Show(); var structuresImporter = new StabilityPointStructuresImporter(assessmentSection.StabilityPointStructures.StabilityPointStructures, assessmentSection.ReferenceLine, filePath, messageProvider, new StabilityPointStructureReplaceDataStrategy(failureMechanism)); structuresImporter.Import(); foreach (StabilityPointStructure structure in assessmentSection.StabilityPointStructures.StabilityPointStructures) { assessmentSection.StabilityPointStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario <StabilityPointStructuresInput> { Name = NamingHelper.GetUniqueName(assessmentSection.StabilityPointStructures.CalculationsGroup.Children, structure.Name + " Calculation", c => c.Name), InputParameters = { Structure = structure } }); } var listBox = (ListBox) new ControlTester("listBox").TheObject; var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; listBox.SelectedItem = failureMechanism.Sections.ElementAt(50); // Precondition DataGridViewRowCollection rows = dataGridView.Rows; Assert.AreEqual(1, rows.Count); Assert.AreEqual("Eerste kunstwerk punt 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue); // Call CalculationGroup calculationsGroup = assessmentSection.StabilityPointStructures.CalculationsGroup; ((StructuresCalculation <StabilityPointStructuresInput>)calculationsGroup.Children[1]).InputParameters.Structure = ((StructuresCalculation <StabilityPointStructuresInput>)calculationsGroup.Children[0]).InputParameters.Structure; calculationsGroup.NotifyObservers(); // Assert Assert.AreEqual(2, rows.Count); Assert.AreEqual("Eerste kunstwerk punt 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue); Assert.AreEqual("Tweede kunstwerk punt 6-3 Calculation", rows[1].Cells[nameColumnIndex].FormattedValue); } mocks.VerifyAll(); }
public void Import_ValidIncompleteFile_LogAndFalse() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); mocks.ReplayAll(); string filePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp"); ReferenceLine referenceLine = CreateReferenceLine(); var importTarget = new StructureCollection <StabilityPointStructure>(); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert string csvFilePath = Path.ChangeExtension(filePath, "csv"); string message = CreateExpectedErrorMessage(csvFilePath, "Gemaal Leemans (93k3)", "KUNST2", new[] { "Geen geldige parameter definities gevonden." }); TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error)); Assert.IsFalse(importResult); Assert.AreEqual(0, importTarget.Count); }
public void Constructor_Always_ExpectedValues() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); mocks.ReplayAll(); // Call var importer = new StabilityPointStructuresImporter(testImportTarget, testReferenceLine, testFilePath, messageProvider, updateStrategy); // Assert Assert.IsInstanceOf <StructuresImporter <StabilityPointStructure> >(importer); }
public void Import_NoParameterIdsDefinedAndOnlyDuplicateUnknownParameterId_TrueAndImportTargetUpdated() { // Setup var importTarget = new StructureCollection <StabilityPointStructure>(); string filePath = Path.Combine(commonIoTestDataPath, "StructuresWithOnlyDuplicateIrrelevantParameterInCsv", "Kunstwerken.shp"); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); mocks.ReplayAll(); var referencePoints = new List <Point2D> { new Point2D(154493.618, 568995.991), new Point2D(156844.169, 574771.498), new Point2D(157910.502, 579115.458), new Point2D(163625.153, 585151.261) }; var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert string csvFilePath = Path.ChangeExtension(filePath, "csv"); string message = CreateExpectedErrorMessage(csvFilePath, "Eerste kunstwerk 6-3", "KWK_1", new[] { "Geen geldige parameter definities gevonden." }); TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error)); Assert.IsFalse(importResult); Assert.AreEqual(0, importTarget.Count); }
public void Import_ParameterIdsWithVaryingCase_TrueAndImportTargetUpdated() { // Setup string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpRandomCaseHeaderCsv", "Kunstwerken.shp"); var importTarget = new StructureCollection <StabilityPointStructure>(); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i => { Assert.AreEqual(filePath, i.Arguments[1]); Assert.AreEqual(4, ((IEnumerable <StabilityPointStructure>)i.Arguments[0]).Count()); }); mocks.ReplayAll(); var referencePoints = new List <Point2D> { new Point2D(154493.618, 568995.991), new Point2D(156844.169, 574771.498), new Point2D(157910.502, 579115.458), new Point2D(163625.153, 585151.261) }; var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert TestHelper.AssertLogMessageIsGenerated(call, $"Gegevens zijn geïmporteerd vanuit bestand '{filePath}'.", 9); Assert.IsTrue(importResult); }
public void Import_AllParameterIdsDefinedAndDuplicateUnknownParameterId_TrueAndImportTargetUpdated() { // Setup var importTarget = new StructureCollection <StabilityPointStructure>(); string filePath = Path.Combine(commonIoTestDataPath, "StructuresWithDuplicateIrrelevantParameterInCsv", "Kunstwerken.shp"); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var strategy = mocks.StrictMock <IStructureUpdateStrategy <StabilityPointStructure> >(); strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments() .WhenCalled(invocation => { Assert.AreSame(invocation.Arguments[1], filePath); var readStructures = (IEnumerable <StabilityPointStructure>)invocation.Arguments[0]; Assert.AreEqual(1, readStructures.Count()); }) .Return(Enumerable.Empty <IObservable>()); mocks.ReplayAll(); var referencePoints = new List <Point2D> { new Point2D(154493.618, 568995.991), new Point2D(156844.169, 574771.498), new Point2D(157910.502, 579115.458), new Point2D(163625.153, 585151.261) }; var referenceLine = new ReferenceLine(); referenceLine.SetGeometry(referencePoints); var importer = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, strategy); // Call bool importResult = importer.Import(); // Assert Assert.IsTrue(importResult); }
public void DoPostImport_UpdateStrategyReturningObservables_AllObservablesNotified() { var messageProvider = mocks.Stub <IImporterMessageProvider>(); var observableA = mocks.StrictMock <IObservable>(); observableA.Expect(o => o.NotifyObservers()); var observableB = mocks.StrictMock <IObservable>(); observableB.Expect(o => o.NotifyObservers()); IObservable[] observables = { observableA, observableB }; var strategy = mocks.StrictMock <IStructureUpdateStrategy <StabilityPointStructure> >(); strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().Return(observables); mocks.ReplayAll(); string filePath = Path.Combine(testDataPath, nameof(StabilityPointStructuresImporter), "MissingParameters", "Kunstwerken.shp") ; var importTarget = new StructureCollection <StabilityPointStructure>(); ReferenceLine referenceLine = CreateReferenceLine(); var importer = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, strategy); importer.Import(); // Call importer.DoPostImport(); // Assert // Assertions performed in TearDown }
public void Import_InvalidCsvFile_LogAndTrue() { // Setup var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); mocks.ReplayAll(); string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpIncompleteCsv", "Kunstwerken.shp"); ReferenceLine referenceLine = CreateReferenceLine(); var importTarget = new StructureCollection <StabilityPointStructure>(); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert string csvFilePath = Path.ChangeExtension(filePath, "csv"); string message = CreateExpectedErrorMessage( csvFilePath, "Coupure Den Oever (90k1)", "KUNST1", new[] { "Parameter 'KW_STERSTAB9' komt meerdere keren voor.", "De waarde voor parameter 'KW_STERSTAB10' op regel 37, kolom 'Numeriekewaarde', moet een getal zijn groter dan 0." }); TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error), 1); Assert.IsFalse(importResult); Assert.AreEqual(0, importTarget.Count); }
public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImportWithDefaultValues() { // Setup string filePath = Path.Combine(testDataPath, nameof(StabilityPointStructuresImporter), "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp"); var importTarget = new StructureCollection <StabilityPointStructure>(); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.Stub <IStructureUpdateStrategy <StabilityPointStructure> >(); updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i => { Assert.AreEqual(filePath, i.Arguments[1]); var readStructures = (IEnumerable <StabilityPointStructure>)i.Arguments[0]; Assert.AreEqual(1, readStructures.Count()); StabilityPointStructure importedStructure = readStructures.First(); var defaultStructure = new StabilityPointStructure(new StabilityPointStructure.ConstructionProperties { Name = "test", Location = new Point2D(0, 0), Id = "id" }); DistributionAssert.AreEqual(defaultStructure.StorageStructureArea, importedStructure.StorageStructureArea); DistributionAssert.AreEqual(defaultStructure.ThresholdHeightOpenWeir, importedStructure.ThresholdHeightOpenWeir); DistributionAssert.AreEqual(defaultStructure.InsideWaterLevelFailureConstruction, importedStructure.InsideWaterLevelFailureConstruction); Assert.AreEqual(defaultStructure.LevellingCount, importedStructure.LevellingCount); DistributionAssert.AreEqual(defaultStructure.AreaFlowApertures, importedStructure.AreaFlowApertures); }); mocks.ReplayAll(); ReferenceLine referenceLine = CreateReferenceLine(); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert TestHelper.AssertLogMessages(call, msgs => { string[] messages = msgs.ToArray(); Assert.AreEqual(12, messages.Length); const string structure = "'Coupure Den Oever (90k1)' (KUNST1)"; Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_STERSTAB2' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_STERSTAB6' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[4]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_STERSTAB12' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[7]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_STERSTAB20' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[9]); Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_STERSTAB25' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[10]); // Don't care about the other messages. }); Assert.IsTrue(importResult); }
public void Import_VarianceValuesNeedConversion_WarnUserAboutConversion() { // Setup string filePath = Path.Combine(testDataPath, "StructuresVarianceValueConversion", "Kunstwerken.shp"); var importTarget = new StructureCollection <StabilityPointStructure>(); var messageProvider = mocks.Stub <IImporterMessageProvider>(); var updateStrategy = mocks.StrictMock <IStructureUpdateStrategy <StabilityPointStructure> >(); updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i => { Assert.AreEqual(filePath, i.Arguments[1]); var structures = (IEnumerable <StabilityPointStructure>)i.Arguments[0]; Assert.AreEqual(1, structures.Count()); StabilityPointStructure structure = structures.First(); Assert.AreEqual(0.5, structure.StorageStructureArea.CoefficientOfVariation.Value); Assert.AreEqual(2, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value); Assert.AreEqual(4, structure.WidthFlowApertures.StandardDeviation.Value); Assert.AreEqual(4, structure.InsideWaterLevel.StandardDeviation.Value); Assert.AreEqual(6, structure.ThresholdHeightOpenWeir.StandardDeviation.Value); Assert.AreEqual(1.5, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value); Assert.AreEqual(8, structure.FlowWidthAtBottomProtection.StandardDeviation.Value); Assert.AreEqual(2, structure.ConstructiveStrengthLinearLoadModel.CoefficientOfVariation.Value); Assert.AreEqual(2.5, structure.ConstructiveStrengthQuadraticLoadModel.CoefficientOfVariation.Value); Assert.AreEqual(10, structure.BankWidth.StandardDeviation.Value); Assert.AreEqual(12, structure.InsideWaterLevelFailureConstruction.StandardDeviation.Value); Assert.AreEqual(14, structure.LevelCrestStructure.StandardDeviation.Value); Assert.AreEqual(3.5, structure.FailureCollisionEnergy.CoefficientOfVariation.Value); Assert.AreEqual(4, structure.ShipMass.CoefficientOfVariation.Value); Assert.AreEqual(4.5, structure.ShipVelocity.CoefficientOfVariation.Value); Assert.AreEqual(5, structure.StabilityLinearLoadModel.CoefficientOfVariation.Value); Assert.AreEqual(5.5, structure.StabilityQuadraticLoadModel.CoefficientOfVariation.Value); Assert.AreEqual(22, structure.AreaFlowApertures.StandardDeviation.Value); }); mocks.ReplayAll(); ReferenceLine referenceLine = CreateReferenceLine(); var structuresImporter = new StabilityPointStructuresImporter(importTarget, referenceLine, filePath, messageProvider, updateStrategy); // Call var importResult = false; Action call = () => importResult = structuresImporter.Import(); // Assert string[] expectedMessages = { "De variatie voor parameter 'KW_STERSTAB2' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 26).", "De variatie voor parameter 'KW_STERSTAB3' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 27).", "De variatie voor parameter 'KW_STERSTAB4' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 28).", "De variatie voor parameter 'KW_STERSTAB5' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 29).", "De variatie voor parameter 'KW_STERSTAB6' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 30).", "De variatie voor parameter 'KW_STERSTAB7' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 31).", "De variatie voor parameter 'KW_STERSTAB8' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 32).", "De variatie voor parameter 'KW_STERSTAB9' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 33).", "De variatie voor parameter 'KW_STERSTAB10' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 34).", "De variatie voor parameter 'KW_STERSTAB11' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 35).", "De variatie voor parameter 'KW_STERSTAB12' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 36).", "De variatie voor parameter 'KW_STERSTAB14' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 38).", "De variatie voor parameter 'KW_STERSTAB17' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 41).", "De variatie voor parameter 'KW_STERSTAB18' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 42).", "De variatie voor parameter 'KW_STERSTAB19' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 43).", "De variatie voor parameter 'KW_STERSTAB23' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 47).", "De variatie voor parameter 'KW_STERSTAB24' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 48).", "De variatie voor parameter 'KW_STERSTAB25' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 49)." }; TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages); Assert.IsTrue(importResult); }
public void ScenariosView_GenerateCalculations_ChangesCorrectlyObservedAndSynced() { // Setup var mocks = new MockRepository(); var messageProvider = mocks.Stub <IImporterMessageProvider>(); mocks.ReplayAll(); using (var form = new Form()) { var assessmentSection = new AssessmentSection(AssessmentSectionComposition.Dike); DataImportHelper.ImportReferenceLine(assessmentSection); StabilityPointStructuresFailureMechanism failureMechanism = assessmentSection.StabilityPointStructures; DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism); CalculationGroup calculationsGroup = assessmentSection.StabilityPointStructures.CalculationsGroup; var view = new StabilityPointStructuresScenariosView(calculationsGroup, assessmentSection.StabilityPointStructures); form.Controls.Add(view); form.Show(); var structuresImporter = new StabilityPointStructuresImporter(assessmentSection.StabilityPointStructures.StabilityPointStructures, assessmentSection.ReferenceLine, filePath, messageProvider, new StabilityPointStructureReplaceDataStrategy(failureMechanism)); structuresImporter.Import(); var listBox = (ListBox) new ControlTester("listBox").TheObject; var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject; listBox.SelectedItem = failureMechanism.Sections.ElementAt(50); // Precondition DataGridViewRowCollection rows = dataGridView.Rows; CollectionAssert.IsEmpty(rows); // Call foreach (StabilityPointStructure structure in assessmentSection.StabilityPointStructures.StabilityPointStructures) { calculationsGroup.Children.Add(new StructuresCalculationScenario <StabilityPointStructuresInput> { Name = NamingHelper.GetUniqueName(((CalculationGroup)view.Data).Children, structure.Name, c => c.Name), InputParameters = { Structure = structure } }); } calculationsGroup.NotifyObservers(); // Assert Assert.AreEqual(1, rows.Count); DataGridViewCellCollection cells = rows[0].Cells; Assert.AreEqual(4, cells.Count); Assert.IsTrue(Convert.ToBoolean(cells[isRelevantColumnIndex].FormattedValue)); Assert.AreEqual(new RoundedDouble(2, 100).ToString(), cells[contributionColumnIndex].FormattedValue); Assert.AreEqual("Eerste kunstwerk punt 6-3", cells[nameColumnIndex].FormattedValue); Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue); } mocks.VerifyAll(); }