Пример #1
0
        public void Import_InvalidCsvFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();
            string filePath = Path.Combine(commonIoTestDataPath, "CorrectShpIncompleteCsv",
                                           "Kunstwerken.shp");

            ReferenceLine referenceLine      = CreateReferenceLine();
            var           importTarget       = new StructureCollection <ClosingStructure>();
            var           structuresImporter = new ClosingStructuresImporter(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[]
            {
                "De waarde voor parameter 'KW_BETSLUIT3' op regel 13, kolom 'Numeriekewaarde', moet in het bereik [0,0, 360,0] liggen.",
                "Parameter 'KW_BETSLUIT5' komt meerdere keren voor."
            });

            TestHelper.AssertLogMessageWithLevelIsGenerated(call, Tuple.Create(message, LogLevelConstant.Error), 1
                                                            );
            Assert.IsFalse(importResult);
            Assert.AreEqual(0, importTarget.Count);
            Assert.IsNull(importTarget.SourcePath);
        }
        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);
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                var view = new ClosingStructuresScenariosView(assessmentSection.ClosingStructures.CalculationsGroup, assessmentSection.ClosingStructures);
                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new ClosingStructuresImporter(assessmentSection.ClosingStructures.ClosingStructures,
                                                                       assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                       new ClosingStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                foreach (ClosingStructure structure in assessmentSection.ClosingStructures.ClosingStructures)
                {
                    assessmentSection.ClosingStructures.CalculationsGroup.Children.Add(new StructuresCalculationScenario <ClosingStructuresInput>
                    {
                        Name            = NamingHelper.GetUniqueName(assessmentSection.ClosingStructures.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(32);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                Assert.AreEqual(1, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);

                // Call
                CalculationGroup calculationsGroup = assessmentSection.ClosingStructures.CalculationsGroup;
                ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[1]).InputParameters.Structure =
                    ((StructuresCalculation <ClosingStructuresInput>)calculationsGroup.Children[0]).InputParameters.Structure;
                calculationsGroup.NotifyObservers();

                // Assert
                Assert.AreEqual(2, rows.Count);
                Assert.AreEqual("Eerste kunstwerk sluiting 6-3 Calculation", rows[0].Cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("Tweede kunstwerk sluiting 6-3 Calculation", rows[1].Cells[nameColumnIndex].FormattedValue);
            }

            mocks.VerifyAll();
        }
Пример #3
0
        public void Import_ValidIncompleteFile_LogAndFalse()
        {
            // Setup
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            mocks.ReplayAll();

            string filePath = Path.Combine(commonIoTestDataPath, "CorrectFiles", "Kunstwerken.shp");

            ReferenceLine referenceLine = CreateReferenceLine();
            var           importTarget  = new StructureCollection <ClosingStructure>();
            var           importer      = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                                        messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.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);
            Assert.IsNull(importTarget.SourcePath);
        }
Пример #4
0
        public void Import_MissingParametersAndDuplicateIrrelevantParameter_LogWarningAndContinueImportWithDefaultValues()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, nameof(ClosingStructuresImporter),
                                               "MissingAndDuplicateIrrelevantParameters", "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var defaultStructure = new ClosingStructure(new ClosingStructure.ConstructionProperties
                {
                    Name     = "test",
                    Location = new Point2D(0, 0),
                    Id       = "id"
                });

                var readStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, readStructures.Count());
                ClosingStructure importedStructure = readStructures.First();
                DistributionAssert.AreEqual(defaultStructure.StorageStructureArea, importedStructure.StorageStructureArea);
                DistributionAssert.AreEqual(defaultStructure.LevelCrestStructureNotClosing, importedStructure.LevelCrestStructureNotClosing);
                DistributionAssert.AreEqual(defaultStructure.AreaFlowApertures, importedStructure.AreaFlowApertures);
                Assert.AreEqual(defaultStructure.FailureProbabilityReparation, importedStructure.FailureProbabilityReparation);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var structuresImporter = new ClosingStructuresImporter(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(10, messages.Length);

                const string structure = "'Coupure Den Oever (90k1)' (KUNST1)";

                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT1' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[0]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT5' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[3]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT8' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[6]);
                Assert.AreEqual($"Geen definitie gevonden voor parameter 'KW_BETSLUIT14' van kunstwerk {structure}. Er wordt een standaard waarde gebruikt.", messages[8]);
                // Don't care about the other messages.
            });
            Assert.IsTrue(importResult);
        }
Пример #5
0
        public void Import_VarianceValuesNeedConversion_WarnUserAboutConversion()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(testDataPath, "StructuresVarianceValueConversion",
                                               "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);

                var closingStructures = (IEnumerable <ClosingStructure>)i.Arguments[0];
                Assert.AreEqual(1, closingStructures.Count());

                ClosingStructure structure = closingStructures.First();
                Assert.AreEqual(0.2, structure.StorageStructureArea.CoefficientOfVariation.Value);
                Assert.AreEqual(20, structure.AllowedLevelIncreaseStorage.StandardDeviation.Value);
                Assert.AreEqual(50, structure.WidthFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(2.2, structure.LevelCrestStructureNotClosing.StandardDeviation.Value);
                Assert.AreEqual(3.3, structure.InsideWaterLevel.StandardDeviation.Value);
                Assert.AreEqual(4.4, structure.ThresholdHeightOpenWeir.StandardDeviation.Value);
                Assert.AreEqual(5.5, structure.AreaFlowApertures.StandardDeviation.Value);
                Assert.AreEqual(0.1, structure.CriticalOvertoppingDischarge.CoefficientOfVariation.Value);
                Assert.AreEqual(6.6, structure.FlowWidthAtBottomProtection.StandardDeviation.Value);
            });
            mocks.ReplayAll();

            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                         messageProvider, updateStrategy);

            // Call
            var    importResult = false;
            Action call         = () => importResult = importer.Import();

            // Assert
            string[] expectedMessages =
            {
                "De variatie voor parameter 'KW_BETSLUIT1' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 10).",
                "De variatie voor parameter 'KW_BETSLUIT2' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 11).",
                "De variatie voor parameter 'KW_BETSLUIT4' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 13).",
                "De variatie voor parameter 'KW_BETSLUIT5' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 14).",
                "De variatie voor parameter 'KW_BETSLUIT6' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 15).",
                "De variatie voor parameter 'KW_BETSLUIT7' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 16).",
                "De variatie voor parameter 'KW_BETSLUIT8' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 17).",
                "De variatie voor parameter 'KW_BETSLUIT9' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een variatiecoëfficiënt (regel 18).",
                "De variatie voor parameter 'KW_BETSLUIT10' van kunstwerk 'Coupure Den Oever (90k1)' (KUNST1) wordt omgerekend in een standaardafwijking (regel 19)."
            };
            TestHelper.AssertLogMessagesAreGenerated(call, expectedMessages);
            Assert.IsTrue(importResult);
        }
Пример #6
0
        public void Import_NoParameterIdsDefinedAndOnlyDuplicateUnknownParameterId_TrueAndImportTargetUpdated()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(commonIoTestDataPath, "StructuresWithOnlyDuplicateIrrelevantParameterInCsv",
                                               "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.Stub <IStructureUpdateStrategy <ClosingStructure> >();

            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 ClosingStructuresImporter(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);
        }
Пример #7
0
        public void Import_AllParameterIdsDefinedAndDuplicateUnknownParameterId_TrueAndImportTargetUpdated()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(commonIoTestDataPath, "StructuresWithDuplicateIrrelevantParameterInCsv",
                                               "Kunstwerken.shp");

            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var strategy        = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments()
            .WhenCalled(invocation =>
            {
                Assert.AreSame(invocation.Arguments[1], filePath);

                var readStructures = (IEnumerable <ClosingStructure>)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 ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                         messageProvider, strategy);

            // Call
            bool importResult = importer.Import();

            // Assert
            Assert.IsTrue(importResult);
        }
Пример #8
0
        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 <ClosingStructure> >();

            strategy.Expect(s => s.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().Return(observables);
            mocks.ReplayAll();

            string filePath = Path.Combine(testDataPath, nameof(ClosingStructuresImporter),
                                           "MissingParameters", "Kunstwerken.shp");

            var           importTarget  = new StructureCollection <ClosingStructure>();
            ReferenceLine referenceLine = CreateReferenceLine();

            var importer = new ClosingStructuresImporter(importTarget, referenceLine, filePath,
                                                         messageProvider, strategy);

            importer.Import();

            // Call
            importer.DoPostImport();

            // Assert
            // Assertions performed in TearDown
        }
Пример #9
0
        public void Import_ParameterIdsWithVaryingCase_TrueAndImportTargetUpdated()
        {
            // Setup
            var    importTarget = new StructureCollection <ClosingStructure>();
            string filePath     = Path.Combine(commonIoTestDataPath, "CorrectShpRandomCaseHeaderCsv",
                                               "Kunstwerken.shp");
            var messageProvider = mocks.Stub <IImporterMessageProvider>();
            var updateStrategy  = mocks.StrictMock <IStructureUpdateStrategy <ClosingStructure> >();

            updateStrategy.Expect(u => u.UpdateStructuresWithImportedData(null, null)).IgnoreArguments().WhenCalled(i =>
            {
                Assert.AreEqual(filePath, i.Arguments[1]);
                Assert.AreEqual(4, ((IEnumerable <ClosingStructure>)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 ClosingStructuresImporter(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}'.", 5);
            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);
                ClosingStructuresFailureMechanism failureMechanism = assessmentSection.ClosingStructures;
                DataImportHelper.ImportFailureMechanismSections(assessmentSection, failureMechanism);

                CalculationGroup calculationsGroup = assessmentSection.ClosingStructures.CalculationsGroup;
                var view = new ClosingStructuresScenariosView(calculationsGroup, assessmentSection.ClosingStructures);

                form.Controls.Add(view);
                form.Show();

                var structuresImporter = new ClosingStructuresImporter(assessmentSection.ClosingStructures.ClosingStructures,
                                                                       assessmentSection.ReferenceLine, filePath, messageProvider,
                                                                       new ClosingStructureReplaceDataStrategy(failureMechanism));
                structuresImporter.Import();

                var listBox      = (ListBox) new ControlTester("listBox").TheObject;
                var dataGridView = (DataGridView) new ControlTester("dataGridView").TheObject;

                listBox.SelectedItem = failureMechanism.Sections.ElementAt(32);

                // Precondition
                DataGridViewRowCollection rows = dataGridView.Rows;
                CollectionAssert.IsEmpty(rows);

                // Call
                foreach (ClosingStructure structure in assessmentSection.ClosingStructures.ClosingStructures)
                {
                    calculationsGroup.Children.Add(new StructuresCalculationScenario <ClosingStructuresInput>
                    {
                        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 sluiting 6-3", cells[nameColumnIndex].FormattedValue);
                Assert.AreEqual("-", cells[failureProbabilityColumnIndex].FormattedValue);
            }

            mocks.VerifyAll();
        }