Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -rbb92ba4d7297c7bf0d1c81ff3d9d6bcab640d55f -r0868d78756c7992a83a096f3d3759046c2dbb217 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision bb92ba4d7297c7bf0d1c81ff3d9d6bcab640d55f) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 0868d78756c7992a83a096f3d3759046c2dbb217) @@ -35,6 +35,7 @@ using Ringtoets.Common.Data.Calculation; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.GrassCoverErosionInwards.Data; +using Ringtoets.HeightStructures.Data; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; using Ringtoets.Integration.Data.StandAlone; @@ -935,6 +936,34 @@ } [Test] + public void Register_WithNullHeightStructuresFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new HeightStructuresSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullHeightStructuresSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] public void Register_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() { // Setup @@ -1424,6 +1453,27 @@ } [Test] + public void TransferIds_WithHeightStructuresSectionResultEntityAddedWithHeightStructuresFailureMechanismSectionResult_EqualHeightStructuresSectionEntityIdAndHeightStructuresFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new HeightStructuresSectionResultEntity() + { + HeightStructuresSectionResultEntityId = storageId + }; + var model = new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] public void TransferIds_WithHydraulicLocationEntityAdded_EqualHydraulicLocationEntityIdAndHydraulicBoundaryLocationStorageId() { // Setup @@ -1885,6 +1935,42 @@ } [Test] + public void RemoveUntouched_HeightStructuresSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new HeightStructuresSectionResultEntity + { + HeightStructuresSectionResultEntityId = 1 + }; + var persistentEntity = new HeightStructuresSectionResultEntity + { + HeightStructuresSectionResultEntityId = 2 + }; + dbContext.HeightStructuresSectionResultEntities.Add(orphanedEntity); + dbContext.HeightStructuresSectionResultEntities.Add(persistentEntity); + + var section = new HeightStructuresFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.HeightStructuresSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.HeightStructuresSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.HeightStructuresSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] public void RemoveUntouched_HydraulicLocationEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() { // Setup