Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -r0e4717786f2f1a865e48da9fde2089a789bfe02c -rc482712c0ff06d5654836fc8d9af535641d63ffb --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 0e4717786f2f1a865e48da9fde2089a789bfe02c) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision c482712c0ff06d5654836fc8d9af535641d63ffb) @@ -1298,6 +1298,62 @@ } [Test] + public void Register_WithNullDuneErosionFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new DuneErosionSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullDuneErosionSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new DuneErosionFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullStabilityStoneCoverFailureMechanismSectionResult_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new StabilityStoneCoverSectionResultEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Register_WithNullStabilityStoneCoverSectionResultEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new StabilityStoneCoverFailureMechanismSectionResult(new TestFailureMechanismSection())); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] public void Register_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() { // Setup @@ -2060,6 +2116,48 @@ } [Test] + public void TransferIds_WithDuneErosionSectionResultEntityAddedWithDuneErosionFailureMechanismSectionResult_EqualDuneErosionSectionEntityIdAndDuneErosionFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new DuneErosionSectionResultEntity + { + DuneErosionSectionResultEntityId = storageId + }; + var model = new DuneErosionFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferIds_WithStabilityStoneCoverSectionResultEntityAddedWithStabilityStoneCoverFailureMechanismSectionResult_EqualStabilityStoneCoverSectionEntityIdAndStabilityStoneCoverFailureMechanismSectionResultStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1,4000); + var entity = new StabilityStoneCoverSectionResultEntity + { + StabilityStoneCoverSectionResultEntityId = storageId + }; + var model = new StabilityStoneCoverFailureMechanismSectionResult(new TestFailureMechanismSection()); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] public void TransferIds_WithHydraulicLocationEntityAdded_EqualHydraulicLocationEntityIdAndHydraulicBoundaryLocationStorageId() { // Setup @@ -2989,6 +3087,78 @@ } [Test] + public void RemoveUntouched_DuneErosionSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new DuneErosionSectionResultEntity + { + DuneErosionSectionResultEntityId = 1 + }; + var persistentEntity = new DuneErosionSectionResultEntity + { + DuneErosionSectionResultEntityId = 2 + }; + dbContext.DuneErosionSectionResultEntities.Add(orphanedEntity); + dbContext.DuneErosionSectionResultEntities.Add(persistentEntity); + + var section = new DuneErosionFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.DuneErosionSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.DuneErosionSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.DuneErosionSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] + public void RemoveUntouched_StabilityStoneCoverSectionResultEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new StabilityStoneCoverSectionResultEntity + { + StabilityStoneCoverSectionResultEntityId = 1 + }; + var persistentEntity = new StabilityStoneCoverSectionResultEntity + { + StabilityStoneCoverSectionResultEntityId = 2 + }; + dbContext.StabilityStoneCoverSectionResultEntities.Add(orphanedEntity); + dbContext.StabilityStoneCoverSectionResultEntities.Add(persistentEntity); + + var section = new StabilityStoneCoverFailureMechanismSectionResult(new TestFailureMechanismSection()) + { + StorageId = persistentEntity.StabilityStoneCoverSectionResultEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, section); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.StabilityStoneCoverSectionResultEntities.Count()); + CollectionAssert.Contains(dbContext.StabilityStoneCoverSectionResultEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] public void RemoveUntouched_HydraulicLocationEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() { // Setup