Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs (.../PipingSoilProfileUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs (.../PipingSoilProfileUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -35,27 +35,78 @@ var soilProfile = new TestPipingSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("collector", paramName); } [Test] - public void Update_ContextWithNoStochasticSoilModel_EntityNotFoundException() + public void Update_ContextWithNoPipingSoilProfile_EntityNotFoundException() { // Setup var soilProfile = new TestPipingSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'SoilProfileEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] + public void Update_ContextWithNoPipingSoilProfileWithId_PropertiesUpdatedAndLayerAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + IEnumerable newLayers = new[] + { + new PipingSoilLayer(5.0) + }; + var storageId = 1; + var soilProfile = new PipingSoilProfile("new name", 0.5, newLayers, SoilProfileType.SoilProfile1D, -1) + { + StorageId = storageId + }; + + ringtoetsEntities.SoilProfileEntities.Add(new SoilProfileEntity + { + SoilProfileEntityId = 2, + Name = string.Empty, + Bottom = 0 + }); + + // Call + TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'SoilProfileEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] public void Update_NewSoilLayer_PropertiesUpdatedAndLayerAdded() { // Setup