Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -rb0b8bffcbb871a42e6c8b282fe20858d6a738dbc -r25e0f6d008a17ea054a3658d82746b3a2e94f3c5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision b0b8bffcbb871a42e6c8b282fe20858d6a738dbc) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 25e0f6d008a17ea054a3658d82746b3a2e94f3c5) @@ -20,6 +20,7 @@ // All rights reserved. using System; +using System.Linq; using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; using Application.Ringtoets.Storage.TestUtil; @@ -37,6 +38,8 @@ using Ringtoets.GrassCoverErosionInwards.Data; using Ringtoets.HeightStructures.Data; using Ringtoets.HeightStructures.Data.TestUtil; +using Ringtoets.MacroStabilityInwards.Primitives; +using Ringtoets.MacroStabilityInwards.Primitives.TestUtil; using Ringtoets.Piping.Data.SoilProfile; using Ringtoets.Piping.Primitives; using Ringtoets.Piping.Primitives.TestUtil; @@ -67,66 +70,274 @@ }); } - #region Contains methods - - [Test] - public void Contains_WithoutPipingSoilProfile_ThrowsArgumentNullException() + [TestFixture] + private class PipingSoilProfileTest : RegistryTest { - // Setup - var registry = new PersistenceRegistry(); + protected override PipingSoilProfile CreateDataModel() + { + return PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + } - // Call - TestDelegate test = () => registry.Contains((PipingSoilProfile) null); + protected override PipingSoilProfileEntity Get(PersistenceRegistry registry, + PipingSoilProfile model) + { + return registry.Get(model); + } - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("model", paramName); + protected override bool Contains(PersistenceRegistry registry, PipingSoilProfile model) + { + return registry.Contains(model); + } + + protected override void Register(PersistenceRegistry registry, PipingSoilProfileEntity entity, + PipingSoilProfile model) + { + registry.Register(entity, model); + } } - [Test] - public void Contains_PipingSoilProfileAdded_ReturnsTrue() + [TestFixture] + private class MacroStabilityInwardsSoilProfile1DTest : RegistryTest { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); - registry.Register(new PipingSoilProfileEntity(), profile); + protected override MacroStabilityInwardsSoilProfile1D CreateDataModel() + { + return new TestMacroStabilityInwardsSoilProfile1D(); + } - // Call - bool result = registry.Contains(profile); + protected override MacroStabilityInwardsSoilProfile1DEntity Get(PersistenceRegistry registry, + MacroStabilityInwardsSoilProfile1D model) + { + return registry.Get(model); + } - // Assert - Assert.IsTrue(result); + protected override bool Contains(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile1D model) + { + return registry.Contains(model); + } + + protected override void Register(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile1DEntity entity, + MacroStabilityInwardsSoilProfile1D model) + { + registry.Register(entity, model); + } } - [Test] - public void Contains_NoPipingSoilProfileAdded_ReturnsFalse() + [TestFixture] + private class MacroStabilityInwardsSoilProfile2DTest : RegistryTest { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); + protected override MacroStabilityInwardsSoilProfile2D CreateDataModel() + { + return new MacroStabilityInwardsSoilProfile2D("", new[] + { + new MacroStabilityInwardsSoilLayer2D(new Ring(new[] + { + new Point2D(0, 0), + new Point2D(1, 1) + }), new Ring[0]) + }, Enumerable.Empty()); + } - // Call - bool result = registry.Contains(profile); + protected override MacroStabilityInwardsSoilProfile2DEntity Get(PersistenceRegistry registry, + MacroStabilityInwardsSoilProfile2D model) + { + return registry.Get(model); + } - // Assert - Assert.IsFalse(result); + protected override bool Contains(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile2D model) + { + return registry.Contains(model); + } + + protected override void Register(PersistenceRegistry registry, MacroStabilityInwardsSoilProfile2DEntity entity, + MacroStabilityInwardsSoilProfile2D model) + { + registry.Register(entity, model); + } } - [Test] - public void Contains_OtherPipingSoilProfileAdded_ReturnsFalse() + [TestFixture] + private abstract class RegistryTest where TDataModel : class + where TEntity : class, new() { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); - registry.Register(new PipingSoilProfileEntity(), PipingSoilProfileTestFactory.CreatePipingSoilProfile()); + [Test] + public void Register_WithNullEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); - // Call - bool result = registry.Contains(profile); + // Call + TestDelegate test = () => Register(registry, null, CreateDataModel()); - // Assert - Assert.IsFalse(result); + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullDataModel_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => Register(registry, new TEntity(), null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_DataModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => Contains(registry, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_DataModelAdded_ReturnsTrue() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + Register(registry, new TEntity(), dataModel); + + // Call + bool result = Contains(registry, dataModel); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoDataModelAdded_ReturnsFalse() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + + // Call + bool result = Contains(registry, dataModel); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_DataModelNull_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => Get(registry, null); + + // Assert + string paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Get_DataModelAdded_ReturnsEntity() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + var entity = new TEntity(); + + Register(registry, entity, dataModel); + + // Call + TEntity result = Get(registry, dataModel); + + // Assert + Assert.AreSame(entity, result); + } + + [Test] + public void Get_NoDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var registry = new PersistenceRegistry(); + TDataModel dataModel = CreateDataModel(); + + // Call + TestDelegate test = () => Get(registry, dataModel); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherDataModelAdded_ThrowsInvalidOperationException() + { + // Setup + var registry = new PersistenceRegistry(); + Register(registry, new TEntity(), CreateDataModel()); + + // Call + TestDelegate test = () => Get(registry, CreateDataModel()); + + // Assert + Assert.Throws(test); + } + + /// + /// Creates a new instance of . + /// + /// + protected abstract TDataModel CreateDataModel(); + + /// + /// Obtains the which was registered for the given . + /// + /// The registry to use. + /// The for which a create operation has + /// been registered. + /// The constructed . + /// Thrown when is + /// null. + /// Thrown when no create operation has + /// been registered for . + protected abstract TEntity Get(PersistenceRegistry registry, TDataModel model); + + /// + /// Checks whether a create operations has been registered for the given . + /// + /// The registry to use. + /// The to check for. + /// true if the was registered before, false + /// otherwise. + /// Thrown when is + /// null. + protected abstract bool Contains(PersistenceRegistry registry, TDataModel model); + + /// + /// Registers a create operation for and the + /// that was constructed with the information. + /// + /// The registry to use. + /// The + /// to be registered. + /// The to be + /// registered. + /// Thrown any of the input parameters is + /// null. + protected abstract void Register(PersistenceRegistry registry, TEntity entity, TDataModel model); } + #region Contains methods + [Test] public void Contains_WithoutPipingSurfaceLine_ThrowsArgumentNullException() { @@ -1013,65 +1224,6 @@ #region Get methods [Test] - public void Get_WithoutPipingSoilProfile_ThrowsArgumentNullException() - { - // Setup - var registry = new PersistenceRegistry(); - - // Call - TestDelegate test = () => registry.Get((PipingSoilProfile) null); - - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("model", paramName); - } - - [Test] - public void Get_PipingSoilProfileAdded_ReturnsEntity() - { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); - var entity = new PipingSoilProfileEntity(); - registry.Register(entity, profile); - - // Call - PipingSoilProfileEntity result = registry.Get(profile); - - // Assert - Assert.AreSame(entity, result); - } - - [Test] - public void Get_NoPipingSoilProfileAdded_ThrowsInvalidOperationException() - { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); - - // Call - TestDelegate test = () => registry.Get(profile); - - // Assert - Assert.Throws(test); - } - - [Test] - public void Get_OtherPipingSoilProfileAdded_ThrowsInvalidOperationException() - { - // Setup - var registry = new PersistenceRegistry(); - PipingSoilProfile profile = PipingSoilProfileTestFactory.CreatePipingSoilProfile(); - registry.Register(new PipingSoilProfileEntity(), PipingSoilProfileTestFactory.CreatePipingSoilProfile()); - - // Call - TestDelegate test = () => registry.Get(profile); - - // Assert - Assert.Throws(test); - } - - [Test] public void Get_WithoutPipingSurfaceLine_ThrowsArgumentNullException() { // Setup @@ -2158,37 +2310,6 @@ } [Test] - public void Register_WithNullPipingSoilProfileEntity_ThrowsArgumentNullException() - { - // Setup - var registry = new PersistenceRegistry(); - - // Call - TestDelegate test = () => registry.Register(null, new PipingSoilProfile("name", 0, new[] - { - new PipingSoilLayer(1) - }, SoilProfileType.SoilProfile1D)); - - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("entity", paramName); - } - - [Test] - public void Register_WithNullPipingSoilProfile_ThrowsArgumentNullException() - { - // Setup - var registry = new PersistenceRegistry(); - - // Call - TestDelegate test = () => registry.Register(new PipingSoilProfileEntity(), null); - - // Assert - string paramName = Assert.Throws(test).ParamName; - Assert.AreEqual("model", paramName); - } - - [Test] public void Register_WithNullHeightStructureEntity_ThrowsArgumentNullException() { // Setup