Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/AssessmentSectionCreateExtensions.cs (.../AssessmentSectionCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -24,7 +24,7 @@ CreateReferenceLine(section, entity); CreateFailureMechanismPlaceHolders(section, entity, collector); - collector.Add(entity, section); + collector.Create(entity, section); return entity; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs =================================================================== diff -u -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs (.../CreateConversionCollector.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs (.../CreateConversionCollector.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -13,9 +13,9 @@ namespace Application.Ringtoets.Storage.Create { /// - /// This class can be used to keep track of create operations on a database. When all operations have been performed, then - /// the collected information can be used, for example, to transfer the ids assigned to the created database instances - /// back to the data model. + /// This class can be used to keep track of create operations on a database. This information can used to reuse previously created + /// objects. When all operations have been performed, then the collected information can be used to transfer the ids assigned to + /// the created database instances back to the data model. /// public class CreateConversionCollector { @@ -28,56 +28,163 @@ private readonly Dictionary soilProfiles = new Dictionary(new ReferenceEqualityComparer()); private readonly Dictionary soilLayers = new Dictionary(new ReferenceEqualityComparer()); - internal void Add(ProjectEntity entity, Project model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(ProjectEntity entity, Project model) { - Add(projects, entity, model); + Create(projects, entity, model); } - internal void Add(AssessmentSectionEntity entity, AssessmentSection model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(AssessmentSectionEntity entity, AssessmentSection model) { - Add(assessmentSections, entity, model); + Create(assessmentSections, entity, model); } - internal void Add(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) { - Add(hydraulicLocations, entity, model); + Create(hydraulicLocations, entity, model); } - internal void Add(FailureMechanismEntity entity, FailureMechanismBase model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(FailureMechanismEntity entity, FailureMechanismBase model) { - Add(failureMechanisms, entity, model); + Create(failureMechanisms, entity, model); } - internal void Add(StochasticSoilModelEntity entity, StochasticSoilModel model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(StochasticSoilModelEntity entity, StochasticSoilModel model) { - Add(stochasticSoilModels, entity, model); + Create(stochasticSoilModels, entity, model); } - internal void Add(StochasticSoilProfileEntity entity, StochasticSoilProfile model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(StochasticSoilProfileEntity entity, StochasticSoilProfile model) { - Add(stochasticSoilProfiles, entity, model); + Create(stochasticSoilProfiles, entity, model); } - internal void Add(SoilProfileEntity entity, PipingSoilProfile model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(SoilProfileEntity entity, PipingSoilProfile model) { - Add(soilProfiles, entity, model); + Create(soilProfiles, entity, model); } - internal void Add(SoilLayerEntity entity, PipingSoilLayer model) + /// + /// Registers a create operation for and the that + /// was constructed with the information. + /// + /// The that was constructed. + /// The new which needed to be created. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Create(SoilLayerEntity entity, PipingSoilLayer model) { - Add(soilLayers, entity, model); + Create(soilLayers, entity, model); } + /// + /// Checks whether a create operations has been registered for the given . + /// + /// The to check for. + /// true if the was created before, false otherwise. + /// Thrown when is null. internal bool Contains(PipingSoilProfile model) { return ContainsValue(soilProfiles, model); } + /// + /// Obtains the which was created for the given . + /// + /// The for which a read operation has been registerd. + /// The constructed . + /// Thrown when is null. + /// Thrown when no create operation has been registered for + /// . + /// Use to find out whether a create operation has been registered for + /// . internal SoilProfileEntity Get(PipingSoilProfile model) { return Get(soilProfiles, model); } + /// + /// Transfer ids from the created entities to the domain model objects' property. + /// internal void TransferIds() { foreach (var entity in projects.Keys) @@ -131,7 +238,7 @@ return collection.ContainsValue(model); } - private void Add(Dictionary collection, T entity, U model) + private void Create(Dictionary collection, T entity, U model) { if (entity == null) { Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismPlaceholderCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismPlaceholderCreateExtensions.cs (.../FailureMechanismPlaceholderCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/FailureMechanismPlaceholderCreateExtensions.cs (.../FailureMechanismPlaceholderCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -19,7 +19,7 @@ IsRelevant = Convert.ToByte(mechanism.IsRelevant) }; - collector.Add(entity, mechanism); + collector.Create(entity, mechanism); return entity; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HydraulicBoundaryLocationCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HydraulicBoundaryLocationCreateExtensions.cs (.../HydraulicBoundaryLocationCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/HydraulicBoundaryLocationCreateExtensions.cs (.../HydraulicBoundaryLocationCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -22,7 +22,7 @@ DesignWaterLevel = Double.IsNaN(location.DesignWaterLevel) ? (double?) null : Convert.ToDouble(location.DesignWaterLevel) }; - collector.Add(entity, location); + collector.Create(entity, location); return entity; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingFailureMechanismCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingFailureMechanismCreateExtensions.cs (.../PipingFailureMechanismCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingFailureMechanismCreateExtensions.cs (.../PipingFailureMechanismCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -21,7 +21,7 @@ CreateStochasticSoilModels(mechanism, collector, entity); - collector.Add(entity, mechanism); + collector.Create(entity, mechanism); return entity; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilLayerCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilLayerCreateExtensions.cs (.../PipingSoilLayerCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilLayerCreateExtensions.cs (.../PipingSoilLayerCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -19,7 +19,7 @@ Top = Convert.ToDecimal(layer.Top) }; - collector.Add(entity, layer); + collector.Create(entity, layer); return entity; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilProfileCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilProfileCreateExtensions.cs (.../PipingSoilProfileCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/PipingSoilProfileCreateExtensions.cs (.../PipingSoilProfileCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -25,7 +25,7 @@ CreatePipingSoilLayers(profile, collector, entity); - collector.Add(entity, profile); + collector.Create(entity, profile); return entity; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ProjectCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ProjectCreateExtensions.cs (.../ProjectCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ProjectCreateExtensions.cs (.../ProjectCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -22,7 +22,7 @@ CreateAssessmentSections(project, entity, collector); - collector.Add(entity, project); + collector.Create(entity, project); return entity; } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilModelCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilModelCreateExtensions.cs (.../StochasticSoilModelCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilModelCreateExtensions.cs (.../StochasticSoilModelCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -24,7 +24,7 @@ entity.StochasticSoilProfileEntities.Add(stochasticSoilProfile.Create(collector)); } - collector.Add(entity, model); + collector.Create(entity, model); return entity; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilProfileCreateExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilProfileCreateExtensions.cs (.../StochasticSoilProfileCreateExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/StochasticSoilProfileCreateExtensions.cs (.../StochasticSoilProfileCreateExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -14,7 +14,7 @@ SoilProfileEntity = profile.SoilProfile.Create(collector) }; - collector.Add(entity, profile); + collector.Create(entity, profile); return entity; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ReadConversionCollector.cs (.../ReadConversionCollector.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -1,27 +1,83 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Application.Ringtoets.Storage.DbContext; using Core.Common.Utils; using Ringtoets.Piping.Primitives; namespace Application.Ringtoets.Storage.Read { + /// + /// Class that can be used to keep track of data model objects which were initialized during a read operation + /// from the database. Can be used to reuse objects when reading an already read entity. + /// public class ReadConversionCollector { private readonly Dictionary soilProfiles = new Dictionary(new ReferenceEqualityComparer()); - internal void Add(SoilProfileEntity entity, PipingSoilProfile profile) + /// + /// Registers a read operation for and the that + /// was constructed with the information. + /// + /// The that was read. + /// The that was constructed. + /// Thrown when either: + /// + /// is null + /// is null + /// + internal void Read(SoilProfileEntity entity, PipingSoilProfile model) { - soilProfiles[entity] = profile; + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + + soilProfiles[entity] = model; } + /// + /// Checks whether a read operations has been registered for the given . + /// + /// The to check for. + /// true if the was read before, false otherwise. + /// Thrown when is null. internal bool Contains(SoilProfileEntity entity) { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } return soilProfiles.ContainsKey(entity); } - internal PipingSoilProfile Get(SoilProfileEntity soilProfileEntity) + /// + /// Obtains the which was read for the given . + /// + /// The for which a read operation has been registerd. + /// The constructed . + /// Thrown when is null. + /// Thrown when no read operation has been registered for + /// . + /// Use to find out whether a read operation has been registered for + /// . + internal PipingSoilProfile Get(SoilProfileEntity entity) { - return soilProfiles[soilProfileEntity]; + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + try + { + return soilProfiles[entity]; + } + catch (KeyNotFoundException e) + { + throw new InvalidOperationException(e.Message, e); + } } } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SoilProfileEntity.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SoilProfileEntity.cs (.../SoilProfileEntity.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/SoilProfileEntity.cs (.../SoilProfileEntity.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -23,7 +23,7 @@ { StorageId = SoilProfileEntityId }; - collector.Add(this, pipingSoilProfile); + collector.Read(this, pipingSoilProfile); return pipingSoilProfile; } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IStorableExtensions.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IStorableExtensions.cs (.../IStorableExtensions.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/IStorableExtensions.cs (.../IStorableExtensions.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -2,8 +2,16 @@ namespace Application.Ringtoets.Storage.Update { + /// + /// This class contains methods which can be performed on the IStorable interface. + /// public static class IStorableExtensions { + /// + /// Checks whether the is concidered new from the database's perspective. + /// + /// The to check for. + /// true if the is concidered new, false otherwise. public static bool IsNew(this IStorable storable) { return storable.StorageId <= 0; Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs =================================================================== diff -u -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -1,11 +1,17 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.Create; using Application.Ringtoets.Storage.DbContext; using Core.Common.Utils; namespace Application.Ringtoets.Storage.Update { + /// + /// Class that can be used to keep track of data model objects which were potentially created or updated during an update + /// operation. Can be used to reuse objects when assigning an already created domain model object or to remove entities + /// from the database which were not potentialy modified. + /// public class UpdateConversionCollector : CreateConversionCollector { private readonly HashSet projects = new HashSet(new ReferenceEqualityComparer()); @@ -17,47 +23,115 @@ private readonly HashSet soilProfiles = new HashSet(new ReferenceEqualityComparer()); private readonly HashSet soilLayers = new HashSet(new ReferenceEqualityComparer()); + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(ProjectEntity entity) { - projects.Add(entity); + Update(entity, projects); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(AssessmentSectionEntity entity) { - assessmentSections.Add(entity); + Update(entity, assessmentSections); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(FailureMechanismEntity entity) { - failureMechanisms.Add(entity); + Update(entity, failureMechanisms); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(HydraulicLocationEntity entity) { hydraulicLocations.Add(entity); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(StochasticSoilModelEntity entity) { - stochasticSoilModels.Add(entity); + Update(entity, stochasticSoilModels); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(StochasticSoilProfileEntity entity) { - stochasticSoilProfiles.Add(entity); + Update(entity, stochasticSoilProfiles); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(SoilProfileEntity entity) { - soilProfiles.Add(entity); + Update(entity, soilProfiles); } + /// + /// Registers an update operation for . + /// + /// The that was updated. + /// Thrown when either: + /// + /// is null + /// internal void Update(SoilLayerEntity entity) { - soilLayers.Add(entity); + Update(entity, soilLayers); } - public void RemoveUntouched(IRingtoetsEntities dbContext) + /// + /// Removes all the entities for which no update operation was registered from the . + /// + /// The from which to remove the entities. + internal void RemoveUntouched(IRingtoetsEntities dbContext) { var projectEntities = dbContext.ProjectEntities; projectEntities.RemoveRange(projectEntities.Local.Except(projects)); @@ -83,5 +157,14 @@ var soilLayerEntities = dbContext.SoilLayerEntities; soilLayerEntities.RemoveRange(soilLayerEntities.Local.Except(soilLayers)); } + + private void Update(T entity, HashSet collection) + { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + collection.Add(entity); + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -110,6 +110,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs =================================================================== diff -u -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 -rd3cfb50d8334298aff5314958fc9fa29846435a5 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs (.../CreateConversionCollectorTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs (.../CreateConversionCollectorTest.cs) (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -39,7 +39,7 @@ // Setup var collector = new CreateConversionCollector(); var profile = new TestPipingSoilProfile(); - collector.Add(new SoilProfileEntity(), profile); + collector.Create(new SoilProfileEntity(), profile); // Call var result = collector.Contains(profile); @@ -68,7 +68,7 @@ // Setup var collector = new CreateConversionCollector(); var profile = new TestPipingSoilProfile(); - collector.Add(new SoilProfileEntity(), new TestPipingSoilProfile()); + collector.Create(new SoilProfileEntity(), new TestPipingSoilProfile()); // Call var result = collector.Contains(profile); @@ -98,7 +98,7 @@ var collector = new CreateConversionCollector(); var profile = new TestPipingSoilProfile(); var entity = new SoilProfileEntity(); - collector.Add(entity, profile); + collector.Create(entity, profile); // Call var result = collector.Get(profile); @@ -127,7 +127,7 @@ // Setup var collector = new CreateConversionCollector(); var profile = new TestPipingSoilProfile(); - collector.Add(new SoilProfileEntity(), new TestPipingSoilProfile()); + collector.Create(new SoilProfileEntity(), new TestPipingSoilProfile()); // Call TestDelegate test = () => collector.Get(profile); @@ -136,228 +136,228 @@ Assert.Throws(test); } - #region Add methods + #region Create methods [Test] - public void Add_WithNullProjectEntity_ThrowsArgumentNullException() + public void Create_WithNullProjectEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new Project()); + TestDelegate test = () => collector.Create(null, new Project()); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullProject_ThrowsArgumentNullException() + public void Create_WithNullProject_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new ProjectEntity(), null); + TestDelegate test = () => collector.Create(new ProjectEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullAssessmentSectionEntity_ThrowsArgumentNullException() + public void Create_WithNullAssessmentSectionEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new AssessmentSection(AssessmentSectionComposition.Dike)); + TestDelegate test = () => collector.Create(null, new AssessmentSection(AssessmentSectionComposition.Dike)); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullAssessmentSection_ThrowsArgumentNullException() + public void Create_WithNullAssessmentSection_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new AssessmentSectionEntity(), null); + TestDelegate test = () => collector.Create(new AssessmentSectionEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullFailureMechanismEntity_ThrowsArgumentNullException() + public void Create_WithNullFailureMechanismEntity_ThrowsArgumentNullException() { // Setup var mocks = new MockRepository(); var model = mocks.StrictMock("name", "code"); var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, model); + TestDelegate test = () => collector.Create(null, model); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullFailureMechanismBase_ThrowsArgumentNullException() + public void Create_WithNullFailureMechanismBase_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new FailureMechanismEntity(), null); + TestDelegate test = () => collector.Create(new FailureMechanismEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() + public void Create_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new HydraulicBoundaryLocation(-1, "name", 0, 0)); + TestDelegate test = () => collector.Create(null, new HydraulicBoundaryLocation(-1, "name", 0, 0)); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullHydraulicBoundaryLocation_ThrowsArgumentNullException() + public void Create_WithNullHydraulicBoundaryLocation_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new HydraulicLocationEntity(), null); + TestDelegate test = () => collector.Create(new HydraulicLocationEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullStochasticSoilModelEntity_ThrowsArgumentNullException() + public void Create_WithNullStochasticSoilModelEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new TestStochasticSoilModel()); + TestDelegate test = () => collector.Create(null, new TestStochasticSoilModel()); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullStochasticSoilModel_ThrowsArgumentNullException() + public void Create_WithNullStochasticSoilModel_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new StochasticSoilModelEntity(), null); + TestDelegate test = () => collector.Create(new StochasticSoilModelEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullStochasticSoilProfileEntity_ThrowsArgumentNullException() + public void Create_WithNullStochasticSoilProfileEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, -1)); + TestDelegate test = () => collector.Create(null, new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, -1)); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullStochasticSoilProfile_ThrowsArgumentNullException() + public void Create_WithNullStochasticSoilProfile_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new StochasticSoilProfileEntity(), null); + TestDelegate test = () => collector.Create(new StochasticSoilProfileEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullSoilProfileEntity_ThrowsArgumentNullException() + public void Create_WithNullSoilProfileEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new PipingSoilProfile("name", 0, new [] { new PipingSoilLayer(1) }, SoilProfileType.SoilProfile1D, -1)); + TestDelegate test = () => collector.Create(null, new PipingSoilProfile("name", 0, new [] { new PipingSoilLayer(1) }, SoilProfileType.SoilProfile1D, -1)); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullPipingSoilProfile_ThrowsArgumentNullException() + public void Create_WithNullPipingSoilProfile_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new SoilProfileEntity(), null); + TestDelegate test = () => collector.Create(new SoilProfileEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("model", paramName); } [Test] - public void Add_WithNullSoilLayerEntity_ThrowsArgumentNullException() + public void Create_WithNullSoilLayerEntity_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(null, new PipingSoilLayer(0)); + TestDelegate test = () => collector.Create(null, new PipingSoilLayer(0)); // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("entity", paramName); } [Test] - public void Add_WithNullPipingSoilLayer_ThrowsArgumentNullException() + public void Create_WithNullPipingSoilLayer_ThrowsArgumentNullException() { // Setup var collector = new CreateConversionCollector(); // Call - TestDelegate test = () => collector.Add(new SoilLayerEntity(), null); + TestDelegate test = () => collector.Create(new SoilLayerEntity(), null); // Assert var paramName = Assert.Throws(test).ParamName; @@ -380,7 +380,7 @@ ProjectEntityId = storageId }; var model = new Project(); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -401,7 +401,7 @@ AssessmentSectionEntityId = storageId }; var model = new AssessmentSection(AssessmentSectionComposition.Dike); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -422,7 +422,7 @@ FailureMechanismEntityId = storageId }; var model = new PipingFailureMechanism(); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -443,7 +443,7 @@ FailureMechanismEntityId = storageId }; var model = new FailureMechanismPlaceholder("name"); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -464,7 +464,7 @@ HydraulicLocationEntityId = storageId }; var model = new HydraulicBoundaryLocation(-1, "name", 0, 0); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -485,7 +485,7 @@ StochasticSoilModelEntityId = storageId }; var model = new StochasticSoilModel(-1, "name", "name"); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -506,7 +506,7 @@ StochasticSoilProfileEntityId = storageId }; var model = new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, -1); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -527,7 +527,7 @@ SoilProfileEntityId = storageId }; var model = new PipingSoilProfile("name", 0, new [] { new PipingSoilLayer(1) }, SoilProfileType.SoilProfile1D, -1); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); @@ -548,7 +548,7 @@ SoilLayerEntityId = storageId }; var model = new PipingSoilLayer(0); - collector.Add(entity, model); + collector.Create(entity, model); // Call collector.TransferIds(); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ReadConversionCollectorTest.cs (revision d3cfb50d8334298aff5314958fc9fa29846435a5) @@ -0,0 +1,158 @@ +using System; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Read; +using NUnit.Framework; +using Ringtoets.Piping.KernelWrapper.TestUtil; + +namespace Application.Ringtoets.Storage.Test.Read +{ + [TestFixture] + public class ReadConversionCollectorTest + { + + [Test] + public void Contains_WithoutEntity_ArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Contains(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Contains_SoilProfileAdded_True() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new SoilProfileEntity(); + collector.Read(entity, new TestPipingSoilProfile()); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoSoilProfileAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new SoilProfileEntity(); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherSoilProfileEntityAdded_False() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new SoilProfileEntity(); + collector.Read(new SoilProfileEntity(), new TestPipingSoilProfile()); + + // Call + var result = collector.Contains(entity); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_WithoutEntity_ArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Get(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Get_SoilProfileAdded_ReturnsEntity() + { + // Setup + var collector = new ReadConversionCollector(); + var profile = new TestPipingSoilProfile(); + var entity = new SoilProfileEntity(); + collector.Read(entity, profile); + + // Call + var result = collector.Get(entity); + + // Assert + Assert.AreSame(profile, result); + } + + [Test] + public void Get_NoSoilProfileAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new SoilProfileEntity(); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherSoilProfileAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new ReadConversionCollector(); + var entity = new SoilProfileEntity(); + collector.Read(new SoilProfileEntity(), new TestPipingSoilProfile()); + + // Call + TestDelegate test = () => collector.Get(entity); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Read_WithNullSoilProfileEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(null, new TestPipingSoilProfile()); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Read_WithNullProfileEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new ReadConversionCollector(); + + // Call + TestDelegate test = () => collector.Read(new SoilProfileEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + } +} \ No newline at end of file