Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -ra20794746c723f3d02434953861bd3dc57800b73 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision a20794746c723f3d02434953861bd3dc57800b73) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -110,7 +110,7 @@ - + @@ -375,7 +375,7 @@ - + Fisheye: Tag e2e6d944af7b0cea6c9c34e77bd0644149526c37 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Create/ProjectCreateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Create/RingtoetsProjectCreateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Create/RingtoetsProjectCreateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Create/RingtoetsProjectCreateExtensions.cs (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -0,0 +1,66 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.DbContext; +using Ringtoets.Integration.Data; + +namespace Application.Ringtoets.Storage.Create +{ + /// + /// Extension methods for related to creating database entities. + /// + internal static class RingtoetsProjectCreateExtensions + { + /// + /// Creates a based on the information of the . + /// + /// The project to create a database entity for. + /// The object keeping track of create operations. + /// A new . + /// Thrown when is null. + internal static ProjectEntity Create(this RingtoetsProject project, PersistenceRegistry registry) + { + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + var entity = new ProjectEntity + { + Description = project.Description + }; + + AddEntitiesForAssessmentSections(project, entity, registry); + + registry.Register(entity, project); + return entity; + } + + private static void AddEntitiesForAssessmentSections(RingtoetsProject project, ProjectEntity entity, PersistenceRegistry registry) + { + foreach (var result in project.AssessmentSections) + { + entity.AssessmentSectionEntities.Add(result.Create(registry)); + } + } + } +} \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProjectEntityReadExtensions.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProjectEntityReadExtensions.cs (.../ProjectEntityReadExtensions.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Read/ProjectEntityReadExtensions.cs (.../ProjectEntityReadExtensions.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -52,7 +52,7 @@ foreach (var assessmentSectionEntity in entity.AssessmentSectionEntities) { - project.Items.Add(assessmentSectionEntity.Read(collector)); + project.AssessmentSections.Add(assessmentSectionEntity.Read(collector)); } return project; Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs =================================================================== diff -u -r3456261423844a9f804b352472ac08feb22485ac -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 3456261423844a9f804b352472ac08feb22485ac) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -71,7 +71,8 @@ /// public void SaveProjectAs(string databaseFilePath, IProject project) { - if (!(project is RingtoetsProject)) + var ringtoetsProject = project as RingtoetsProject; + if (ringtoetsProject == null) { throw new ArgumentNullException("project"); } @@ -82,7 +83,7 @@ writer.Perform(() => { SetConnectionToNewFile(databaseFilePath); - SaveProjectInDatabase(databaseFilePath, (RingtoetsProject) project); + SaveProjectInDatabase(databaseFilePath, ringtoetsProject); }); } catch (IOException e) @@ -111,7 +112,8 @@ /// public void SaveProject(string databaseFilePath, IProject project) { - if (!(project is RingtoetsProject)) + var ringtoetsProject = project as RingtoetsProject; + if (ringtoetsProject == null) { throw new ArgumentNullException("project"); } @@ -122,10 +124,10 @@ } catch { - SaveProjectAs(databaseFilePath, project); + SaveProjectAs(databaseFilePath, ringtoetsProject); } - UpdateProjectInDatabase(databaseFilePath, (RingtoetsProject) project); + UpdateProjectInDatabase(databaseFilePath, ringtoetsProject); } /// @@ -188,7 +190,8 @@ return true; } - if (!(project is RingtoetsProject)) + var ringtoetsProject = project as RingtoetsProject; + if (ringtoetsProject == null) { throw new ArgumentNullException("project"); } @@ -197,7 +200,6 @@ { try { - var ringtoetsProject = (RingtoetsProject) project; var persistenceRegistry = new PersistenceRegistry(); ringtoetsProject.Update(persistenceRegistry, dbContext); persistenceRegistry.RemoveUntouched(dbContext); Fisheye: Tag e2e6d944af7b0cea6c9c34e77bd0644149526c37 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/Update/ProjectUpdateExtensions.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Update/RingtoetsProjectUpdateExtensions.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Update/RingtoetsProjectUpdateExtensions.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Update/RingtoetsProjectUpdateExtensions.cs (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -0,0 +1,81 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +using Application.Ringtoets.Storage.Exceptions; +using Ringtoets.Integration.Data; + +namespace Application.Ringtoets.Storage.Update +{ + /// + /// Extension methods for related to updating a . + /// + internal static class RingtoetsProjectUpdateExtensions + { + /// + /// Updates a in the database based on the information of the + /// . + /// + /// The project to update the database entity for. + /// The object keeping track of update operations. + /// The context to obtain the existing entity from. + /// Thrown when either: + /// + /// is null + /// is null + /// + /// When + /// does not have a corresponding entity in the database. + internal static void Update(this RingtoetsProject project, PersistenceRegistry registry, IRingtoetsEntities context) + { + if (context == null) + { + throw new ArgumentNullException("context"); + } + if (registry == null) + { + throw new ArgumentNullException("registry"); + } + + ProjectEntity entity = project.GetCorrespondingEntity( + context.ProjectEntities, + o => o.ProjectEntityId); + + entity.Description = project.Description; + + foreach (var result in project.AssessmentSections) + { + if (result.IsNew()) + { + entity.AssessmentSectionEntities.Add(result.Create(registry)); + } + else + { + result.Update(registry, context); + } + } + + registry.Register(entity, project); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -r3456261423844a9f804b352472ac08feb22485ac -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 3456261423844a9f804b352472ac08feb22485ac) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -140,7 +140,7 @@ - + @@ -248,7 +248,7 @@ - + Fisheye: Tag e2e6d944af7b0cea6c9c34e77bd0644149526c37 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/ProjectCreateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/RingtoetsProjectCreateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/RingtoetsProjectCreateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Create/RingtoetsProjectCreateExtensionsTest.cs (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -0,0 +1,86 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; +using Application.Ringtoets.Storage.Create; +using NUnit.Framework; +using Ringtoets.Common.Data.AssessmentSection; +using Ringtoets.Integration.Data; + +namespace Application.Ringtoets.Storage.Test.Create +{ + [TestFixture] + public class RingtoetsProjectCreateExtensionsTest + { + [Test] + public void Create_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var project = new RingtoetsProject(); + + // Call + TestDelegate test = () => project.Create(null); + + // Assert + var parameterName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", parameterName); + } + + [Test] + public void Create_WithCollector_ReturnsProjectEntityWithDescription() + { + // Setup + var testdescription = "testDescription"; + var project = new RingtoetsProject + { + Description = testdescription + }; + var registry = new PersistenceRegistry(); + + // Call + var entity = project.Create(registry); + + // Assert + Assert.NotNull(entity); + Assert.AreEqual(testdescription, entity.Description); + } + + [Test] + public void Create_WithAssessmentSections_AddsSectionsToEntity() + { + // Setup + var project = new RingtoetsProject + { + AssessmentSections = + { + new AssessmentSection(AssessmentSectionComposition.Dike) + } + }; + var registry = new PersistenceRegistry(); + + // Call + var entity = project.Create(registry); + + // Assert + Assert.AreEqual(1, entity.AssessmentSectionEntities.Count); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs =================================================================== diff -u -rbc7cd9cbf90d04580e6b3542c56edc590867c43a -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision bc7cd9cbf90d04580e6b3542c56edc590867c43a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/IntegrationTests/StorageSqLiteIntegrationTest.cs (.../StorageSqLiteIntegrationTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -76,8 +76,8 @@ try { storage.SaveProjectAs(tempFile, fullProject); - firstProject = storage.LoadProject(tempRingtoetsFile) as RingtoetsProject; - secondProject = storage.LoadProject(tempFile) as RingtoetsProject; + firstProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); + secondProject = (RingtoetsProject) storage.LoadProject(tempFile); } catch (Exception exception) { @@ -109,7 +109,7 @@ Assert.DoesNotThrow(test, String.Format("Precondition: failed to save project to file '{0}'.", tempRingtoetsFile)); // Call - RingtoetsProject loadedProject = storage.LoadProject(tempRingtoetsFile) as RingtoetsProject; + RingtoetsProject loadedProject = (RingtoetsProject) storage.LoadProject(tempRingtoetsFile); // Assert AssertProjectsAreEqual(fullProject, loadedProject); @@ -177,7 +177,7 @@ Assert.AreEqual("Project", gui.Project.Name); Assert.IsEmpty(gui.Project.Description); Assert.IsInstanceOf(gui.Project); - CollectionAssert.IsEmpty(((RingtoetsProject) gui.Project).Items); + CollectionAssert.IsEmpty(((RingtoetsProject) gui.Project).AssessmentSections); } } @@ -207,7 +207,7 @@ Assert.AreEqual("Project", gui.Project.Name); Assert.IsEmpty(gui.Project.Description); Assert.IsInstanceOf(gui.Project); - CollectionAssert.IsEmpty(((RingtoetsProject) gui.Project).Items); + CollectionAssert.IsEmpty(((RingtoetsProject) gui.Project).AssessmentSections); } } @@ -217,8 +217,8 @@ Assert.NotNull(actualProject); Assert.AreNotSame(expectedProject, actualProject); - AssessmentSection[] expectedProjectAssessmentSections = expectedProject.Items.ToArray(); - AssessmentSection[] actualProjectAssessmentSections = actualProject.Items.ToArray(); + AssessmentSection[] expectedProjectAssessmentSections = expectedProject.AssessmentSections.ToArray(); + AssessmentSection[] actualProjectAssessmentSections = actualProject.AssessmentSections.ToArray(); Assert.AreEqual(expectedProjectAssessmentSections.Length, actualProjectAssessmentSections.Length); for (var i = 0; i < expectedProjectAssessmentSections.Length; i++) { Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProjectEntityReadExtensionsTest.cs =================================================================== diff -u -rea14c73fc9ac706d48a5af7125bb570a5d07dd28 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProjectEntityReadExtensionsTest.cs (.../ProjectEntityReadExtensionsTest.cs) (revision ea14c73fc9ac706d48a5af7125bb570a5d07dd28) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Read/ProjectEntityReadExtensionsTest.cs (.../ProjectEntityReadExtensionsTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -89,7 +89,7 @@ var project = entity.Read(new ReadConversionCollector()); // Assert - Assert.AreEqual(2, project.Items.Count); + Assert.AreEqual(2, project.AssessmentSections.Count); } } } \ No newline at end of file Fisheye: Tag e2e6d944af7b0cea6c9c34e77bd0644149526c37 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/ProjectUpdateExtensionsTest.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/RingtoetsProjectUpdateExtensionsTest.cs =================================================================== diff -u --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/RingtoetsProjectUpdateExtensionsTest.cs (revision 0) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Update/RingtoetsProjectUpdateExtensionsTest.cs (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -0,0 +1,386 @@ +// Copyright (C) Stichting Deltares 2016. All rights reserved. +// +// This file is part of Ringtoets. +// +// Ringtoets is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// All names, logos, and references to "Deltares" are registered trademarks of +// Stichting Deltares and remain full property of Stichting Deltares at all times. +// All rights reserved. + +using System; + +using Application.Ringtoets.Storage.Create; +using Application.Ringtoets.Storage.DbContext; +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.Common.Data.AssessmentSection; +using Ringtoets.Integration.Data; + +namespace Application.Ringtoets.Storage.Test.Update +{ + [TestFixture] + public class RingtoetsProjectUpdateExtensionsTest + { + [Test] + public void Update_WithoutContext_ThrowsArgumentNullException() + { + // Setup + var project = new RingtoetsProject(); + + // Call + TestDelegate test = () => project.Update(new PersistenceRegistry(), null); + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("context", paramName); + } + + [Test] + public void Update_WithoutPersistenceRegistry_ThrowsArgumentNullException() + { + // Setup + var project = new RingtoetsProject(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + project.Update(null, ringtoetsEntities); + } + }; + + // Assert + var paramName = Assert.Throws(test).ParamName; + Assert.AreEqual("registry", paramName); + } + + [Test] + public void Update_ContextWithNoProject_ThrowsEntityNotFoundException() + { + // Setup + var project = new RingtoetsProject(); + + // Call + TestDelegate test = () => + { + using (var ringtoetsEntities = new RingtoetsEntities()) + { + project.Update(new PersistenceRegistry(), ringtoetsEntities); + } + }; + + // Assert + Assert.Throws(test); + } + + [Test] + public void Update_ContextWithNoProjectWithId_ThrowsEntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var project = new RingtoetsProject + { + StorageId = storageId + }; + + ringtoetsEntities.ProjectEntities.Add(new ProjectEntity + { + ProjectEntityId = 2 + }); + + // Call + TestDelegate test = () => project.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + 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(); + } + + [Test] + public void Update_ContextWithMultipleProjectsWithId_ThrowsEntityNotFoundException() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var storageId = 1; + var project = new RingtoetsProject + { + StorageId = storageId + }; + + ringtoetsEntities.ProjectEntities.Add(new ProjectEntity + { + ProjectEntityId = storageId + }); + ringtoetsEntities.ProjectEntities.Add(new ProjectEntity + { + ProjectEntityId = storageId + }); + + // Call + TestDelegate test = () => project.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + 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(); + } + + [Test] + public void Update_ContextWithProject_DescriptionUpdated() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var newDescription = "newDescription"; + var project = new RingtoetsProject + { + StorageId = 1, + Description = newDescription + }; + + var entity = new ProjectEntity + { + ProjectEntityId = 1, + Description = string.Empty + }; + ringtoetsEntities.ProjectEntities.Add(entity); + + // Call + project.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(newDescription, entity.Description); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ProjectWithNewSection_SectionAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + + mocks.ReplayAll(); + + var project = new RingtoetsProject + { + StorageId = 1, + AssessmentSections = + { + new AssessmentSection(AssessmentSectionComposition.Dike) + } + }; + + var entity = new ProjectEntity + { + ProjectEntityId = 1 + }; + ringtoetsEntities.ProjectEntities.Add(entity); + + // Call + project.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + Assert.AreEqual(1, entity.AssessmentSectionEntities.Count); + + mocks.VerifyAll(); + } + + [Test] + public void Update_ProjectWithExistingSection_NoSectionsAdded() + { + // Setup + MockRepository mocks = new MockRepository(); + var ringtoetsEntities = RingtoetsEntitiesHelper.CreateStub(mocks); + mocks.ReplayAll(); + + var section = new AssessmentSection(AssessmentSectionComposition.Dike) + { + StorageId = 1, + PipingFailureMechanism = + { + StorageId = 1, + CalculationsGroup = + { + StorageId = 23 + }, + PipingProbabilityAssessmentInput = + { + StorageId = 2 + } + }, + GrassCoverErosionInwards = + { + StorageId = 1, + CalculationsGroup = + { + StorageId = 854563 + }, + GeneralInput = + { + StorageId = 3 + } + }, + MacrostabilityInwards = + { + StorageId = 1 + }, + HeightStructures = + { + StorageId = 1 + }, + ClosingStructure = + { + StorageId = 1 + }, + StrengthStabilityPointConstruction = + { + StorageId = 1 + }, + StabilityStoneCover = + { + StorageId = 1 + }, + WaveImpactAsphaltCover = + { + StorageId = 1 + }, + GrassCoverErosionOutwards = + { + StorageId = 1 + }, + GrassCoverSlipOffOutwards = + { + StorageId = 1 + }, + PipingStructure = + { + StorageId = 1 + }, + DuneErosion = + { + StorageId = 1 + }, + GrassCoverSlipOffInwards = + { + StorageId = 1 + }, + MacrostabilityOutwards = + { + StorageId = 1 + }, + Microstability = + { + StorageId = 1 + }, + StrengthStabilityLengthwiseConstruction = + { + StorageId = 1 + }, + TechnicalInnovation = + { + StorageId = 1 + }, + WaterPressureAsphaltCover = + { + StorageId = 1 + } + }; + var project = new RingtoetsProject + { + StorageId = 1, + AssessmentSections = + { + section + } + }; + + var assessmentSectionEntity = new AssessmentSectionEntity + { + AssessmentSectionEntityId = section.StorageId + }; + var projectEntity = new ProjectEntity + { + ProjectEntityId = project.StorageId, + AssessmentSectionEntities = + { + assessmentSectionEntity + } + }; + + ringtoetsEntities.ProjectEntities.Add(projectEntity); + ringtoetsEntities.AssessmentSectionEntities.Add(assessmentSectionEntity); + ringtoetsEntities.CalculationGroupEntities.Add(new CalculationGroupEntity + { + CalculationGroupEntityId = section.PipingFailureMechanism.CalculationsGroup.StorageId + }); + ringtoetsEntities.CalculationGroupEntities.Add(new CalculationGroupEntity + { + CalculationGroupEntityId = section.GrassCoverErosionInwards.CalculationsGroup.StorageId + }); + ringtoetsEntities.FailureMechanismEntities.Add(new FailureMechanismEntity + { + FailureMechanismEntityId = 1 + }); + ringtoetsEntities.PipingFailureMechanismMetaEntities.Add(new PipingFailureMechanismMetaEntity + { + PipingFailureMechanismMetaEntityId = section.PipingFailureMechanism.PipingProbabilityAssessmentInput.StorageId + }); + ringtoetsEntities.GrassCoverErosionInwardsFailureMechanismMetaEntities.Add(new GrassCoverErosionInwardsFailureMechanismMetaEntity + { + GrassCoverErosionInwardsFailureMechanismMetaEntityId = section.GrassCoverErosionInwards.GeneralInput.StorageId + }); + + // Call + project.Update(new PersistenceRegistry(), ringtoetsEntities); + + // Assert + CollectionAssert.AreEqual(new[] + { + assessmentSectionEntity + }, projectEntity.AssessmentSectionEntities); + + mocks.VerifyAll(); + } + } +} \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs (.../RingtoetsProjectTestHelperTest.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil.Test/RingtoetsProjectTestHelperTest.cs (.../RingtoetsProjectTestHelperTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -56,7 +56,7 @@ Assert.AreEqual(expectedProjectName, project.Name); Assert.AreEqual(expectedDescription, project.Description); - AssessmentSection assessmentSection = project.Items.FirstOrDefault(); + AssessmentSection assessmentSection = project.AssessmentSections.FirstOrDefault(); Assert.NotNull(assessmentSection); Assert.AreEqual(expectedAssessmentSectionName, assessmentSection.Name); Index: Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs =================================================================== diff -u -rbc7cd9cbf90d04580e6b3542c56edc590867c43a -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision bc7cd9cbf90d04580e6b3542c56edc590867c43a) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.TestUtil/RingtoetsProjectTestHelper.cs (.../RingtoetsProjectTestHelper.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -104,7 +104,7 @@ { Name = "tempProjectFile", Description = "description", - Items = + AssessmentSections = { assessmentSection } Index: Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Demo/Ringtoets/src/Demo.Ringtoets/Commands/AddNewDemoAssessmentSectionCommand.cs (.../AddNewDemoAssessmentSectionCommand.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -53,7 +53,7 @@ public void Execute(params object[] arguments) { var project = (RingtoetsProject) projectOwner.Project; - project.Items.Add(CreateNewDemoAssessmentSection()); + project.AssessmentSections.Add(CreateNewDemoAssessmentSection()); project.NotifyObservers(); } Index: Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Demo/Ringtoets/test/Demo.Ringtoets.Test/Commands/AddNewDemoAssessmentSectionCommandTest.cs (.../AddNewDemoAssessmentSectionCommandTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -66,8 +66,8 @@ command.Execute(); // Assert - Assert.AreEqual(1, project.Items.Count); - var demoAssessmentSection = project.Items[0]; + Assert.AreEqual(1, project.AssessmentSections.Count); + var demoAssessmentSection = project.AssessmentSections[0]; Assert.AreEqual("Demo traject", demoAssessmentSection.Name); Assert.IsNotEmpty(demoAssessmentSection.HydraulicBoundaryDatabase.FilePath); Index: Ringtoets/Integration/src/Ringtoets.Integration.Data/RingtoetsProject.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Ringtoets/Integration/src/Ringtoets.Integration.Data/RingtoetsProject.cs (.../RingtoetsProject.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Ringtoets/Integration/src/Ringtoets.Integration.Data/RingtoetsProject.cs (.../RingtoetsProject.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -43,13 +43,13 @@ Name = name; Description = ""; - Items = new List(); + AssessmentSections = new List(); } /// - /// Gets or sets the items of the . + /// Gets or sets the assessmentSections of the . /// - public IList Items { get; private set; } + public IList AssessmentSections { get; private set; } /// /// Gets or sets the name of the . @@ -76,7 +76,7 @@ return string.Equals(Name, otherProject.Name) && string.Equals(Description, otherProject.Description) && StorageId == otherProject.StorageId && - Items.SequenceEqual(otherProject.Items); + AssessmentSections.SequenceEqual(otherProject.AssessmentSections); } public override bool Equals(object obj) Index: Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs =================================================================== diff -u -r0b6cce0bd86288273634f7ead3817885a7c20fd0 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision 0b6cce0bd86288273634f7ead3817885a7c20fd0) +++ Ringtoets/Integration/src/Ringtoets.Integration.Plugin/RingtoetsPlugin.cs (.../RingtoetsPlugin.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -263,8 +263,8 @@ throw new ArgumentNullException("assessmentSection"); } - assessmentSection.Name = GetUniqueForAssessmentSectionName(ringtoetsProject.Items, assessmentSection.Name); - ringtoetsProject.Items.Add(assessmentSection); + assessmentSection.Name = GetUniqueForAssessmentSectionName(ringtoetsProject.AssessmentSections, assessmentSection.Name); + ringtoetsProject.AssessmentSections.Add(assessmentSection); ringtoetsProject.NotifyObservers(); if (Gui != null) @@ -390,7 +390,7 @@ CreateData = owner => { var project = (RingtoetsProject) owner; - assessmentSection.Name = GetUniqueForAssessmentSectionName(project.Items, assessmentSection.Name); + assessmentSection.Name = GetUniqueForAssessmentSectionName(project.AssessmentSections, assessmentSection.Name); return assessmentSection; } } @@ -407,7 +407,7 @@ var project = dataObject as RingtoetsProject; if (project != null) { - foreach (var item in project.Items) + foreach (var item in project.AssessmentSections) { yield return item; } @@ -535,7 +535,7 @@ { Text = project => project.Name, Image = project => GuiResources.ProjectIcon, - ChildNodeObjects = nodeData => nodeData.Items.Cast().ToArray(), + ChildNodeObjects = nodeData => nodeData.AssessmentSections.Cast().ToArray(), ContextMenuStrip = (nodeData, parentData, treeViewControl) => { var addItem = new StrictContextMenuItem( @@ -622,7 +622,7 @@ { return; } - var sectionsWithDatabase = ringtoetsProject.Items.Where(i => i.HydraulicBoundaryDatabase != null); + var sectionsWithDatabase = ringtoetsProject.AssessmentSections.Where(i => i.HydraulicBoundaryDatabase != null); foreach (AssessmentSection section in sectionsWithDatabase) { string selectedFile = section.HydraulicBoundaryDatabase.FilePath; @@ -818,7 +818,7 @@ { var parentProject = (RingtoetsProject) parentNodeData; var assessmentSection = (AssessmentSection) nodeData; - parentProject.Items.Remove(assessmentSection); + parentProject.AssessmentSections.Remove(assessmentSection); parentProject.NotifyObservers(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/RingtoetsProjectTest.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/RingtoetsProjectTest.cs (.../RingtoetsProjectTest.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Ringtoets/Integration/test/Ringtoets.Integration.Data.Test/RingtoetsProjectTest.cs (.../RingtoetsProjectTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -40,7 +40,7 @@ Assert.IsInstanceOf(project); Assert.AreEqual("Project", project.Name); Assert.AreEqual("", project.Description); - CollectionAssert.IsEmpty(project.Items); + CollectionAssert.IsEmpty(project.AssessmentSections); } [Test] @@ -56,7 +56,7 @@ Assert.IsInstanceOf(project); Assert.AreEqual(someName, project.Name); Assert.AreEqual("", project.Description); - CollectionAssert.IsEmpty(project.Items); + CollectionAssert.IsEmpty(project.AssessmentSections); } [Test] @@ -152,12 +152,12 @@ } [Test] - public void Equals_ProjectItemsChanged_ReturnsFalse() + public void Equals_ProjectAssessmentSectionsChanged_ReturnsFalse() { // Setup RingtoetsProject newProject = new RingtoetsProject(); RingtoetsProject changedProject = new RingtoetsProject(); - newProject.Items.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); + newProject.AssessmentSections.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); // Call bool result = newProject.Equals(changedProject); @@ -175,8 +175,14 @@ const long storageId = 1234; const string name = "Some name"; const string desctiption = "Some desctiption"; - var project = new RingtoetsProject(name) { StorageId = storageId, Description = desctiption }; - var otherProject = new RingtoetsProject(name) { StorageId = storageId, Description = desctiption }; + var project = new RingtoetsProject(name) + { + StorageId = storageId, Description = desctiption + }; + var otherProject = new RingtoetsProject(name) + { + StorageId = storageId, Description = desctiption + }; // Call var result = project.GetHashCode(); Index: Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs =================================================================== diff -u -r1eed3e3f652618c52a462edc502cfd4250772314 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision 1eed3e3f652618c52a462edc502cfd4250772314) +++ Ringtoets/Integration/test/Ringtoets.Integration.Forms.Test/TreeNodeInfos/AssessmentSectionTreeNodeInfoTest.cs (.../AssessmentSectionTreeNodeInfoTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -374,7 +374,7 @@ mocks.ReplayAll(); var project = new RingtoetsProject(); - project.Items.Add(assessmentSection); + project.AssessmentSections.Add(assessmentSection); project.Attach(observerMock); using (var plugin = new RingtoetsPlugin()) @@ -385,7 +385,7 @@ info.OnNodeRemoved(assessmentSection, project); // Assert - CollectionAssert.DoesNotContain(project.Items, assessmentSection); + CollectionAssert.DoesNotContain(project.AssessmentSections, assessmentSection); } mocks.VerifyAll(); } Index: Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs =================================================================== diff -u -r239ea628125c5ec4004a843abce2d269af93c431 -re2e6d944af7b0cea6c9c34e77bd0644149526c37 --- Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision 239ea628125c5ec4004a843abce2d269af93c431) +++ Ringtoets/Integration/test/Ringtoets.Integration.Plugin.Test/RingtoetsPluginTest.cs (.../RingtoetsPluginTest.cs) (revision e2e6d944af7b0cea6c9c34e77bd0644149526c37) @@ -136,7 +136,7 @@ FilePath = testDataPath } }; - project.Items.Add(section); + project.AssessmentSections.Add(section); // When Action action = () => { gui.Project = project; }; @@ -172,7 +172,7 @@ FilePath = notExistingFile } }; - project.Items.Add(section); + project.AssessmentSections.Add(section); plugin.Gui = gui; gui.Run(); @@ -416,17 +416,17 @@ { // Setup var project = new RingtoetsProject(); - project.Items.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); - project.Items.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); - project.Items.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); + project.AssessmentSections.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); + project.AssessmentSections.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); + project.AssessmentSections.Add(new AssessmentSection(AssessmentSectionComposition.Dike)); using (var plugin = new RingtoetsPlugin()) { // Call var childrenWithViewDefinitions = plugin.GetChildDataWithViewDefinitions(project); // Assert - var expectedResult = project.Items; + var expectedResult = project.AssessmentSections; CollectionAssert.AreEquivalent(expectedResult, childrenWithViewDefinitions); } } @@ -509,14 +509,14 @@ project.Attach(projectObserver); // Precondition - CollectionAssert.IsEmpty(project.Items); + CollectionAssert.IsEmpty(project.AssessmentSections); // Call plugin.SetAssessmentSectionToProject(project, assessmentSection); } // Assert - Assert.AreEqual(1, project.Items.Count); - CollectionAssert.Contains(project.Items, assessmentSection); + Assert.AreEqual(1, project.AssessmentSections.Count); + CollectionAssert.Contains(project.AssessmentSections, assessmentSection); mockRepository.VerifyAll(); } @@ -537,7 +537,7 @@ } // Assert - CollectionAssert.AllItemsAreUnique(project.Items.Select(section => section.Name)); + CollectionAssert.AllItemsAreUnique(project.AssessmentSections.Select(section => section.Name)); } [Test]