Index: Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs =================================================================== diff -u -rf28e5c177128224ea84257a3f29677f38b51f33f -r0e8c9f3912451d121375b590426837a3e6683dc5 --- Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision f28e5c177128224ea84257a3f29677f38b51f33f) +++ Ringtoets/Common/test/Ringtoets.Common.IO.Test/FileImporters/StructuresImporterTest.cs (.../StructuresImporterTest.cs) (revision 0e8c9f3912451d121375b590426837a3e6683dc5) @@ -595,6 +595,52 @@ } [Test] + public void Import_ValidImportFile_CallsUpdateStrategyWithExpectedArguments() + { + // Setup + var targetCollection = new StructureCollection(); + string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, + Path.Combine("Structures", "CorrectFiles", + "Kunstwerken.shp")); + + var createdStructures = new[] + { + new TestStructure() + }; + + var messageProvider = mocks.Stub(); + var updateStrategy = mocks.StrictMock>(); + updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .WhenCalled(i => + { + Assert.AreSame(targetCollection, i.Arguments[0]); + Assert.AreSame(createdStructures, i.Arguments[1]); + Assert.AreSame(filePath, i.Arguments[2]); + }); + mocks.ReplayAll(); + + ReferenceLine referenceLine = CreateReferenceLine(); + + var importer = new TestStructuresImporter(targetCollection, + referenceLine, + filePath, + updateStrategy, + messageProvider) + { + CreatedTestStructures = createdStructures + }; + + // Call + importer.Import(); + + // Assert + Assert.IsTrue(importer.CreateStructuresCalled); + + // Further assertions done in the TearDown + } + + [Test] public void Import_IllegalCsvFile_ReturnsFalse() { // Setup @@ -627,6 +673,9 @@ messageProvider.Expect(mp => mp.GetAddDataToModelProgressText()).Return(""); messageProvider.Expect(mp => mp.GetUpdateDataFailedLogMessageText("Kunstwerken")).Return("error {0}"); var updateStrategy = mocks.Stub>(); + updateStrategy.Expect(us => us.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .Throw(new UpdateDataException("Exception message")); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, @@ -638,10 +687,7 @@ referenceLine, filePath, updateStrategy, - messageProvider) - { - UpdateWithCreatedStructuresAction = () => { throw new UpdateDataException("Exception message"); } - }; + messageProvider); var importResult = true; @@ -659,31 +705,33 @@ { // Setup var messageProvider = mocks.Stub(); - var updateStrategy = mocks.Stub>(); + var observableA = mocks.StrictMock(); observableA.Expect(o => o.NotifyObservers()); var observableB = mocks.StrictMock(); observableB.Expect(o => o.NotifyObservers()); + + var updateStrategy = mocks.StrictMock>(); + updateStrategy.Expect(strat => strat.UpdateStructuresWithImportedData(null, null, null)) + .IgnoreArguments() + .Return(new[] + { + observableA, + observableB + }); mocks.ReplayAll(); string filePath = TestHelper.GetTestDataPath(TestDataPath.Ringtoets.Common.IO, Path.Combine("Structures", "CorrectFiles", "Kunstwerken.shp")); ReferenceLine referenceLine = CreateReferenceLine(); - IObservable[] observables = - { - observableA, - observableB - }; + var importer = new TestStructuresImporter(new StructureCollection(), referenceLine, filePath, updateStrategy, - messageProvider) - { - UpdateWithCreatedStructuresAction = () => observables - }; + messageProvider); importer.Import(); @@ -884,15 +932,17 @@ private class TestStructuresImporter : StructuresImporter { - public Func> UpdateWithCreatedStructuresAction; - public TestStructuresImporter(StructureCollection importTarget, ReferenceLine referenceLine, string filePath, IStructureUpdateStrategy structureUpdateStrategy, IImporterMessageProvider messageProvider) : base(importTarget, referenceLine, filePath, messageProvider, structureUpdateStrategy) {} + public IEnumerable CreatedTestStructures { private get; set; } = Enumerable.Empty(); + + public bool CreateStructuresCalled { get; private set; } + public new RoundedDouble GetStandardDeviation(StructuresParameterRow parameter, string structureName) { return base.GetStandardDeviation(parameter, structureName); @@ -903,10 +953,12 @@ return base.GetCoefficientOfVariation(parameter, structureName); } - protected override IEnumerable UpdateWithCreatedStructures(ICollection structureLocations, - Dictionary> groupedStructureParameterRows) + protected override IEnumerable CreateStructures(IEnumerable structureLocations, + IDictionary> groupedStructureParameterRows) { - return UpdateWithCreatedStructuresAction?.Invoke(); + CreateStructuresCalled = true; + + return CreatedTestStructures; } } }