Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -53,6 +53,7 @@ Properties\GlobalAssembly.cs + @@ -142,6 +143,7 @@ + @@ -172,6 +174,10 @@ {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + + {90DE728E-48EF-4665-AB38-3D88E41D9F4D} + Ringtoets.GrassCoverErosionInwards.Data + {70f8cc9c-5bc8-4fb2-b201-eae7fa8088c2} Ringtoets.HydraRing.Data Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -r56fcaa1987b9a7235553ff43a0a4f36b46efdb2e -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 56fcaa1987b9a7235553ff43a0a4f36b46efdb2e) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -51,6 +51,7 @@ }; CreatePipingFailureMechanism(section, entity, collector); + CreateGrassCoverErosionInwardsFailureMechanism(section, entity, collector); CreateHydraulicDatabase(section, entity, collector); CreateReferenceLine(section, entity); CreateFailureMechanismPlaceHolders(section, entity, collector); @@ -59,6 +60,11 @@ return entity; } + private static void CreateGrassCoverErosionInwardsFailureMechanism(AssessmentSection section, AssessmentSectionEntity entity, CreateConversionCollector collector) + { + entity.FailureMechanismEntities.Add(section.GrassCoverErosionInwards.Create(collector)); + } + private static void CreateFailureMechanismPlaceHolders(AssessmentSection section, AssessmentSectionEntity entity, CreateConversionCollector collector) { entity.FailureMechanismEntities.Add(section.MacrostabilityInwards.Create(FailureMechanismType.MacrostabilityInwards, collector)); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensions.cs (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -0,0 +1,60 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.Create; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.DbContext +{ + /// + /// Extension methods for related to creating a . + /// + public static class GrassCoverErosionInwardsFailureMechanismCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The failure mechanism to create a database entity for. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + public static FailureMechanismEntity Create(this GrassCoverErosionInwardsFailureMechanism mechanism, CreateConversionCollector collector) + { + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + var entity = new FailureMechanismEntity + { + FailureMechanismType = (short) FailureMechanismType.GrassRevetmentTopErosionAndInwards, + IsRelevant = Convert.ToByte(mechanism.IsRelevant) + }; + + mechanism.CreateFailureMechanismSections(collector, entity); + + collector.Create(entity, mechanism); + return entity; + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntity.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntity.cs (.../AssessmentSectionEntity.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/AssessmentSectionEntity.cs (.../AssessmentSectionEntity.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -56,6 +56,7 @@ }; ReadPipingFailureMechanism(assessmentSection, collector); + ReadGrassCoverErosionInwardsFailureMechanism(assessmentSection); ReadHydraulicDatabase(assessmentSection); ReadReferenceLine(assessmentSection); ReadFailureMechanismPlaceholders(assessmentSection); @@ -107,6 +108,23 @@ } } + private void ReadGrassCoverErosionInwardsFailureMechanism(AssessmentSection assessmentSection) + { + var grassCoverErosionInwardsFailureMechanismEntity = FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (int)FailureMechanismType.GrassRevetmentTopErosionAndInwards); + if (grassCoverErosionInwardsFailureMechanismEntity != null) + { + var failureMechanism = grassCoverErosionInwardsFailureMechanismEntity.ReadAsGrassCoverErosionInwardsFailureMechanism(); + + var grassCoverErosionInwards = assessmentSection.GrassCoverErosionInwards; + grassCoverErosionInwards.IsRelevant = failureMechanism.IsRelevant; + grassCoverErosionInwards.StorageId = failureMechanism.StorageId; + foreach (var failureMechanismSection in failureMechanism.Sections) + { + grassCoverErosionInwards.AddSection(failureMechanismSection); + } + } + } + private void ReadFailureMechanismPlaceholders(AssessmentSection assessmentSection) { ReadFailureMechanismPlaceholder(FailureMechanismType.MacrostabilityInwards, assessmentSection.MacrostabilityInwards); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntity.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntity.cs (.../FailureMechanismEntity.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/FailureMechanismEntity.cs (.../FailureMechanismEntity.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -22,6 +22,7 @@ using System; using Application.Ringtoets.Storage.Read; using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Piping.Data; @@ -63,6 +64,23 @@ } /// + /// Read the and use the information to construct a . + /// + /// A new . + public GrassCoverErosionInwardsFailureMechanism ReadAsGrassCoverErosionInwardsFailureMechanism() + { + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + StorageId = FailureMechanismEntityId, + IsRelevant = IsRelevant == 1 + }; + + ReadFailureMechanismSections(failureMechanism); + + return failureMechanism; + } + + /// /// Read the and use the information to construct a . /// /// A new . Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs =================================================================== diff -u -r56fcaa1987b9a7235553ff43a0a4f36b46efdb2e -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs (.../AssessmentSectionUpdateExtensions.cs) (revision 56fcaa1987b9a7235553ff43a0a4f36b46efdb2e) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/AssessmentSectionUpdateExtensions.cs (.../AssessmentSectionUpdateExtensions.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -63,6 +63,7 @@ entity.Composition = (short) section.Composition; UpdatePipingFailureMechanism(section, collector, context); + UpdateGrassCoverErosionInwardsFailureMechanism(section, collector, context); UpdateHydraulicDatabase(section, entity, collector, context); UpdateReferenceLine(section, entity, context); UpdateFailureMechanismPlaceHolders(section, collector, context); @@ -98,6 +99,11 @@ section.PipingFailureMechanism.Update(collector, context); } + private static void UpdateGrassCoverErosionInwardsFailureMechanism(AssessmentSection section, UpdateConversionCollector collector, IRingtoetsEntities context) + { + section.GrassCoverErosionInwards.Update(collector, context); + } + private static void UpdateReferenceLine(AssessmentSection section, AssessmentSectionEntity entity, IRingtoetsEntities context) { if (HasChanges(entity.ReferenceLinePointEntities, section.ReferenceLine)) Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensions.cs (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -0,0 +1,80 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.Properties; +using Application.Ringtoets.Storage.Update; +using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.Piping.Data; + +namespace Application.Ringtoets.Storage.DbContext +{ + /// + /// Extension methods for related to updating a . + /// + public static class GrassCoverErosionInwardsFailureMechanismUpdateExtensions + { + /// + /// Updates a in the database based on the information of the + /// . + /// + /// The mechanism to update the database entity for. + /// The object keeping track of update operations. + /// The context to obtain the existing entity from. + /// Thrown when either: + /// + /// is null + /// is null + /// + public static void Update(this GrassCoverErosionInwardsFailureMechanism mechanism, UpdateConversionCollector collector, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (collector == null) + { + throw new ArgumentNullException("collector"); + } + + var entity = GetSingleFailureMechanism(mechanism, context); + entity.IsRelevant = Convert.ToByte(mechanism.IsRelevant); + + mechanism.UpdateFailureMechanismSections(collector, entity, context); + + collector.Update(entity); + } + + private static FailureMechanismEntity GetSingleFailureMechanism(GrassCoverErosionInwardsFailureMechanism mechanism, IRingtoetsEntities context) + { + try + { + return context.FailureMechanismEntities.Single(fme => fme.FailureMechanismEntityId == mechanism.StorageId); + } + catch (InvalidOperationException exception) + { + throw new EntityNotFoundException(string.Format(Resources.Error_Entity_Not_Found_0_1, typeof(FailureMechanismEntity).Name, mechanism.StorageId), exception); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -52,7 +52,7 @@ /// Thrown when is null internal void Update(ProjectEntity entity) { - Update(entity, projects); + Update(entity, entity.ProjectEntityId, projects); } /// @@ -62,7 +62,7 @@ /// Thrown when is null internal void Update(AssessmentSectionEntity entity) { - Update(entity, assessmentSections); + Update(entity, entity.AssessmentSectionEntityId, assessmentSections); } /// @@ -72,7 +72,7 @@ /// Thrown when is null internal void Update(FailureMechanismEntity entity) { - Update(entity, failureMechanisms); + Update(entity, entity.FailureMechanismEntityId, failureMechanisms); } /// @@ -82,7 +82,7 @@ /// Thrown when is null public void Update(FailureMechanismSectionEntity entity) { - Update(entity, failureMechanismSections); + Update(entity, entity.FailureMechanismSectionEntityId, failureMechanismSections); } /// @@ -92,7 +92,7 @@ /// Thrown when is null internal void Update(HydraulicLocationEntity entity) { - Update(entity, hydraulicLocations); + Update(entity, entity.HydraulicLocationEntityId, hydraulicLocations); } /// @@ -102,7 +102,7 @@ /// Thrown when is null internal void Update(StochasticSoilModelEntity entity) { - Update(entity, stochasticSoilModels); + Update(entity, entity.StochasticSoilModelEntityId, stochasticSoilModels); } /// @@ -112,7 +112,7 @@ /// Thrown when is null internal void Update(StochasticSoilProfileEntity entity) { - Update(entity, stochasticSoilProfiles); + Update(entity, entity.StochasticSoilProfileEntityId, stochasticSoilProfiles); } /// @@ -122,7 +122,7 @@ /// Thrown when is null internal void Update(SoilProfileEntity entity) { - Update(entity, soilProfiles); + Update(entity, entity.SoilProfileEntityId, soilProfiles); } /// @@ -132,7 +132,7 @@ /// Thrown when is null internal void Update(SoilLayerEntity entity) { - Update(entity, soilLayers); + Update(entity, entity.SoilLayerEntityId, soilLayers); } /// @@ -205,12 +205,16 @@ soilLayerEntities.RemoveRange(soilLayerEntitiesToRemove); } - private void Update(T entity, HashSet collection) + private void Update(T entity, long entityId, HashSet collection) { if (entity == null) { throw new ArgumentNullException("entity"); } + if (entityId <= 0) + { + throw new ArgumentException("Entity cannot be new when added to the updated list.", "entity"); + } collection.Add(entity); } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -81,6 +81,7 @@ + @@ -113,6 +114,7 @@ + @@ -147,6 +149,10 @@ {d4200f43-3f72-4f42-af0a-8ced416a38ec} Ringtoets.Common.Data + + {90DE728E-48EF-4665-AB38-3D88E41D9F4D} + Ringtoets.GrassCoverErosionInwards.Data + {70f8cc9c-5bc8-4fb2-b201-eae7fa8088c2} Ringtoets.HydraRing.Data Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/AssessmentSectionCreateExtensionsTest.cs =================================================================== diff -u -r75a219c391144ca71a684f46e96e5d3f0c17f170 -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/AssessmentSectionCreateExtensionsTest.cs (.../AssessmentSectionCreateExtensionsTest.cs) (revision 75a219c391144ca71a684f46e96e5d3f0c17f170) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/AssessmentSectionCreateExtensionsTest.cs (.../AssessmentSectionCreateExtensionsTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -72,8 +72,9 @@ Assert.IsNotNull(entity); Assert.AreEqual((short)assessmentSectionComposition, entity.Composition); Assert.AreEqual(testName, entity.Name); - Assert.AreEqual(9, entity.FailureMechanismEntities.Count); + Assert.AreEqual(10, entity.FailureMechanismEntities.Count); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.Piping)); + Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.GrassRevetmentTopErosionAndInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.MacrostabilityInwards)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.StructureHeight)); Assert.IsNotNull(entity.FailureMechanismEntities.SingleOrDefault(fme => fme.FailureMechanismType == (short)FailureMechanismType.ReliabilityClosingOfStructure)); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismBaseCreateExtensions.cs =================================================================== diff -u -r45a98c616c6de35bc98ae800d94027d6f9247970 -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismBaseCreateExtensions.cs (.../FailureMechanismBaseCreateExtensions.cs) (revision 45a98c616c6de35bc98ae800d94027d6f9247970) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismBaseCreateExtensions.cs (.../FailureMechanismBaseCreateExtensions.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -31,7 +31,7 @@ namespace Application.Ringtoets.Storage.Test.Create { [TestFixture] - public class FailureMechanismBaseCreateExtensions + public class FailureMechanismBaseCreateExtensionsTest { [Test] public void CreateFailureMechanismSections_WithoutCollector_ArgumentNullException() @@ -89,17 +89,19 @@ // Assert Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); } - } - public class TestFailureMechanism : FailureMechanismBase { - public TestFailureMechanism() : base("", "") - {} - - public override IEnumerable Calculations + private class TestFailureMechanism : FailureMechanismBase { - get + public TestFailureMechanism() + : base("", "") + { } + + public override IEnumerable Calculations { - throw new NotImplementedException(); + get + { + throw new NotImplementedException(); + } } } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/GrassCoverErosionInwardsFailureMechanismCreateExtensionsTest.cs (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -0,0 +1,76 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.GrassCoverErosionInwards.Data; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismTest + { + [Test] + public void CreateFailureMechanismSections_WithoutCollector_ArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Create(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void CreateFailureMechanismSections_WithoutSections_EmptyFailureMechanismSectionEntities() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + var entity = failureMechanism.Create(new CreateConversionCollector()); + + // Assert + Assert.IsEmpty(entity.FailureMechanismSectionEntities); + } + + [Test] + public void CreateFailureMechanismSections_WithSections_FailureMechanismSectionEntitiesCreated() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + failureMechanism.AddSection(new FailureMechanismSection("", new [] { new Point2D(0,0) })); + + // Call + var entity = failureMechanism.Create(new CreateConversionCollector()); + + // Assert + Assert.AreEqual(1, entity.FailureMechanismSectionEntities.Count); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/AssessmentSectionEntityTest.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/AssessmentSectionEntityTest.cs (.../AssessmentSectionEntityTest.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/AssessmentSectionEntityTest.cs (.../AssessmentSectionEntityTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -171,7 +171,7 @@ } [Test] - public void Read_WithFailureMechanismWithFailureMechanismSectionsSet_ReturnsNewAssessmentSectionWithFailureMechanismSectionsInPipingFailureMechanism() + public void Read_WithPipingFailureMechanismWithFailureMechanismSectionsSet_ReturnsNewAssessmentSectionWithFailureMechanismSectionsInPipingFailureMechanism() { // Setup var entity = new AssessmentSectionEntity(); @@ -195,6 +195,30 @@ } [Test] + public void Read_WithGrassCoverErosionInwardsFailureMechanismWithFailureMechanismSectionsSet_ReturnsNewAssessmentSectionWithFailureMechanismSectionsInGrassCoverErosionInwardsFailureMechanism() + { + // Setup + var entity = new AssessmentSectionEntity(); + var entityId = new Random(21).Next(1, 502); + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = entityId, + FailureMechanismType = (int) FailureMechanismType.GrassRevetmentTopErosionAndInwards, + FailureMechanismSectionEntities = CreateFailureMechanismSectionEntities() + }; + entity.FailureMechanismEntities.Add(failureMechanismEntity); + + var collector = new ReadConversionCollector(); + + // Call + var section = entity.Read(collector); + + // Assert + Assert.AreEqual(2, section.GrassCoverErosionInwards.Sections.Count()); + } + + [Test] [TestCase(true)] [TestCase(false)] public void Read_WithFailureMechanismPlaceholdersSet_ReturnsNewAssessmentSectionWithFailureMechanismsSet(bool isRelevant) Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityTest.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityTest.cs (.../FailureMechanismEntityTest.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/FailureMechanismEntityTest.cs (.../FailureMechanismEntityTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -69,7 +69,7 @@ } [Test] - public void ReadAsPipingFailureMechanism_WithStochasticSoilModelsSet_ReturnsNewPipingFailureMechanismWithStochasticSoilModels() + public void ReadAsPipingFailureMechanism_WithStochasticSoilModelsSet_ReturnsNewPipingFailureMechanismWithStochasticSoilModelsSet() { // Setup var entity = new FailureMechanismEntity @@ -90,7 +90,7 @@ } [Test] - public void ReadAsPipingFailureMechanismPlaceholder_WithSectionsSet_ReturnsNewFailureMechanismPlaceholderWithFailureMechanismSections() + public void ReadAsPipingFailureMechanism_WithSectionsSet_ReturnsNewPipingFailureMechanismWithFailureMechanismSectionsSet() { // Setup var entityId = new Random(21).Next(1, 502); @@ -121,6 +121,59 @@ [Test] [TestCase(true)] [TestCase(false)] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithCollector_ReturnsNewGrassCoverErosionInwardsFailureMechanismWithPropertiesSet(bool isRelevant) + { + // Setup + var entityId = new Random(21).Next(1, 502); + var entity = new FailureMechanismEntity + { + FailureMechanismEntityId = entityId, + IsRelevant = Convert.ToByte(isRelevant), + }; + var collector = new ReadConversionCollector(); + + // Call + var failureMechanism = entity.ReadAsGrassCoverErosionInwardsFailureMechanism(); + + // Assert + Assert.IsNotNull(failureMechanism); + Assert.AreEqual(entityId, failureMechanism.StorageId); + Assert.AreEqual(isRelevant, failureMechanism.IsRelevant); + Assert.IsEmpty(failureMechanism.Sections); + } + + [Test] + public void ReadAsGrassCoverErosionInwardsFailureMechanism_WithSectionsSet_ReturnsNewGrassCoverErosionInwardsFailureMechanismWithFailureMechanismSectionsAdded() + { + // Setup + var entityId = new Random(21).Next(1, 502); + var entity = new FailureMechanismEntity + { + FailureMechanismEntityId = entityId, + FailureMechanismSectionEntities = + { + new FailureMechanismSectionEntity + { + Name = "section", + FailureMechanismSectionPointEntities = + { + new FailureMechanismSectionPointEntity() + } + } + } + }; + var collector = new ReadConversionCollector(); + + // Call + var failureMechanism = entity.ReadAsGrassCoverErosionInwardsFailureMechanism(); + + // Assert + Assert.AreEqual(1, failureMechanism.Sections.Count()); + } + + [Test] + [TestCase(true)] + [TestCase(false)] public void ReadAsFailureMechanismPlaceholder_WithoutSectionsSet_ReturnsNewFailureMechanismPlaceholder(bool isRelevant) { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs =================================================================== diff -u -r75a219c391144ca71a684f46e96e5d3f0c17f170 -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs (.../AssessmentSectionUpdateExtensionsTest.cs) (revision 75a219c391144ca71a684f46e96e5d3f0c17f170) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs (.../AssessmentSectionUpdateExtensionsTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Data.Entity; using System.Linq; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.Exceptions; @@ -134,11 +135,8 @@ var newName = "newName"; var composition = AssessmentSectionComposition.Dune; - var section = new AssessmentSection(composition) - { - StorageId = 1, - Name = newName - }; + var section = InitialzeCreatedDikeAssessmentSection(AssessmentSectionComposition.Dune); + section.Name = newName; var entity = new AssessmentSectionEntity { @@ -147,7 +145,7 @@ Composition = (short) AssessmentSectionComposition.Dike }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for failure mechanisms + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -177,18 +175,15 @@ { new Point2D(1, 2) }); - var section = new AssessmentSection(AssessmentSectionComposition.Dike) - { - StorageId = 1, - ReferenceLine = referenceLine - }; + var section = InitialzeCreatedDikeAssessmentSection(); + section.ReferenceLine = referenceLine; var entity = new AssessmentSectionEntity { AssessmentSectionEntityId = 1 }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for failure mechanisms + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -213,11 +208,8 @@ { new Point2D(1, 2) }); - var section = new AssessmentSection(AssessmentSectionComposition.Dike) - { - StorageId = 1, - ReferenceLine = referenceLine - }; + var section = InitialzeCreatedDikeAssessmentSection(); + section.ReferenceLine = referenceLine; var referenceLinePointEntity = new ReferenceLinePointEntity { @@ -232,8 +224,8 @@ } }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for failure mechanisms ringtoetsEntities.ReferenceLinePointEntities.Add(referenceLinePointEntity); + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -256,17 +248,14 @@ var newVersion = "new version"; var filePath = "new path"; - var section = new AssessmentSection(AssessmentSectionComposition.Dike) + var section = InitialzeCreatedDikeAssessmentSection(); + section.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - StorageId = 1, - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + FilePath = filePath, + Version = newVersion, + Locations = { - FilePath = filePath, - Version = newVersion, - Locations = - { - new HydraulicBoundaryLocation(-1, string.Empty, 0, 0) - } + new HydraulicBoundaryLocation(-1, string.Empty, 0, 0) } }; @@ -275,7 +264,7 @@ AssessmentSectionEntityId = 1 }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for failure mechanisms + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -303,17 +292,14 @@ { StorageId = 1 }; - var section = new AssessmentSection(AssessmentSectionComposition.Dike) + var section = InitialzeCreatedDikeAssessmentSection(); + section.HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase { - StorageId = 1, - HydraulicBoundaryDatabase = new HydraulicBoundaryDatabase + FilePath = filePath, + Version = newVersion, + Locations = { - FilePath = filePath, - Version = newVersion, - Locations = - { - hydraulicBoundaryLocation - } + hydraulicBoundaryLocation } }; @@ -332,7 +318,7 @@ } }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for failure mechanisms + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); ringtoetsEntities.HydraulicLocationEntities.Add(hydraulicLocationEntity); // Call @@ -358,17 +344,53 @@ mocks.ReplayAll(); - var section = new AssessmentSection(AssessmentSectionComposition.Dike) + var section = InitialzeCreatedDikeAssessmentSection(); + section.PipingFailureMechanism.StorageId = 1; + section.PipingFailureMechanism.Contribution = 0.5; + section.PipingFailureMechanism.IsRelevant = true; + + var failureMechanismEntity = new FailureMechanismEntity { - StorageId = 1, - PipingFailureMechanism = + FailureMechanismEntityId = 1, + IsRelevant = Convert.ToByte(false) + }; + var entity = new AssessmentSectionEntity + { + AssessmentSectionEntityId = 1, + FailureMechanismEntities = { - StorageId = 1, - Contribution = 0.5, - IsRelevant = true + failureMechanismEntity } }; + ringtoetsEntities.AssessmentSectionEntities.Add(entity); + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); + // Call + section.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + CollectionAssert.AreEqual(new[] + { + failureMechanismEntity + }, entity.FailureMechanismEntities); + + mocks.VerifyAll(); + } + + [Test] + public void Update_AssessmentSectionWithUpdatedGrassCoverErosionInwardsFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var section = InitialzeCreatedDikeAssessmentSection(); + section.GrassCoverErosionInwards.Contribution = 0.5; + section.GrassCoverErosionInwards.IsRelevant = true; + var failureMechanismEntity = new FailureMechanismEntity { FailureMechanismEntityId = 1, @@ -383,8 +405,8 @@ } }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for all other failure mechanisms ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -407,58 +429,32 @@ mocks.ReplayAll(); - var section = new AssessmentSection(AssessmentSectionComposition.Dike) - { - StorageId = 1, - MacrostabilityInwards = - { - StorageId = 1, - Contribution = 0.5, - IsRelevant = true - }, - Overtopping = - { - StorageId = 2, - Contribution = 0.5, - IsRelevant = true - }, - Closing = - { - StorageId = 3, - Contribution = 0.5, - IsRelevant = true - }, - FailingOfConstruction = - { - StorageId = 4, - Contribution = 0.5, - IsRelevant = true - }, - StoneRevetment = - { - StorageId = 5, - Contribution = 0.5, - IsRelevant = true - }, - AsphaltRevetment = - { - StorageId = 6, - Contribution = 0.5, - IsRelevant = true - }, - GrassRevetment = - { - StorageId = 7, - Contribution = 0.5, - IsRelevant = true - }, - DuneErosion = - { - StorageId = 8, - Contribution = 0.5, - IsRelevant = true - } - }; + var section = InitialzeCreatedDikeAssessmentSection(); + section.StorageId = 1; + section.MacrostabilityInwards.StorageId = 1; + section.MacrostabilityInwards.Contribution = 0.5; + section.MacrostabilityInwards.IsRelevant = true; + section.Overtopping.StorageId = 2; + section.Overtopping.Contribution = 0.5; + section.Overtopping.IsRelevant = true; + section.Closing.StorageId = 3; + section.Closing.Contribution = 0.5; + section.Closing.IsRelevant = true; + section.FailingOfConstruction.StorageId = 4; + section.FailingOfConstruction.Contribution = 0.5; + section.FailingOfConstruction.IsRelevant = true; + section.StoneRevetment.StorageId = 5; + section.StoneRevetment.Contribution = 0.5; + section.StoneRevetment.IsRelevant = true; + section.AsphaltRevetment.StorageId = 6; + section.AsphaltRevetment.Contribution = 0.5; + section.AsphaltRevetment.IsRelevant = true; + section.GrassRevetment.StorageId = 7; + section.GrassRevetment.Contribution = 0.5; + section.GrassRevetment.IsRelevant = true; + section.DuneErosion.StorageId = 8; + section.DuneErosion.Contribution = 0.5; + section.DuneErosion.IsRelevant = true; var macrostabilityInwardsEntity = new FailureMechanismEntity { @@ -516,7 +512,6 @@ } }; ringtoetsEntities.AssessmentSectionEntities.Add(entity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); // Dummy for piping ringtoetsEntities.FailureMechanismEntities.Add(macrostabilityInwardsEntity); ringtoetsEntities.FailureMechanismEntities.Add(overtoppingEntity); ringtoetsEntities.FailureMechanismEntities.Add(closingEntity); @@ -525,6 +520,7 @@ ringtoetsEntities.FailureMechanismEntities.Add(asphaltRevetmentEntity); ringtoetsEntities.FailureMechanismEntities.Add(grassRevetmentEntity); ringtoetsEntities.FailureMechanismEntities.Add(duneErosionEntity); + FillWithFailureMechanismEntities(ringtoetsEntities.FailureMechanismEntities); // Call section.Update(new UpdateConversionCollector(), ringtoetsEntities); @@ -544,5 +540,73 @@ mocks.VerifyAll(); } + + public AssessmentSection InitialzeCreatedDikeAssessmentSection(AssessmentSectionComposition composition = AssessmentSectionComposition.Dike) + { + return new AssessmentSection(composition) + { + StorageId = 1, + PipingFailureMechanism = + { + StorageId = 1 + }, + GrassCoverErosionInwards = + { + StorageId = 2 + }, + MacrostabilityInwards = + { + StorageId = 3 + }, + Overtopping = + { + StorageId = 4 + }, + Closing = + { + StorageId = 5 + }, + FailingOfConstruction = + { + StorageId = 6 + }, + StoneRevetment = + { + StorageId = 7 + }, + AsphaltRevetment = + { + StorageId = 8 + }, + GrassRevetment = + { + StorageId = 9 + }, + DuneErosion = + { + StorageId = 10 + } + }; + } + + private void FillWithFailureMechanismEntities(DbSet failureMechanismEntities) + { + var failureMechanismEntity = failureMechanismEntities.LastOrDefault(); + long startId = 0; + if (failureMechanismEntity != null) + { + startId = failureMechanismEntity.FailureMechanismEntityId; + } + + var count = failureMechanismEntities.Count(); + for (var i = 1; i <= 10 - count; i++) + { + failureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = startId + i + }); + } + } } + } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/GrassCoverErosionInwardsFailureMechanismUpdateExtensionsTest.cs (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -0,0 +1,233 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using System.Linq; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.TestUtil; +using Application.Ringtoets.Storage.Update; +using Core.Common.Base.Geometry; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.GrassCoverErosionInwards.Data; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class GrassCoverErosionInwardsFailureMechanismUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("context", paramName); + } + + [Test] + public void Update_WithoutCollector_ArgumentNullException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(null, ringtoetsEntities); + } + }; + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Update_ContextWithNoPipingFailureMechanism_EntityNotFoundException() + { + // Setup + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoPipingFailureMechanismWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + StorageId = storageId + }; + + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 2 + }); + + // Call + TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithPipingFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + StorageId = 1, + IsRelevant = true + }; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + IsRelevant = Convert.ToByte(false) + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + // Call + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), failureMechanismEntity.IsRelevant); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithNewFailureMechanismSections_FailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + StorageId = 1 + }; + failureMechanism.AddSection(new FailureMechanismSection("", new[] { new Point2D(0, 0) })); + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + // Call + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithUpdatedFailureMechanismSections_NoNewFailureMechanismSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new GrassCoverErosionInwardsFailureMechanism + { + StorageId = 1 + }; + var testName = "testName"; + failureMechanism.AddSection(new FailureMechanismSection(testName, new[] { new Point2D(0, 0) }) + { + StorageId = 1 + }); + + var failureMechanismSectionEntity = new FailureMechanismSectionEntity + { + FailureMechanismSectionEntityId = 1, + }; + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + FailureMechanismSectionEntities = + { + failureMechanismSectionEntity + } + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + ringtoetsEntities.FailureMechanismSectionEntities.Add(failureMechanismSectionEntity); + + // Call + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + Assert.AreEqual(1, failureMechanismEntity.FailureMechanismSectionEntities.Count); + Assert.AreEqual(testName, failureMechanismEntity.FailureMechanismSectionEntities.ElementAt(0).Name); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs =================================================================== diff -u -r75a219c391144ca71a684f46e96e5d3f0c17f170 -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs (.../ProjectUpdateExtensionsTest.cs) (revision 75a219c391144ca71a684f46e96e5d3f0c17f170) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs (.../ProjectUpdateExtensionsTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -243,7 +243,47 @@ { new AssessmentSection(AssessmentSectionComposition.Dike) { - StorageId = 1 + StorageId = 1, + PipingFailureMechanism = + { + StorageId = 1 + }, + GrassCoverErosionInwards = + { + StorageId = 1 + }, + MacrostabilityInwards = + { + StorageId = 1 + }, + Overtopping = + { + StorageId = 1 + }, + Closing = + { + StorageId = 1 + }, + FailingOfConstruction = + { + StorageId = 1 + }, + StoneRevetment = + { + StorageId = 1 + }, + AsphaltRevetment = + { + StorageId = 1 + }, + GrassRevetment = + { + StorageId = 1 + }, + DuneErosion = + { + StorageId = 1 + } } } }; @@ -263,7 +303,10 @@ ringtoetsEntities.ProjectEntities.Add(projectEntity); ringtoetsEntities.AssessmentSectionEntities.Add(assessmentSectionEntity); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 1 + }); // Call project.Update(new UpdateConversionCollector(), ringtoetsEntities); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs =================================================================== diff -u -r4bb55feac151da4010e81849de3103327f7f40ae -r070f77d4fa62658c40449c64eac12a85dc51ea41 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs (.../UpdateConversionCollectorTest.cs) (revision 4bb55feac151da4010e81849de3103327f7f40ae) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs (.../UpdateConversionCollectorTest.cs) (revision 070f77d4fa62658c40449c64eac12a85dc51ea41) @@ -19,6 +19,7 @@ // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. +using System; using System.Linq; using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; @@ -42,15 +43,136 @@ Assert.IsInstanceOf(collector); } + #region Update method + [Test] + public void Update_WithNewProject_ThrowArgumentException() + { + // Setup + var entity = new ProjectEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewAssessmentSection_ThrowArgumentException() + { + // Setup + var entity = new AssessmentSectionEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewFailureMechanismSection_ThrowArgumentException() + { + // Setup + var entity = new FailureMechanismSectionEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewHydraulicLocation_ThrowArgumentException() + { + // Setup + var entity = new HydraulicLocationEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewStochasticSoilModel_ThrowArgumentException() + { + // Setup + var entity = new StochasticSoilModelEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewStochasticSoilProfile_ThrowArgumentException() + { + // Setup + var entity = new StochasticSoilProfileEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewSoilProfile_ThrowArgumentException() + { + // Setup + var entity = new SoilProfileEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_WithNewSoilLayer_ThrowArgumentException() + { + // Setup + var entity = new SoilLayerEntity(); + var collector = new UpdateConversionCollector(); + + // Call + TestDelegate test = () => collector.Update(entity); + + // Assert + Assert.Throws(test); + } + + #endregion + + #region RemoveUntouched method + + [Test] public void RemoveUntouched_ProjectEntityInUpdatedList_ProjectEntityNotRemoved() { // Setup MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var projectEntity = new ProjectEntity(); + var projectEntity = new ProjectEntity + { + ProjectEntityId = 1 + }; ringtoetsEntities.ProjectEntities.Add(projectEntity); var collector = new UpdateConversionCollector(); @@ -70,7 +192,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.ProjectEntities.Add(new ProjectEntity()); + ringtoetsEntities.ProjectEntities.Add(new ProjectEntity + { + ProjectEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -89,7 +214,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var assessmentSectionEntity = new AssessmentSectionEntity(); + var assessmentSectionEntity = new AssessmentSectionEntity + { + AssessmentSectionEntityId = 1 + }; ringtoetsEntities.AssessmentSectionEntities.Add(assessmentSectionEntity); var collector = new UpdateConversionCollector(); @@ -109,7 +237,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.AssessmentSectionEntities.Add(new AssessmentSectionEntity()); + ringtoetsEntities.AssessmentSectionEntities.Add(new AssessmentSectionEntity + { + AssessmentSectionEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -128,7 +259,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var failureMechanismEntity = new FailureMechanismEntity(); + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1 + }; ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); var collector = new UpdateConversionCollector(); @@ -148,7 +282,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -167,7 +304,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var failureMechanismEntity = new FailureMechanismSectionEntity(); + var failureMechanismEntity = new FailureMechanismSectionEntity + { + FailureMechanismSectionEntityId = 1 + }; ringtoetsEntities.FailureMechanismSectionEntities.Add(failureMechanismEntity); var collector = new UpdateConversionCollector(); @@ -187,7 +327,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.FailureMechanismSectionEntities.Add(new FailureMechanismSectionEntity()); + ringtoetsEntities.FailureMechanismSectionEntities.Add(new FailureMechanismSectionEntity + { + FailureMechanismSectionEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -206,7 +349,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var hydraulicLocationEntity = new HydraulicLocationEntity(); + var hydraulicLocationEntity = new HydraulicLocationEntity + { + HydraulicLocationEntityId = 1 + }; ringtoetsEntities.HydraulicLocationEntities.Add(hydraulicLocationEntity); var collector = new UpdateConversionCollector(); @@ -226,7 +372,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.HydraulicLocationEntities.Add(new HydraulicLocationEntity()); + ringtoetsEntities.HydraulicLocationEntities.Add(new HydraulicLocationEntity + { + HydraulicLocationEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -245,7 +394,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + var stochasticSoilModelEntity = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = 1 + }; ringtoetsEntities.StochasticSoilModelEntities.Add(stochasticSoilModelEntity); var collector = new UpdateConversionCollector(); @@ -265,7 +417,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.StochasticSoilModelEntities.Add(new StochasticSoilModelEntity()); + ringtoetsEntities.StochasticSoilModelEntities.Add(new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -284,7 +439,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var stochasticSoilProfileEntity = new StochasticSoilProfileEntity(); + var stochasticSoilProfileEntity = new StochasticSoilProfileEntity + { + StochasticSoilProfileEntityId = 1 + }; ringtoetsEntities.StochasticSoilProfileEntities.Add(stochasticSoilProfileEntity); var collector = new UpdateConversionCollector(); @@ -304,7 +462,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.StochasticSoilProfileEntities.Add(new StochasticSoilProfileEntity()); + ringtoetsEntities.StochasticSoilProfileEntities.Add(new StochasticSoilProfileEntity + { + StochasticSoilProfileEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -323,7 +484,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var soilProfileEntity = new SoilProfileEntity(); + var soilProfileEntity = new SoilProfileEntity + { + SoilProfileEntityId = 1 + }; ringtoetsEntities.SoilProfileEntities.Add(soilProfileEntity); var collector = new UpdateConversionCollector(); @@ -343,7 +507,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.SoilProfileEntities.Add(new SoilProfileEntity()); + ringtoetsEntities.SoilProfileEntities.Add(new SoilProfileEntity + { + SoilProfileEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -362,7 +529,10 @@ var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - var soilLayerEntity = new SoilLayerEntity(); + var soilLayerEntity = new SoilLayerEntity + { + SoilLayerEntityId = 1 + }; ringtoetsEntities.SoilLayerEntities.Add(soilLayerEntity); var collector = new UpdateConversionCollector(); @@ -382,7 +552,10 @@ MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); - ringtoetsEntities.SoilLayerEntities.Add(new SoilLayerEntity()); + ringtoetsEntities.SoilLayerEntities.Add(new SoilLayerEntity + { + SoilLayerEntityId = 1 + }); var collector = new UpdateConversionCollector(); @@ -392,5 +565,7 @@ // Assert Assert.AreEqual(0, ringtoetsEntities.SoilLayerEntities.Count()); } + + #endregion } } \ No newline at end of file