Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs =================================================================== diff -u -rfede09cc68b91cab1a81cbd63b3b7120fa9bf218 -r678685141f0211ca24ce5c03fc5eb05cc99f0f48 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision fede09cc68b91cab1a81cbd63b3b7120fa9bf218) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/PersistenceRegistryTest.cs (.../PersistenceRegistryTest.cs) (revision 678685141f0211ca24ce5c03fc5eb05cc99f0f48) @@ -844,6 +844,34 @@ } [Test] + public void Register_WithNullPipingCalculationOutputEntity_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(null, new PipingOutput(1,1,1,1,1,1)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Register_WithNullPipingOutput_ThrowsArgumentNullException() + { + // Setup + var registry = new PersistenceRegistry(); + + // Call + TestDelegate test = () => registry.Register(new PipingCalculationOutputEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] public void Register_WithNullStochasticSoilModelEntity_ThrowsArgumentNullException() { // Setup @@ -1212,6 +1240,27 @@ } [Test] + public void TransferId_WithPipingCalculationOutputEntityAdded_EqualPipingCalculationOutputEntityIdAndPipingOutputStorageId() + { + // Setup + var registry = new PersistenceRegistry(); + + long storageId = new Random(21).Next(1, 4000); + var entity = new PipingCalculationOutputEntity + { + PipingCalculationOutputEntityId = storageId + }; + var model = new PipingOutput(1,2,3,4,5,6); + registry.Register(entity, model); + + // Call + registry.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] public void TransferId_WithStochasticSoilModelEntityAdded_EqualStochasticSoilModelEntityIdAndStochasticSoilModelStorageId() { // Setup @@ -1598,6 +1647,42 @@ } [Test] + public void RemoveUntouched_PipingCalculationOutputEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() + { + // Setup + var mocks = new MockRepository(); + IRingtoetsEntities dbContext = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var orphanedEntity = new PipingCalculationOutputEntity + { + PipingCalculationOutputEntityId = 1 + }; + var persistentEntity = new PipingCalculationOutputEntity + { + PipingCalculationOutputEntityId = 2 + }; + dbContext.PipingCalculationOutputEntities.Add(orphanedEntity); + dbContext.PipingCalculationOutputEntities.Add(persistentEntity); + + var calculationGroup = new PipingOutput(1,2,3,4,5,6) + { + StorageId = persistentEntity.PipingCalculationOutputEntityId + }; + + var registry = new PersistenceRegistry(); + registry.Register(persistentEntity, calculationGroup); + + // Call + registry.RemoveUntouched(dbContext); + + // Assert + Assert.AreEqual(1, dbContext.PipingCalculationOutputEntities.Count()); + CollectionAssert.Contains(dbContext.PipingCalculationOutputEntities, persistentEntity); + mocks.VerifyAll(); + } + + [Test] public void RemoveUntouched_StochasticSoilModelEntity_OrphanedEntityIsRemovedFromRingtoetsEntities() { // Setup