Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs (.../CreateConversionCollector.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/CreateConversionCollector.cs (.../CreateConversionCollector.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -1,17 +1,22 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Application.Ringtoets.Storage.DbContext; using Core.Common.Base.Data; using Core.Common.Utils; using Ringtoets.Common.Data.FailureMechanism; using Ringtoets.HydraRing.Data; using Ringtoets.Integration.Data; -using Ringtoets.Integration.Data.Placeholders; using Ringtoets.Piping.Data; using Ringtoets.Piping.Primitives; 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. + /// public class CreateConversionCollector { private readonly Dictionary projects = new Dictionary(new ReferenceEqualityComparer()); @@ -33,21 +38,16 @@ Add(assessmentSections, entity, model); } - public void Add(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) + internal void Add(HydraulicLocationEntity entity, HydraulicBoundaryLocation model) { Add(hydraulicLocations, entity, model); } - public void Add(FailureMechanismEntity entity, FailureMechanismPlaceholder model) + internal void Add(FailureMechanismEntity entity, FailureMechanismBase model) { Add(failureMechanisms, entity, model); } - internal void Add(FailureMechanismEntity entity, PipingFailureMechanism model) - { - Add(failureMechanisms, entity, model); - } - internal void Add(StochasticSoilModelEntity entity, StochasticSoilModel model) { Add(stochasticSoilModels, entity, model); @@ -70,7 +70,7 @@ internal bool Contains(PipingSoilProfile model) { - return soilProfiles.ContainsValue(model); + return ContainsValue(soilProfiles, model); } internal SoilProfileEntity Get(PipingSoilProfile model) @@ -121,13 +121,37 @@ } } + private bool ContainsValue(Dictionary collection, U model) + { + if (model == null) + { + throw new ArgumentNullException("model"); + } + + return collection.ContainsValue(model); + } + private void Add(Dictionary collection, T entity, U model) { + if (entity == null) + { + throw new ArgumentNullException("entity"); + } + if (model == null) + { + throw new ArgumentNullException("model"); + } + collection[entity] = model; } private T Get(Dictionary collection, U model) { + if (model == null) + { + throw new ArgumentNullException("model"); + } + return collection.Keys.Single(k => ReferenceEquals(collection[k], model)); } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/AssemblyInfo.cs =================================================================== diff -u -r2ae1c9433c3c28b32105b9778b682b5e512a0f00 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision 2ae1c9433c3c28b32105b9778b682b5e512a0f00) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/AssemblyInfo.cs (.../AssemblyInfo.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -26,4 +26,5 @@ [assembly: AssemblyTitle("Application.Ringtoets.Storage")] [assembly: AssemblyProduct("Application.Ringtoets.Storage")] [assembly: Guid("141a91e4-bc69-45a4-8cb6-195bda83031b")] -[assembly: InternalsVisibleTo("Application.Ringtoets.Storage.Test")] \ No newline at end of file +[assembly: InternalsVisibleTo("Application.Ringtoets.Storage.Test")] +[assembly: InternalsVisibleTo("Application.Ringtoets.Storage.TestUtil")] \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.Designer.cs =================================================================== diff -u -r2ae1c9433c3c28b32105b9778b682b5e512a0f00 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision 2ae1c9433c3c28b32105b9778b682b5e512a0f00) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.Designer.cs (.../Resources.Designer.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.42000 +// Runtime Version:4.0.30319.34209 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -61,27 +61,30 @@ } /// - /// Looks up a localized string similar to /* ---------------------------------------------------- */ - ////* Generated by Enterprise Architect Version 12.0 */ - ////* Created On : 17-Mar-2016 12:54:29 PM */ - ////* DBMS : SQLite */ - ////* ---------------------------------------------------- */ - /// - ////* Drop Tables */ - /// - ///DROP TABLE IF EXISTS 'DikeAssessmentSectionEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'FailureMechanismEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'ProjectEntity' - ///; - /// - ///DROP TABLE IF EXISTS 'Version' - ///; - /// - ////* Create Tables with Primary and Foreign Keys, Check and [rest of string was truncated]";. + /// Looks up a localized string similar to /* ---------------------------------------------------- */ + ////* Generated by Enterprise Architect Version 12.0 */ + ////* Created On : 21-apr-2016 15:29:00 */ + ////* DBMS : SQLite */ + ////* ---------------------------------------------------- */ + /// + ////* Drop Tables */ + /// + ///DROP TABLE IF EXISTS 'VersionEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'ProjectEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'AssessmentSectionEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'FailureMechanismEntity' + ///; + /// + ///DROP TABLE IF EXISTS 'HydraulicLocationEntity' + ///; + /// + ///DROP TABL [rest of string was truncated]";. /// internal static string DatabaseStructure { get { @@ -142,5 +145,14 @@ return ResourceManager.GetString("Ringtoets_project_file_filter", resourceCulture); } } + + /// + /// Looks up a localized string similar to Het bestand is geen geldig Ringtoets bestand.. + /// + internal static string StorageSqLite_LoadProject_Invalid_Ringtoets_database_file { + get { + return ResourceManager.GetString("StorageSqLite_LoadProject_Invalid_Ringtoets_database_file", resourceCulture); + } + } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.resx =================================================================== diff -u -ref1c61d94f2aec3b4ff32fcf03253d7ad386c8e5 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.resx (.../Resources.resx) (revision ef1c61d94f2aec3b4ff32fcf03253d7ad386c8e5) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Properties/Resources.resx (.../Resources.resx) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -139,4 +139,7 @@ Ringtoetsproject (*.rtd)|*.rtd + + Het bestand is geen geldig Ringtoets bestand. + \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -80,20 +80,14 @@ SetConnectionToNewFile(databaseFilePath); using (var dbContext = new RingtoetsEntities(connectionString)) { - var projectEntityPersistor = new ProjectPersistor(dbContext); try { -// projectEntityPersistor.InsertModel(project); - var collector = new CreateConversionCollector(); dbContext.ProjectEntities.Add(project.Create(collector)); var changes = dbContext.SaveChanges(); collector.TransferIds(); -// projectEntityPersistor.PerformPostSaveActions(); - project.Name = Path.GetFileNameWithoutExtension(databaseFilePath); - return changes; } catch (DataException exception) @@ -138,23 +132,19 @@ SetConnectionToFile(databaseFilePath); using (var dbContext = new RingtoetsEntities(connectionString)) { - var projectEntityPersistor = new ProjectPersistor(dbContext); try { -// projectEntityPersistor.UpdateModel(project); -// projectEntityPersistor.RemoveUnModifiedEntries(); - var updateCollector = new UpdateConversionCollector(); project.Update(updateCollector, dbContext); updateCollector.RemoveUntouched(dbContext); var changes = dbContext.SaveChanges(); updateCollector.TransferIds(); -// projectEntityPersistor.PerformPostSaveActions(); + return changes; } - catch (EntityNotFoundException) + catch (EntityNotFoundException e) { - throw CreateStorageWriterException(string.Format(Resources.Error_Entity_Not_Found_0_1, "project", project.StorageId)); + throw CreateStorageWriterException(e.Message, e); } catch (DataException exception) { @@ -195,7 +185,7 @@ var projectEntity = GetSingleProject(dbContext); if (projectEntity == null) { - throw CreateStorageReaderException("Het bestand is geen geldig Ringtoets bestand."); + throw CreateStorageReaderException(Resources.StorageSqLite_LoadProject_Invalid_Ringtoets_database_file); } var project = projectEntity.Read(); @@ -235,12 +225,8 @@ using (var dbContext = new RingtoetsEntities(connectionString)) { -// var projectEntityPersistor = new ProjectPersistor(dbContext); try { -// projectEntityPersistor.UpdateModel(project); -// projectEntityPersistor.RemoveUnModifiedEntries(); - var updateConversionCollector = new UpdateConversionCollector(); project.Update(updateConversionCollector, dbContext); updateConversionCollector.RemoveUntouched(dbContext); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/UpdateConversionCollector.cs (.../UpdateConversionCollector.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -22,17 +22,17 @@ projects.Add(entity); } - public void Update(AssessmentSectionEntity entity) + internal void Update(AssessmentSectionEntity entity) { assessmentSections.Add(entity); } - public void Update(FailureMechanismEntity entity) + internal void Update(FailureMechanismEntity entity) { failureMechanisms.Add(entity); } - public void Update(HydraulicLocationEntity entity) + internal void Update(HydraulicLocationEntity entity) { hydraulicLocations.Add(entity); } @@ -57,7 +57,7 @@ soilLayers.Add(entity); } - public void RemoveUntouched(RingtoetsEntities dbContext) + public void RemoveUntouched(IRingtoetsEntities dbContext) { var projectEntities = dbContext.ProjectEntities; projectEntities.RemoveRange(projectEntities.Local.Except(projects)); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -90,6 +90,8 @@ + + @@ -125,6 +127,7 @@ + @@ -133,6 +136,7 @@ + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/CreateConversionCollectorTest.cs (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -0,0 +1,562 @@ +using System; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Common.Data.FailureMechanism; +using Ringtoets.HydraRing.Data; +using Ringtoets.Integration.Data; +using Ringtoets.Integration.Data.Placeholders; +using Ringtoets.Piping.Data; +using Ringtoets.Piping.Data.TestUtil; +using Ringtoets.Piping.KernelWrapper.TestUtil; +using Ringtoets.Piping.Primitives; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class CreateConversionCollectorTest + { + [Test] + public void Contains_WithoutModel_ArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Contains(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Contains_SoilProfileAdded_True() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + collector.Add(new SoilProfileEntity(), profile); + + // Call + var result = collector.Contains(profile); + + // Assert + Assert.IsTrue(result); + } + + [Test] + public void Contains_NoSoilProfileAdded_False() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + + // Call + var result = collector.Contains(profile); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Contains_OtherSoilProfileAdded_False() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + collector.Add(new SoilProfileEntity(), new TestPipingSoilProfile()); + + // Call + var result = collector.Contains(profile); + + // Assert + Assert.IsFalse(result); + } + + [Test] + public void Get_WithoutModel_ArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Get(null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Get_SoilProfileAdded_ReturnsEntity() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + var entity = new SoilProfileEntity(); + collector.Add(entity, profile); + + // Call + var result = collector.Get(profile); + + // Assert + Assert.AreSame(entity, result); + } + + [Test] + public void Get_NoSoilProfileAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + + // Call + TestDelegate test = () => collector.Get(profile); + + // Assert + Assert.Throws(test); + } + + [Test] + public void Get_OtherSoilProfileAdded_ThrowsInvalidOperationException() + { + // Setup + var collector = new CreateConversionCollector(); + var profile = new TestPipingSoilProfile(); + collector.Add(new SoilProfileEntity(), new TestPipingSoilProfile()); + + // Call + TestDelegate test = () => collector.Get(profile); + + // Assert + Assert.Throws(test); + } + + #region Add methods + + [Test] + public void Add_WithNullProjectEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new Project()); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullProject_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new ProjectEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullAssessmentSectionEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new AssessmentSection(AssessmentSectionComposition.Dike)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullAssessmentSection_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new AssessmentSectionEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullFailureMechanismEntity_ThrowsArgumentNullException() + { + // Setup + var mocks = new MockRepository(); + var model = mocks.StrictMock("name", "code"); + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, model); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullFailureMechanismBase_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new FailureMechanismEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullHydraulicLocationEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new HydraulicBoundaryLocation(-1, "name", 0, 0)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullHydraulicBoundaryLocation_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new HydraulicLocationEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullStochasticSoilModelEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new TestStochasticSoilModel()); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullStochasticSoilModel_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new StochasticSoilModelEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullStochasticSoilProfileEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, -1)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullStochasticSoilProfile_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new StochasticSoilProfileEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullSoilProfileEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(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() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new SoilProfileEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + [Test] + public void Add_WithNullSoilLayerEntity_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(null, new PipingSoilLayer(0)); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("entity", paramName); + } + + [Test] + public void Add_WithNullPipingSoilLayer_ThrowsArgumentNullException() + { + // Setup + var collector = new CreateConversionCollector(); + + // Call + TestDelegate test = () => collector.Add(new SoilLayerEntity(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("model", paramName); + } + + #endregion + + #region TransferId method + + [Test] + public void TransferId_WithProjectEntityAdded_EqualProjectEntityIdAndProjectStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new ProjectEntity + { + ProjectEntityId = storageId + }; + var model = new Project(); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithAssessmentSectionEntityAdded_EqualAssessmentSectionEntityIdAndAssessmentSectionStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new AssessmentSectionEntity + { + AssessmentSectionEntityId = storageId + }; + var model = new AssessmentSection(AssessmentSectionComposition.Dike); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithFailureMechanismEntityAddedWithPipingFailureMechanism_EqualFailureMechanismEntityIdAndPipingFailureMechanismStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new FailureMechanismEntity + { + FailureMechanismEntityId = storageId + }; + var model = new PipingFailureMechanism(); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithFailureMechanismEntityAddedWithFailureMechanismPlaceholder_EqualFailureMechanismEntityIdAndFailureMechanismPlaceholderStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new FailureMechanismEntity + { + FailureMechanismEntityId = storageId + }; + var model = new FailureMechanismPlaceholder("name"); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithHydraulicLocationEntityAdded_EqualHydraulicLocationEntityIdAndHydraulicBoundaryLocationStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new HydraulicLocationEntity + { + HydraulicLocationEntityId = storageId + }; + var model = new HydraulicBoundaryLocation(-1, "name", 0, 0); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithStochasticSoilModelEntityAdded_EqualStochasticSoilModelEntityIdAndStochasticSoilModelStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = storageId + }; + var model = new StochasticSoilModel(-1, "name", "name"); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithStochasticSoilProfileEntityAdded_EqualStochasticSoilProfileEntityIdAndStochasticSoilProfileStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new StochasticSoilProfileEntity + { + StochasticSoilProfileEntityId = storageId + }; + var model = new StochasticSoilProfile(1, SoilProfileType.SoilProfile1D, -1); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithSoilProfileEntityAdded_EqualSoilProfileEntityIdAndPipingSoilProfileStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new SoilProfileEntity + { + SoilProfileEntityId = storageId + }; + var model = new PipingSoilProfile("name", 0, new [] { new PipingSoilLayer(1) }, SoilProfileType.SoilProfile1D, -1); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + [Test] + public void TransferId_WithSoilLayerEntityAdded_EqualSoilLayerEntityIdAndPipingSoilLayerStorageId() + { + // Setup + var collector = new CreateConversionCollector(); + + long storageId = new Random(21).Next(1,4000); + var entity = new SoilLayerEntity + { + SoilLayerEntityId = storageId + }; + var model = new PipingSoilLayer(0); + collector.Add(entity, model); + + // Call + collector.TransferIds(); + + // Assert + Assert.AreEqual(storageId, model.StorageId); + } + + #endregion + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismPlaceholderCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismPlaceholderCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/FailureMechanismPlaceholderCreateExtensionsTest.cs (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -0,0 +1,49 @@ +using System; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using NUnit.Framework; +using Ringtoets.Integration.Data.Placeholders; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class FailureMechanismPlaceholderCreateExtensionsTest + { + [Test] + public void Create_WithoutCollector_ThrowsArgumentNullException() + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("name"); + + // Call + TestDelegate test = () => failureMechanism.Create(FailureMechanismType.DuneErosion, null); + + // Assert + var parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", parameterName); + } + + [Test] + [TestCase(true)] + [TestCase(false)] + public void Create_WithCollector_ReturnsFailureMechanismEntityWithPropertiesSet(bool isRelevant) + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("name") + { + IsRelevant = isRelevant + }; + var collector = new CreateConversionCollector(); + var failureMechanismType = FailureMechanismType.DuneErosion; + + // Call + var entity = failureMechanism.Create(failureMechanismType, collector); + + // Assert + Assert.IsNotNull(entity); + Assert.AreEqual((short)failureMechanismType, entity.FailureMechanismType); + Assert.AreEqual(Convert.ToByte(isRelevant), entity.IsRelevant); + Assert.IsEmpty(entity.StochasticSoilModelEntities); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs =================================================================== diff -u -rf1bd17ba95b3fbae5928d4240523d50d8b83b64d -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision f1bd17ba95b3fbae5928d4240523d50d8b83b64d) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -23,6 +23,7 @@ using System.Data; using System.Data.SQLite; using System.IO; +using Application.Ringtoets.Storage.Properties; using Application.Ringtoets.Storage.TestUtil; using Core.Common.Base.Data; using Core.Common.Base.Storage; @@ -90,7 +91,7 @@ } [Test] - public void LoadProject_InvalidRingtoetsFile_ThrowsStorageExceptionAndStorageValidationException() + public void LoadProject_RingtoetsFileWithoutSchema_ThrowsStorageExceptionAndStorageValidationException() { // Setup string validPath = "empty.rtd"; @@ -107,15 +108,43 @@ } [Test] + public void LoadProject_RingtoetsFileWithTwoProjects_ThrowsStorageExceptionAndStorageValidationException() + { + // Setup + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try + { + TestDelegate precondition = () => SqLiteDatabaseHelper.CreateDatabaseFile(tempRingtoetsFile, SqLiteDatabaseHelper.GetCompleteSchema()); + Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); + + // Call + TestDelegate test = () => new StorageSqLite().LoadProject(tempRingtoetsFile); + + // Assert + var expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': {1}", tempRingtoetsFile, Resources.StorageSqLite_LoadProject_Invalid_Ringtoets_database_file); + + StorageException exception = Assert.Throws(test); + Assert.IsInstanceOf(exception); + Assert.AreEqual(expectedMessage, exception.Message); + } + finally + { + CallGarbageCollector(); + fileDisposeHelper.Dispose(); + } + } + + [Test] public void LoadProject_CorruptRingtoetsFileThatPassesValidation_ThrowsStorageExceptionWithFullStackTrace() { // Setup var expectedMessage = String.Format(@"Fout bij het lezen van bestand '{0}': ", tempRingtoetsFile); var expectedInnerExceptionMessage = "An error occurred while executing the command definition. See the inner exception for details."; - var expectedInnerExceptionInnerExceptionMessage = "SQL logic error or missing database" + Environment.NewLine + - "no such table: ProjectEntity"; + var expectedInnerExceptionInnerExceptionMessage = "SQL logic error or missing database" + Environment.NewLine + + "no such table: ProjectEntity"; - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { TestDelegate precondition = () => SqLiteDatabaseHelper.CreateDatabaseFile(tempRingtoetsFile, SqLiteDatabaseHelper.GetCorruptSchema()); Assert.DoesNotThrow(precondition, "Precondition failed: creating corrupt database file failed"); @@ -133,7 +162,11 @@ Assert.IsInstanceOf(exception.InnerException.InnerException); Assert.AreEqual(expectedInnerExceptionInnerExceptionMessage, exception.InnerException.InnerException.Message); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -148,7 +181,8 @@ projectMock.Description = ""; projectMock.StorageId = 1L; - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Precondition SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, projectMock); @@ -161,7 +195,11 @@ Assert.AreEqual(1L, loadedProject.StorageId); Assert.AreEqual(projectName, loadedProject.Name); Assert.AreEqual(projectMock.Description, loadedProject.Description); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -190,14 +228,19 @@ // Setup var storage = new StorageSqLite(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Call TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, null); // Assert Assert.Throws(test); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -208,14 +251,19 @@ var project = new Project(); var storage = new StorageSqLite(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Call TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, project); // Assert Assert.DoesNotThrow(test); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -226,7 +274,8 @@ var project = new Project(); var storage = new StorageSqLite(); - using (var fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { fileDisposeHelper.Create(); @@ -235,7 +284,11 @@ // Assert Assert.DoesNotThrow(test); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -247,7 +300,8 @@ var project = new Project(); var storage = new StorageSqLite(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Call TestDelegate test = () => storage.SaveProjectAs(tempRingtoetsFile, project); @@ -263,7 +317,11 @@ Assert.IsInstanceOf(exception.InnerException); Assert.IsInstanceOf(exception); Assert.AreEqual(expectedMessage, exception.Message); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -293,7 +351,8 @@ var storage = new StorageSqLite(); Project storedProject = new Project(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Precondition SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); @@ -303,7 +362,11 @@ // Assert Assert.Throws(test); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -349,9 +412,10 @@ }; var storage = new StorageSqLite(); var expectedMessage = String.Format(@"Fout bij het schrijven naar bestand '{0}'{1}: {2}", tempRingtoetsFile, "", - String.Format("Het object '{0}' met id '{1}' is niet gevonden.", "project", projectWithIncorrectStorageId.StorageId)); + String.Format("Het object '{0}' met id '{1}' is niet gevonden.", "ProjectEntity", projectWithIncorrectStorageId.StorageId)); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { // Precondition SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, savedProject); @@ -362,7 +426,11 @@ // Assert StorageException exception = Assert.Throws(test); Assert.AreEqual(expectedMessage, exception.Message); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -381,7 +449,8 @@ var expectedInnerExceptionInnerExceptionMessage = "SQL logic error or missing database" + Environment.NewLine + "no such table: ProjectEntity"; - using (var fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { fileDisposeHelper.Create(); @@ -401,7 +470,11 @@ Assert.IsInstanceOf(exception.InnerException.InnerException); Assert.AreEqual(expectedInnerExceptionInnerExceptionMessage, exception.InnerException.InnerException.Message); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -418,7 +491,8 @@ }; var storage = new StorageSqLite(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { TestDelegate precondition = () => storage.SaveProjectAs(tempRingtoetsFile, project); Assert.DoesNotThrow(precondition, String.Format("Precondition: file '{0}' must be a valid Ringtoets database file.", tempRingtoetsFile)); @@ -429,7 +503,11 @@ // Assert Assert.DoesNotThrow(test); Assert.AreEqual(projectName, project.Name); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -438,16 +516,12 @@ { // Setup StorageSqLite storageSqLite = new StorageSqLite(); - var mockRepository = new MockRepository(); - var projectMock = mockRepository.StrictMock(); - mockRepository.ReplayAll(); // Call - bool hasChanges = storageSqLite.HasChanges(projectMock); + bool hasChanges = storageSqLite.HasChanges(new Project()); // Assert Assert.IsTrue(hasChanges); - mockRepository.VerifyAll(); } [Test] @@ -457,7 +531,8 @@ StorageSqLite storageSqLite = new StorageSqLite(); Project storedProject = new Project(); - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); Project loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); @@ -467,7 +542,11 @@ // Assert Assert.IsFalse(hasChanges); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -479,7 +558,8 @@ Project storedProject = new Project(); var changedName = "some name"; - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); Project loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); @@ -490,7 +570,11 @@ // Assert Assert.IsFalse(hasChanges); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } @@ -502,7 +586,8 @@ Project storedProject = new Project(); var changedDescription = "some description"; - using (new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(tempRingtoetsFile, storedProject); Project loadedProject = storageSqLite.LoadProject(tempRingtoetsFile); @@ -513,12 +598,16 @@ // Assert Assert.IsTrue(hasChanges); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } [Test] - public void HasChanges_EmptyDatabaseFile_ReturnsFalse() + public void HasChanges_SavedToEmptyDatabaseFile_ReturnsFalse() { // Setup var mockRepository = new MockRepository(); @@ -527,7 +616,8 @@ mockRepository.ReplayAll(); var storage = new StorageSqLite(); - using (var fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(tempRingtoetsFile); + try { fileDisposeHelper.Create(); @@ -540,7 +630,11 @@ // Assert Assert.IsFalse(hasChanges); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } mockRepository.VerifyAll(); } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs (.../AssessmentSectionUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/AssessmentSectionUpdateExtensionsTest.cs (.../AssessmentSectionUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -37,7 +37,13 @@ var section = new AssessmentSection(AssessmentSectionComposition.Dike); // Call - TestDelegate test = () => section.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + section.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; @@ -51,10 +57,18 @@ var section = new AssessmentSection(AssessmentSectionComposition.Dike); // Call - TestDelegate test = () => section.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + section.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'AssessmentSectionEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] @@ -66,9 +80,10 @@ mocks.ReplayAll(); + var storageId = 1; var section = new AssessmentSection(AssessmentSectionComposition.Dike) { - StorageId = 1 + StorageId = storageId }; ringtoetsEntities.AssessmentSectionEntities.Add(new AssessmentSectionEntity @@ -80,7 +95,9 @@ TestDelegate test = () => section.Update(new UpdateConversionCollector(), ringtoetsEntities); // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'AssessmentSectionEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/FailureMechanismPlaceholderUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/FailureMechanismPlaceholderUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/FailureMechanismPlaceholderUpdateExtensionsTest.cs (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -0,0 +1,134 @@ +using System; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Application.Ringtoets.Storage.TestUtil; +using Application.Ringtoets.Storage.Update; +using NUnit.Framework; +using Rhino.Mocks; +using Ringtoets.Integration.Data.Placeholders; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class FailureMechanismPlaceholderUpdateExtensionsTest + { + + [Test] + public void Update_WithoutContext_ArgumentNullException() + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("name"); + + // Call + TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("context", paramName); + } + + [Test] + public void Update_WithoutCollector_ArgumentNullException() + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("name"); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(null, ringtoetsEntities); + } + }; + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("collector", paramName); + } + + [Test] + public void Update_ContextWithNoFailureMechanism_EntityNotFoundException() + { + // Setup + var failureMechanism = new FailureMechanismPlaceholder("name"); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + } + + [Test] + public void Update_ContextWithNoFailureMechanismWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var failureMechanism = new FailureMechanismPlaceholder("name") + { + StorageId = storageId + }; + + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 2 + }); + + // Call + TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new FailureMechanismPlaceholder("name") + { + StorageId = 1, + IsRelevant = true + }; + + var failureMechanismEntity = new FailureMechanismEntity + { + FailureMechanismEntityId = 1, + IsRelevant = Convert.ToByte(false) + }; + + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + // Call + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + Assert.AreEqual(Convert.ToByte(true), failureMechanismEntity.IsRelevant); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/HydraulicBoundaryLocationUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/HydraulicBoundaryLocationUpdateExtensionsTest.cs (.../HydraulicBoundaryLocationUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/HydraulicBoundaryLocationUpdateExtensionsTest.cs (.../HydraulicBoundaryLocationUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -3,7 +3,6 @@ using Application.Ringtoets.Storage.Exceptions; using Application.Ringtoets.Storage.TestUtil; using Application.Ringtoets.Storage.Update; -using Core.Common.Base.Data; using NUnit.Framework; using Rhino.Mocks; using Ringtoets.HydraRing.Data; @@ -34,7 +33,13 @@ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); // Call - TestDelegate test = () => hydraulicBoundaryLocation.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + hydraulicBoundaryLocation.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; @@ -48,13 +53,52 @@ var hydraulicBoundaryLocation = new TestHydraulicBoundaryLocation(); // Call - TestDelegate test = () => hydraulicBoundaryLocation.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + hydraulicBoundaryLocation.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'HydraulicLocationEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] + public void Update_ContextWithNoNoHydraulicBoundaryLocationWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var section = new TestHydraulicBoundaryLocation + { + StorageId = storageId + }; + + ringtoetsEntities.HydraulicLocationEntities.Add(new HydraulicLocationEntity + { + HydraulicLocationEntityId = 2 + }); + + // Call + TestDelegate test = () => section.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'HydraulicLocationEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] public void Update_WithHydraulicBoundaryLocation_PropertiesUpdated() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingFailureMechanismUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingFailureMechanismUpdateExtensionsTest.cs (.../PipingFailureMechanismUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingFailureMechanismUpdateExtensionsTest.cs (.../PipingFailureMechanismUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -33,37 +33,82 @@ var failureMechanism = new PipingFailureMechanism(); // Call - TestDelegate test = () => failureMechanism.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("collector", paramName); } [Test] - public void Update_ContextWithNoHydraulicBoundaryLocation_EntityNotFoundException() + public void Update_ContextWithNoPipingFailureMechanism_EntityNotFoundException() { // Setup var failureMechanism = new PipingFailureMechanism(); // Call - TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] - public void Update_ContextWithHydraulicBoundaryLocation_PropertiesUpdated() + public void Update_ContextWithNoPipingFailureMechanismWithId_EntityNotFoundException() { // Setup MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); + var storageId = 1; var failureMechanism = new PipingFailureMechanism { + StorageId = storageId + }; + + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 2 + }); + + // Call + TestDelegate test = () => failureMechanism.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'FailureMechanismEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ContextWithPipingFailureMechanism_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var failureMechanism = new PipingFailureMechanism + { StorageId = 1, IsRelevant = true }; Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilLayerUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilLayerUpdateExtensionsTest.cs (.../PipingSoilLayerUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilLayerUpdateExtensionsTest.cs (.../PipingSoilLayerUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -33,28 +33,42 @@ var pipingSoilLayer = new PipingSoilLayer(0.5); // Call - TestDelegate test = () => pipingSoilLayer.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + pipingSoilLayer.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("collector", paramName); } [Test] - public void Update_ContextWithNoHydraulicBoundaryLocation_EntityNotFoundException() + public void Update_ContextWithNoPipingSoilLayer_EntityNotFoundException() { // Setup var pipingSoilLayer = new PipingSoilLayer(0.5); // Call - TestDelegate test = () => pipingSoilLayer.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + pipingSoilLayer.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'SoilLayerEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] - public void Update_WithHydraulicBoundaryLocation_PropertiesUpdated() + public void Update_ContextWithNoPipingSoilLayerWithId_EntityNotFoundException() { // Setup MockRepository mocks = new MockRepository(); @@ -64,8 +78,41 @@ var random = new Random(21); double newTop = random.NextDouble() * 10; - var hydraulicBoundaryLocation = new PipingSoilLayer(newTop) + var storageId = 1; + var pipingSoilLayer = new PipingSoilLayer(newTop) { + StorageId = storageId + }; + + ringtoetsEntities.SoilLayerEntities.Add(new SoilLayerEntity + { + SoilLayerEntityId = 2 + }); + + // Call + TestDelegate test = () => pipingSoilLayer.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'SoilLayerEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_WithPipingSoilLayer_PropertiesUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var random = new Random(21); + double newTop = random.NextDouble() * 10; + var pipingSoilLayer = new PipingSoilLayer(newTop) + { StorageId = 1, IsAquifer = true }; @@ -80,7 +127,7 @@ ringtoetsEntities.SoilLayerEntities.Add(soilLayerEntity); // Call - hydraulicBoundaryLocation.Update(new UpdateConversionCollector(), ringtoetsEntities); + pipingSoilLayer.Update(new UpdateConversionCollector(), ringtoetsEntities); // Assert Assert.AreEqual(Convert.ToDouble(newTop), Convert.ToDouble(soilLayerEntity.Top), 1e-6); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs (.../PipingSoilProfileUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/PipingSoilProfileUpdateExtensionsTest.cs (.../PipingSoilProfileUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -35,27 +35,78 @@ var soilProfile = new TestPipingSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; Assert.AreEqual("collector", paramName); } [Test] - public void Update_ContextWithNoStochasticSoilModel_EntityNotFoundException() + public void Update_ContextWithNoPipingSoilProfile_EntityNotFoundException() { // Setup var soilProfile = new TestPipingSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'SoilProfileEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] + public void Update_ContextWithNoPipingSoilProfileWithId_PropertiesUpdatedAndLayerAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + IEnumerable newLayers = new[] + { + new PipingSoilLayer(5.0) + }; + var storageId = 1; + var soilProfile = new PipingSoilProfile("new name", 0.5, newLayers, SoilProfileType.SoilProfile1D, -1) + { + StorageId = storageId + }; + + ringtoetsEntities.SoilProfileEntities.Add(new SoilProfileEntity + { + SoilProfileEntityId = 2, + Name = string.Empty, + Bottom = 0 + }); + + // Call + TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'SoilProfileEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] public void Update_NewSoilLayer_PropertiesUpdatedAndLayerAdded() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs (.../ProjectUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs (.../ProjectUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -38,7 +38,13 @@ var project = new Project(); // Call - TestDelegate test = () => project.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + project.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; @@ -52,7 +58,13 @@ var project = new Project(); // Call - TestDelegate test = () => project.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + project.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert Assert.Throws(test); @@ -67,9 +79,10 @@ mocks.ReplayAll(); + var storageId = 1; var project = new Project { - StorageId = 1 + StorageId = storageId }; ringtoetsEntities.ProjectEntities.Add(new ProjectEntity @@ -81,7 +94,9 @@ TestDelegate test = () => project.Update(new UpdateConversionCollector(), ringtoetsEntities); // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'ProjectEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); mocks.VerifyAll(); } @@ -95,26 +110,34 @@ mocks.ReplayAll(); + var storageId = 1; var project = new Project { - StorageId = 1 + StorageId = storageId }; ringtoetsEntities.ProjectEntities.Add(new ProjectEntity { - ProjectEntityId = 1 + ProjectEntityId = storageId }); ringtoetsEntities.ProjectEntities.Add(new ProjectEntity { - ProjectEntityId = 1 + ProjectEntityId = storageId }); // Call TestDelegate test = () => project.Update(new UpdateConversionCollector(), ringtoetsEntities); // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'ProjectEntity' met id '{0}' is niet gevonden.", storageId); + var expectedInnerMessage = "Sequence contains more than one matching element"; + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + Assert.IsInstanceOf(exception.InnerException); + Assert.AreEqual(expectedInnerMessage, exception.InnerException.Message); + mocks.VerifyAll(); } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilModelUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilModelUpdateExtensionsTest.cs (.../StochasticSoilModelUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilModelUpdateExtensionsTest.cs (.../StochasticSoilModelUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -36,7 +36,13 @@ var soilModel = new TestStochasticSoilModel(); // Call - TestDelegate test = () => soilModel.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilModel.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; @@ -50,13 +56,54 @@ var soilModel = new TestStochasticSoilModel(); // Call - TestDelegate test = () => soilModel.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilModel.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'StochasticSoilModelEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] + public void Update_ContextWithNoStochasticSoilModelWithId_EntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var soilModel = new StochasticSoilModel(-storageId, "name", "segment name") + { + StorageId = storageId, + }; + + ringtoetsEntities.StochasticSoilModelEntities.Add(new StochasticSoilModelEntity + { + StochasticSoilModelEntityId = 2, + Name = string.Empty, + SegmentName = string.Empty + }); + + // Call + TestDelegate test = () => soilModel.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'StochasticSoilModelEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] public void Update_ContextWithStochasticSoilModel_PropertiesUpdated() { // Setup Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilProfileUpdateExtensionsTest.cs =================================================================== diff -u -rb6432b2cbcb2db9bd326d9f006fb2d8b2528d263 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilProfileUpdateExtensionsTest.cs (.../StochasticSoilProfileUpdateExtensionsTest.cs) (revision b6432b2cbcb2db9bd326d9f006fb2d8b2528d263) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/StochasticSoilProfileUpdateExtensionsTest.cs (.../StochasticSoilProfileUpdateExtensionsTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -35,7 +35,13 @@ var soilProfile = new TestStochasticSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(null, new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(null, ringtoetsEntities); + } + }; // Assert var paramName = Assert.Throws(test).ParamName; @@ -49,21 +55,61 @@ var soilProfile = new TestStochasticSoilProfile(); // Call - TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), new RingtoetsEntities()); + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + } + }; // Assert - Assert.Throws(test); + var expectedMessage = String.Format("Het object 'StochasticSoilProfileEntity' met id '{0}' is niet gevonden.", 0); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); } [Test] - public void Update_WithNewSoilProfile_PropertiesUpdatedSoilProfileAdded() + public void Update_WithNoStochasticSoilProfileWithId_EntityNotFoundException() { // Setup MockRepository mocks = new MockRepository(); var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); mocks.ReplayAll(); + var storageId = 1; + var soilProfile = new StochasticSoilProfile(0.5, SoilProfileType.SoilProfile1D, -1) + { + StorageId = storageId, + SoilProfile = new TestPipingSoilProfile() + }; + + ringtoetsEntities.StochasticSoilProfileEntities.Add(new StochasticSoilProfileEntity + { + StochasticSoilProfileEntityId = 2, + }); + + // Call + TestDelegate test = () => soilProfile.Update(new UpdateConversionCollector(), ringtoetsEntities); + + // Assert + var expectedMessage = String.Format("Het object 'StochasticSoilProfileEntity' met id '{0}' is niet gevonden.", storageId); + EntityNotFoundException exception = Assert.Throws(test); + Assert.AreEqual(expectedMessage, exception.Message); + + mocks.VerifyAll(); + } + + [Test] + public void Update_WithNewStochasticSoilProfile_PropertiesUpdatedSoilProfileAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + + mocks.ReplayAll(); + var newProbability = 0.5; var soilProfile = new StochasticSoilProfile(newProbability, SoilProfileType.SoilProfile1D, -1) { @@ -90,7 +136,7 @@ } [Test] - public void Update_WithUpdatedSoilProfile_InstanceReferenceNotChanged() + public void Update_WithUpdatedStochasticSoilProfile_InstanceReferenceNotChanged() { // Setup MockRepository mocks = new MockRepository(); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/UpdateConversionCollectorTest.cs (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -0,0 +1,336 @@ +using System.Linq; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.TestUtil; +using Application.Ringtoets.Storage.Update; +using NUnit.Framework; +using Rhino.Mocks; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class UpdateConversionCollectorTest + { + [Test] + public void Constructor_CreatesNewInstance() + { + // Call + var collector = new UpdateConversionCollector(); + + // Assert + Assert.IsInstanceOf(collector); + } + + [Test] + public void RemoveUntouched_ProjectEntityInUpdatedList_ProjectEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var projectEntity = new ProjectEntity(); + ringtoetsEntities.ProjectEntities.Add(projectEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(projectEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.ProjectEntities.Count()); + } + + [Test] + public void RemoveUntouched_ProjectEntityNotInUpdatedList_ProjectEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.ProjectEntities.Add(new ProjectEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.ProjectEntities.Count()); + } + + [Test] + public void RemoveUntouched_AssessmentSectionEntityInUpdatedList_AssessmentSectionEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var assessmentSectionEntity = new AssessmentSectionEntity(); + ringtoetsEntities.AssessmentSectionEntities.Add(assessmentSectionEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(assessmentSectionEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.AssessmentSectionEntities.Count()); + } + + [Test] + public void RemoveUntouched_AssessmentSectionEntityNotInUpdatedList_AssessmentSectionEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.AssessmentSectionEntities.Add(new AssessmentSectionEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.AssessmentSectionEntities.Count()); + } + + [Test] + public void RemoveUntouched_FailureMechanismEntityInUpdatedList_FailureMechanismEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var failureMechanismEntity = new FailureMechanismEntity(); + ringtoetsEntities.FailureMechanismEntities.Add(failureMechanismEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(failureMechanismEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.FailureMechanismEntities.Count()); + } + + [Test] + public void RemoveUntouched_FailureMechanismEntityNotInUpdatedList_FailureMechanismEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.FailureMechanismEntities.Count()); + } + + [Test] + public void RemoveUntouched_HydraulicLocationEntityInUpdatedList_HydraulicLocationEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var hydraulicLocationEntity = new HydraulicLocationEntity(); + ringtoetsEntities.HydraulicLocationEntities.Add(hydraulicLocationEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(hydraulicLocationEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.HydraulicLocationEntities.Count()); + } + + [Test] + public void RemoveUntouched_HydraulicLocationEntityNotInUpdatedList_HydraulicLocationEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.HydraulicLocationEntities.Add(new HydraulicLocationEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.HydraulicLocationEntities.Count()); + } + + [Test] + public void RemoveUntouched_StochasticSoilModelEntityInUpdatedList_StochasticSoilModelEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var stochasticSoilModelEntity = new StochasticSoilModelEntity(); + ringtoetsEntities.StochasticSoilModelEntities.Add(stochasticSoilModelEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(stochasticSoilModelEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.StochasticSoilModelEntities.Count()); + } + + [Test] + public void RemoveUntouched_StochasticSoilModelEntityNotInUpdatedList_StochasticSoilModelEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.StochasticSoilModelEntities.Add(new StochasticSoilModelEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.StochasticSoilModelEntities.Count()); + } + + [Test] + public void RemoveUntouched_StochasticSoilProfileEntityInUpdatedList_StochasticSoilProfileEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var stochasticSoilProfileEntity = new StochasticSoilProfileEntity(); + ringtoetsEntities.StochasticSoilProfileEntities.Add(stochasticSoilProfileEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(stochasticSoilProfileEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.StochasticSoilProfileEntities.Count()); + } + + [Test] + public void RemoveUntouched_StochasticSoilProfileEntityNotInUpdatedList_StochasticSoilProfileEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.StochasticSoilProfileEntities.Add(new StochasticSoilProfileEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.StochasticSoilProfileEntities.Count()); + } + + [Test] + public void RemoveUntouched_SoilProfileEntityInUpdatedList_SoilProfileEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var soilProfileEntity = new SoilProfileEntity(); + ringtoetsEntities.SoilProfileEntities.Add(soilProfileEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(soilProfileEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.SoilProfileEntities.Count()); + } + + [Test] + public void RemoveUntouched_SoilProfileEntityNotInUpdatedList_SoilProfileEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.SoilProfileEntities.Add(new SoilProfileEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.SoilProfileEntities.Count()); + } + + [Test] + public void RemoveUntouched_SoilLayerEntityInUpdatedList_SoilLayerEntityNotRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + + var soilLayerEntity = new SoilLayerEntity(); + ringtoetsEntities.SoilLayerEntities.Add(soilLayerEntity); + + var collector = new UpdateConversionCollector(); + collector.Update(soilLayerEntity); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(1, ringtoetsEntities.SoilLayerEntities.Count()); + } + + [Test] + public void RemoveUntouched_SoilLayerEntityNotInUpdatedList_SoilLayerEntityRemoved() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.Create(mocks); + mocks.ReplayAll(); + ringtoetsEntities.SoilLayerEntities.Add(new SoilLayerEntity()); + + var collector = new UpdateConversionCollector(); + + // Call + collector.RemoveUntouched(ringtoetsEntities); + + // Assert + Assert.AreEqual(0, ringtoetsEntities.SoilLayerEntities.Count()); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs (.../SqLiteDatabaseHelperTest.cs) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/SqLiteDatabaseHelperTest.cs (.../SqLiteDatabaseHelperTest.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -146,15 +146,20 @@ MockRepository mockRepository = new MockRepository(); var projectMock = mockRepository.StrictMock(); - using (new FileDisposeHelper(validPath)) + FileDisposeHelper fileDisposeHelper = new FileDisposeHelper(validPath); + try { // Call TestDelegate test = () => SqLiteDatabaseHelper.CreateValidRingtoetsDatabase(validPath, projectMock); // Assert Assert.DoesNotThrow(test); Assert.IsTrue(File.Exists(validPath)); + } + finally + { CallGarbageCollector(); + fileDisposeHelper.Dispose(); } } Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs =================================================================== diff -u -r4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision 4e65fa5d8abdf1c0a9238492cdbcd7d2b3fa2d0f) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/SqLiteDatabaseHelper.cs (.../SqLiteDatabaseHelper.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -20,8 +20,10 @@ // All rights reserved. using System; +using System.Data.Entity.Core.EntityClient; using System.Data.SQLite; using Core.Common.Base.Data; +using Core.Common.Base.Properties; using NUnit.Framework; namespace Application.Ringtoets.Storage.TestUtil @@ -97,5 +99,14 @@ "CREATE TABLE VersionEntity (VersionId INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," + " FromVersion VARCHAR (16), ToVersion VARCHAR (16),Timestamp NUMERIC); "; } + + /// + /// Returns a corrupt databaseschema that will pass validation. + /// + /// The corrupt databaseschema that will pass validation. + public static string GetCompleteSchema() + { + return Properties.Resources.DatabaseStructure; + } } } \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs =================================================================== diff -u -r4e14ed090d09a220a790b3562ceb4232dab1cce6 -rbc9552772d4e6a6bd786dfcaef808da1964e8c53 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs (.../TestDbSet.cs) (revision 4e14ed090d09a220a790b3562ceb4232dab1cce6) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/TestDbSet.cs (.../TestDbSet.cs) (revision bc9552772d4e6a6bd786dfcaef808da1964e8c53) @@ -74,7 +74,8 @@ public override IEnumerable RemoveRange(IEnumerable entities) { - foreach (var e in entities) + var list = entities.ToList(); + foreach (var e in list) { collection.Remove(e); }