Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj
===================================================================
diff -u -r985570095b487598c6c2ae93b92e2bce65bf7e90 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -54,15 +54,17 @@
Properties\GlobalAssembly.cs
+
RingtoetsEntities.tt
+
+
-
RingtoetsEntities.tt
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/AssessmentSectionEntityConverter.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/AssessmentSectionEntityConverter.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/AssessmentSectionEntityConverter.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,78 @@
+using System;
+using System.Data.Entity;
+using System.Linq;
+using Application.Ringtoets.Storage.DbContext;
+using Ringtoets.Integration.Data;
+using Ringtoets.Integration.Data.Contribution;
+
+namespace Application.Ringtoets.Storage.Converters
+{
+ internal enum AssessmentSectionTypes
+ {
+ DikeAssessment = 1,
+ DuneAssessmentSection = 2
+ }
+
+ internal class AssessmentSectionEntityConverter
+ {
+ private readonly long projectEntityId;
+
+ public AssessmentSectionEntityConverter(long projectId)
+ {
+ projectEntityId = projectId;
+ }
+
+ public DikeAssessmentSection DikeAssessmentSection(IDbSet dbSet, long storageId)
+ {
+ var assessmentSectionEntity = GetAssessmentSectionEntity(dbSet, AssessmentSectionTypes.DikeAssessment, storageId);
+ if (assessmentSectionEntity == null)
+ {
+ return null;
+ }
+
+ return DikeAssessmentSectionEntityToAssessmentSection(assessmentSectionEntity);
+ }
+
+ public DuneAssessmentSection DuneAssessmentSection(IDbSet dbSet, long storageId)
+ {
+ var a = GetAssessmentSectionEntity(dbSet, AssessmentSectionTypes.DuneAssessmentSection, storageId);
+ throw new NotImplementedException();
+ }
+
+ private AssessmentSectionEntity GetAssessmentSectionEntity(IDbSet dbSet, AssessmentSectionTypes type, long storageId)
+ {
+ return dbSet.SingleOrDefault(db => db.AssessmentSectionEntityId == storageId && db.ProjectEntityId == projectEntityId && db.Type == (int)type);
+ }
+
+ private void DikeAssessmentSectionToAssessmentSectionEntity(DikeAssessmentSection dikeAssessmentSection, AssessmentSectionEntity assessmentSectionEntity)
+ {
+ if (dikeAssessmentSection == null || assessmentSectionEntity == null)
+ {
+ throw new ArgumentNullException();
+ }
+ assessmentSectionEntity.ProjectEntityId = projectEntityId;
+ assessmentSectionEntity.AssessmentSectionEntityId = dikeAssessmentSection.StorageId;
+ assessmentSectionEntity.Name = dikeAssessmentSection.Name;
+ }
+
+ private DikeAssessmentSection DikeAssessmentSectionEntityToAssessmentSection(AssessmentSectionEntity assessmentSectionEntity)
+ {
+ if (assessmentSectionEntity == null)
+ {
+ throw new ArgumentNullException();
+ }
+ var dikeAssessmentSection = new DikeAssessmentSection
+ {
+ StorageId = assessmentSectionEntity.AssessmentSectionEntityId,
+ Name = assessmentSectionEntity.Name
+ };
+
+ if (assessmentSectionEntity.Norm != null)
+ {
+ dikeAssessmentSection.FailureMechanismContribution.Norm = assessmentSectionEntity.Norm.Value;
+ }
+
+ return dikeAssessmentSection;
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/IEntityConverter.cs
===================================================================
diff -u -r6946691cf40fe32509dcaaa5266600b165954319 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/IEntityConverter.cs (.../IEntityConverter.cs) (revision 6946691cf40fe32509dcaaa5266600b165954319)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/IEntityConverter.cs (.../IEntityConverter.cs) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -1,5 +1,8 @@
namespace Application.Ringtoets.Storage.Converters
{
+ ///
+ /// Interface for entity converters.
+ ///
public interface IEntityConverter
{
///
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs
===================================================================
diff -u -r85053cd7be8aa42587cc2b0e25d6b98b5a5c2893 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs (.../ProjectEntityConverter.cs) (revision 85053cd7be8aa42587cc2b0e25d6b98b5a5c2893)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converters/ProjectEntityConverter.cs (.../ProjectEntityConverter.cs) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -1,104 +1,60 @@
using System;
-using System.Data.Entity;
-using System.Linq;
using Application.Ringtoets.Storage.DbContext;
-using Application.Ringtoets.Storage.Exceptions;
using Core.Common.Base.Data;
namespace Application.Ringtoets.Storage.Converters
{
///
- /// Converter for to and to .
+ /// Converter for to
+ /// and to .
///
- public static class ProjectEntityConverter
+ public class ProjectEntityConverter : IEntityConverter
{
///
- /// Gets a new , based on the found in the database.
+ /// Converts to .
///
- /// Database set of .
- /// A new or null when not found.
- /// Thrown when is null.
- public static Project GetProject(IDbSet dbSet)
+ /// The to convert.
+ /// A new instance of , based on the properties of .
+ /// Thrown when is null.
+ public Project ConvertEntityToModel(ProjectEntity entity)
{
- var entry = dbSet.FirstOrDefault();
- return entry == null ? null : ProjectEntityToProject(entry);
- }
-
- ///
- /// Updates the , based upon the , in the .
- ///
- /// Execute .SaveChanges() afterwards to update the storage.
- /// Database set of .
- /// to be saved in the database.
- /// Thrown when or is null.
- /// When multiple instances are found that refer to .
- /// When no entities was found that refer to .
- public static void UpdateProjectEntity(IDbSet dbSet, Project project)
- {
- if (project == null)
+ if (entity == null)
{
- throw new ArgumentNullException();
+ throw new ArgumentNullException("entity");
}
- var entry = dbSet.SingleOrDefault(db => db.ProjectEntityId == project.StorageId);
- if (entry == null)
+ var project = new Project
{
- throw new EntityNotFoundException();
- }
- ProjectToProjectEntity(project, entry);
+ StorageId = entity.ProjectEntityId,
+ Name = entity.Name,
+ Description = entity.Description
+ };
+
+ return project;
}
///
- /// Insert the , based upon the , in the .
+ /// Converts to .
///
- /// Execute .SaveChanges() afterwards to update the storage.
- /// Database set of .
- /// to be saved in the database.
- /// New instance of .
- /// Thrown when or is null.
- public static ProjectEntity InsertProjectEntity(IDbSet dbSet, Project project)
+ /// The to convert.
+ /// A reference to the to be saved.
+ /// Thrown when:
+ /// - is null
+ /// - is null.
+ ///
+ public void ConvertModelToEntity(Project modelObject, ProjectEntity entity)
{
- if (dbSet == null)
+ if (modelObject == null)
{
- throw new ArgumentNullException();
+ throw new ArgumentNullException("modelObject");
}
- var projectEntity = new ProjectEntity();
- ProjectToProjectEntity(project, projectEntity);
- dbSet.Add(projectEntity);
- return projectEntity;
- }
-
- ///
- /// Converts to .
- ///
- /// The to convert.
- /// A reference to the to be saved.
- /// Thrown when or is null.
- private static void ProjectToProjectEntity(Project project, ProjectEntity projectEntity)
- {
- if (project == null || projectEntity == null)
+ if (entity == null)
{
- throw new ArgumentNullException();
+ throw new ArgumentNullException("entity");
}
- projectEntity.Name = project.Name;
- projectEntity.Description = project.Description;
- projectEntity.LastUpdated = new DateTime().Ticks;
+ entity.ProjectEntityId = modelObject.StorageId;
+ entity.Name = modelObject.Name;
+ entity.Description = modelObject.Description;
+ entity.LastUpdated = new DateTime().Ticks;
}
-
- ///
- /// Converts to a new instance of .
- ///
- /// to convert.
- /// A new instance of , based on the properties of .
- private static Project ProjectEntityToProject(ProjectEntity projectEntity)
- {
- var project = new Project
- {
- StorageId = projectEntity.ProjectEntityId,
- Name = projectEntity.Name,
- Description = projectEntity.Description
- };
-
- return project;
- }
}
}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/IEntityPersistor.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/IEntityPersistor.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/IEntityPersistor.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,26 @@
+using System.Data.Entity;
+
+namespace Application.Ringtoets.Storage.Persistors
+{
+ ///
+ /// Interface for entity persistors.
+ ///
+ public interface IEntityPersistor where T1 : class where T2 : class
+ {
+ ///
+ /// Insert the , based upon the , in the sequence.
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// to be inserted in the storage.
+ /// New instance of .
+ T2 AddEntity(T1 model);
+
+ ///
+ /// Updates the , based upon the , in the sequence.
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// to be saved in the storage.
+ /// The .
+ T2 UpdateEntity(T1 model);
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ProjectEntityPersistor.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ProjectEntityPersistor.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/Persistors/ProjectEntityPersistor.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,86 @@
+using System;
+using System.Data.Entity;
+using System.Linq;
+using Application.Ringtoets.Storage.Converters;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Core.Common.Base.Data;
+
+namespace Application.Ringtoets.Storage.Persistors
+{
+ ///
+ /// Persistor for .
+ ///
+ public class ProjectEntityPersistor : IEntityPersistor
+ {
+ private readonly ProjectEntityConverter converter;
+ private readonly IDbSet dbSet;
+
+ ///
+ /// Instanciate a new ProjectEntityPersistor.
+ ///
+ /// Sequence from the storage.
+ /// Thrown when is null.
+ public ProjectEntityPersistor(IDbSet projectEntitiesSet)
+ {
+ if (projectEntitiesSet == null)
+ {
+ throw new ArgumentNullException("projectEntitiesSet");
+ }
+ dbSet = projectEntitiesSet;
+ converter = new ProjectEntityConverter();
+ }
+
+ ///
+ /// Gets the only as from the sequence.
+ ///
+ /// A new , loaded from the sequence, or null when not found.
+ /// Thrown when there are more than one elements in the sequence.
+ public Project GetEntityAsModel()
+ {
+ var entry = dbSet.SingleOrDefault();
+ return entry == null ? null : converter.ConvertEntityToModel(entry);
+ }
+
+ ///
+ /// Updates the , based upon the , in the sequence.
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// to be saved in the storage.
+ /// The .
+ /// Thrown when is null.
+ /// Thrown when is not found.
+ public ProjectEntity UpdateEntity(Project project)
+ {
+ if (project == null)
+ {
+ throw new ArgumentNullException("project", "Cannot update databaseSet when no project is set.");
+ }
+ var entry = dbSet.SingleOrDefault(db => db.ProjectEntityId == project.StorageId);
+ if (entry == null)
+ {
+ throw new EntityNotFoundException();
+ }
+ converter.ConvertModelToEntity(project, entry);
+ return entry;
+ }
+
+ ///
+ /// Insert the , based upon the , in the sequence.
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// to be inserted in the sequence.
+ /// New instance of .
+ /// Thrown when is null.
+ public ProjectEntity AddEntity(Project project)
+ {
+ if (project == null)
+ {
+ throw new ArgumentNullException("project");
+ }
+ var projectEntity = new ProjectEntity();
+ converter.ConvertModelToEntity(project, projectEntity);
+ return dbSet.Add(projectEntity);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntityStorage.cs
===================================================================
diff -u
--- Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntityStorage.cs (revision 0)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntityStorage.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,120 @@
+using System;
+using System.Data.Entity;
+using System.Linq;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Core.Common.Base.Data;
+
+namespace Application.Ringtoets.Storage.Persistors
+{
+ ///
+ /// Converter for to and to .
+ ///
+ public static class ProjectEntityStorage
+ {
+ ///
+ /// Gets the ProjectEntity from the .
+ ///
+ /// Database set of .
+ /// A new , loaded from the database, or null when not found.
+ public static ProjectEntity GetProjectEntity(IDbSet dbSet)
+ {
+ return dbSet.FirstOrDefault();
+ }
+
+ ///
+ /// Gets a new , based on the found in the database.
+ ///
+ /// Database set of .
+ /// A new or null when not found.
+ /// Thrown when is null.
+ public static Project GetProject(IDbSet dbSet)
+ {
+ var entry = GetProjectEntity(dbSet);
+ return entry == null ? null : ProjectEntityToProject(entry);
+ }
+
+ ///
+ /// Updates the , based upon the , in the .
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// Database set of .
+ /// to be saved in the database.
+ /// The .
+ /// Thrown when or is null.
+ /// When multiple instances are found that refer to .
+ /// When no entities was found that refer to .
+ public static ProjectEntity UpdateProjectEntity(IDbSet dbSet, Project project)
+ {
+ if (project == null)
+ {
+ throw new ArgumentNullException("project", "Cannot update databaseSet when no project is set.");
+ }
+ var entry = dbSet.SingleOrDefault(db => db.ProjectEntityId == project.StorageId);
+ if (entry == null)
+ {
+ throw new EntityNotFoundException();
+ }
+ ProjectToProjectEntity(project, entry);
+ return entry;
+ }
+
+ ///
+ /// Insert the , based upon the , in the .
+ ///
+ /// Execute .SaveChanges() afterwards to update the storage.
+ /// Database set of .
+ /// to be saved in the database.
+ /// New instance of .
+ /// Thrown when or is null.
+ public static ProjectEntity InsertProjectEntity(IDbSet dbSet, Project project)
+ {
+ if (dbSet == null)
+ {
+ throw new ArgumentNullException("dbSet", "Cannot update databaseSet when no databaseSet is set.");
+ }
+ var projectEntity = new ProjectEntity();
+ ProjectToProjectEntity(project, projectEntity);
+ dbSet.Add(projectEntity);
+ return projectEntity;
+ }
+
+ ///
+ /// Converts to a new instance of .
+ ///
+ /// to convert.
+ /// A new instance of , based on the properties of .
+ public static Project ProjectEntityToProject(ProjectEntity projectEntity)
+ {
+ var project = new Project
+ {
+ StorageId = projectEntity.ProjectEntityId,
+ Name = projectEntity.Name,
+ Description = projectEntity.Description
+ };
+
+ return project;
+ }
+
+ ///
+ /// Converts to .
+ ///
+ /// The to convert.
+ /// A reference to the to be saved.
+ /// Thrown when or is null.
+ private static void ProjectToProjectEntity(Project project, ProjectEntity projectEntity)
+ {
+ if (project == null)
+ {
+ throw new ArgumentNullException("project", "Cannot convert Project to ProjectEntity when project is not supplied");
+ }
+ if (projectEntity == null)
+ {
+ throw new ArgumentNullException("projectEntity", "Cannot convert Project to ProjectEntity when ProjectEntity is not supplied");
+ }
+ projectEntity.Name = project.Name;
+ projectEntity.Description = project.Description;
+ projectEntity.LastUpdated = new DateTime().Ticks;
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs
===================================================================
diff -u -r985570095b487598c6c2ae93b92e2bce65bf7e90 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
+++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -2,9 +2,9 @@
using System.Data;
using System.Data.Entity;
using System.IO;
-using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
using Application.Ringtoets.Storage.Exceptions;
+using Application.Ringtoets.Storage.Persistors;
using Application.Ringtoets.Storage.Properties;
using Core.Common.Base.Data;
using Core.Common.Base.Storage;
@@ -43,11 +43,12 @@
SetConnectionToNewFile(databaseFilePath);
using (var dbContext = new RingtoetsEntities(connectionString))
{
- var entity = ProjectEntityConverter.InsertProjectEntity(dbContext.ProjectEntities, project);
+ var projectEntityPersistor = new ProjectEntityPersistor(dbContext.ProjectEntities);
+ var projectEntity = projectEntityPersistor.AddEntity(project);
try
{
var changes = dbContext.SaveChanges();
- project.StorageId = entity.ProjectEntityId;
+ project.StorageId = projectEntity.ProjectEntityId;
return changes;
}
catch (DataException exception)
@@ -87,9 +88,10 @@
}
using (var dbContext = new RingtoetsEntities(connectionString))
{
+ var projectEntityPersistor = new ProjectEntityPersistor(dbContext.ProjectEntities);
try
{
- ProjectEntityConverter.UpdateProjectEntity(dbContext.ProjectEntities, project);
+ projectEntityPersistor.UpdateEntity(project);
return dbContext.SaveChanges();
}
catch (EntityNotFoundException)
@@ -120,7 +122,8 @@
SetConnectionToFile(databaseFilePath);
using (var dbContext = new RingtoetsEntities(connectionString))
{
- return ProjectEntityConverter.GetProject(dbContext.ProjectEntities);
+ var projectEntityPersistor = new ProjectEntityPersistor(dbContext.ProjectEntities);
+ return projectEntityPersistor.GetEntityAsModel();
}
}
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj
===================================================================
diff -u -rf165ef32cdd4f7be892d0433578709272ee7a70e -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision f165ef32cdd4f7be892d0433578709272ee7a70e)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -51,6 +51,7 @@
..\..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll
True
+
..\..\..\..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net40\System.Data.SQLite.dll
@@ -62,11 +63,12 @@
-
-
+
+
+
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs
===================================================================
diff -u -r85053cd7be8aa42587cc2b0e25d6b98b5a5c2893 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision 85053cd7be8aa42587cc2b0e25d6b98b5a5c2893)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -1,227 +1,115 @@
using System;
-using System.Collections.Generic;
-using System.Data.Entity;
-using System.Linq;
using Application.Ringtoets.Storage.Converters;
using Application.Ringtoets.Storage.DbContext;
-using Application.Ringtoets.Storage.Exceptions;
using Core.Common.Base.Data;
using NUnit.Framework;
-using Rhino.Mocks;
namespace Application.Ringtoets.Storage.Test.Converter
{
[TestFixture]
public class ProjectEntityConverterTest
{
[Test]
- public void GetProject_DbSetWithValidProjectEntity_ReturnsTheProjectEntityAsProject()
+ public void DefaultConstructor_Always_NewProjectEntityConverter()
{
- // Setup
- const long projectId = 1;
- var projectEntity = new ProjectEntity()
- {
- ProjectEntityId = projectId,
- Name = "test",
- Description = "description"
- };
-
- var projectEntities = GetDbSetTest(new List
- {
- projectEntity
- });
-
// Call
- Project project = ProjectEntityConverter.GetProject(projectEntities);
+ ProjectEntityConverter converter = new ProjectEntityConverter();
// Assert
- Assert.IsInstanceOf(project);
- Assert.AreEqual(project.StorageId, projectId);
- Assert.AreEqual(project.Name, projectEntity.Name);
- Assert.AreEqual(project.Description, projectEntity.Description);
- Assert.IsEmpty(project.Items);
+ Assert.IsInstanceOf>(converter);
}
[Test]
- public void GetProject_NullDataSet_ThrowsArgumentNullException()
+ public void ConvertEntityToModel_NullEntity_ThrowsArgumentNullException()
{
- // Setup
- TestDelegate test = () => ProjectEntityConverter.GetProject(null);
+ // SetUp
+ ProjectEntityConverter converter = new ProjectEntityConverter();
- // Assert
- Assert.Throws(test);
- }
+ // Call
+ TestDelegate test = () => converter.ConvertEntityToModel(null);
- [Test]
- public void UpdateProjectEntity_NullDataValidProject_ThrowsArgumentNullException()
- {
- // Setup
- var project = new Project();
- TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(null, project);
-
// Assert
Assert.Throws(test);
}
[Test]
- public void UpdateProjectEntity_ValidDataSetNullProject_ThrowsArgumentNullException()
+ public void ConvertEntityToModel_ValidProjectEntity_ReturnsTheProjectEntityAsProject()
{
- // Setup
- var projectEntities = GetDbSetTest(new List());
- TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, null);
-
- // Assert
- Assert.Throws(test);
- }
-
- [Test]
- public void UpdateProjectEntity_DuplicateProjectEntityId_ThrowsInvalidOperationException()
- {
- // Setup
- const long projectId = 1;
- var project = new Project
+ // SetUp
+ const long storageId = 1234L;
+ const string name = "test";
+ const string description = "Description";
+ ProjectEntity projectEntity = new ProjectEntity()
{
- StorageId = projectId
+ ProjectEntityId = storageId,
+ Name = name,
+ Description = description
};
- var projectEnties = new List
- {
- new ProjectEntity()
- {
- ProjectEntityId = projectId
- },
- new ProjectEntity()
- {
- ProjectEntityId = projectId
- }
- };
- var projectEntities = GetDbSetTest(projectEnties);
+ ProjectEntityConverter converter = new ProjectEntityConverter();
// Call
- TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+ Project project = converter.ConvertEntityToModel(projectEntity);
// Assert
- Assert.Throws(test);
+ Assert.AreNotEqual(projectEntity, project);
+ Assert.AreEqual(storageId, project.StorageId);
+ Assert.AreEqual(name, project.Name);
+ Assert.AreEqual(description, project.Description);
}
[Test]
- public void UpdateProjectEntity_UnknownProjectEntityId_ThrowsEntityNotFoundException()
+ public void ConvertModelToEntity_NullEntity_ThrowsArgumentNullException()
{
- // Setup
- const long projectId = 1;
- const long projectEntityId = 2;
- var project = new Project
- {
- StorageId = projectId
- };
- var projectEnties = new List
- {
- new ProjectEntity()
- {
- ProjectEntityId = projectEntityId
- }
- };
- var projectEntities = GetDbSetTest(projectEnties);
+ // SetUp
+ ProjectEntityConverter converter = new ProjectEntityConverter();
+ Project project = new Project();
// Call
- TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+ TestDelegate test = () => converter.ConvertModelToEntity(project, null);
// Assert
- Assert.Throws(test);
+ Assert.Throws(test);
}
[Test]
- public void UpdateProjectEntity_WithSingleProject_ProjectEntriesEqualToProject()
+ public void ConvertModelToEntity_NullModel_ThrowsArgumentNullException()
{
- // Setup
- const long projectId = 1;
- var project = new Project
- {
- StorageId = projectId,
- Name = "test",
- Description = "description"
- };
- var projectEnties = new List
- {
- new ProjectEntity()
- {
- ProjectEntityId = projectId
- }
- };
- IDbSet projectEntities = GetDbSetTest(projectEnties);
+ // SetUp
+ ProjectEntityConverter converter = new ProjectEntityConverter();
+ ProjectEntity projectEntity = new ProjectEntity();
// Call
- ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+ TestDelegate test = () => converter.ConvertModelToEntity(null, projectEntity);
// Assert
- Assert.IsInstanceOf(project);
- List projectEntitiesArray = projectEntities.ToList();
- Assert.AreEqual(projectEntitiesArray.Count, 1);
-
- ProjectEntity projectEntity = projectEntitiesArray[0];
-
- Assert.AreEqual(project.StorageId, projectEntity.ProjectEntityId);
- Assert.AreEqual(project.Name, projectEntity.Name);
- Assert.AreEqual(project.Description, projectEntity.Description);
- Assert.AreNotEqual(project, projectEntity);
- }
-
- [Test]
- public void InsertProjectEntity_NullDataValidProject_ThrowsArgumentNullException()
- {
- // Setup
- var project = new Project();
- TestDelegate test = () => ProjectEntityConverter.InsertProjectEntity(null, project);
-
- // Assert
Assert.Throws(test);
}
[Test]
- public void InsertProjectEntity_ValidDataSetNullProject_ThrowsArgumentNullException()
+ public void ConvertModelToEntity_ValidProject_UpdatesTheProjectAsProjectEntity()
{
- // Setup
- var projectEntities = GetDbSetTest(new List());
- TestDelegate test = () => ProjectEntityConverter.InsertProjectEntity(projectEntities, null);
-
- // Assert
- Assert.Throws(test);
- }
-
- [Test]
- public void InsertProjectEntity_ValidProject_ReturnsTheProjectAsProjectEntity()
- {
- // Setup
- const long projectId = 1;
- var project = new Project
+ // SetUp
+ const long storageId = 1234L;
+ const string name = "test";
+ const string description = "Description";
+ Project project = new Project
{
- StorageId = projectId,
- Name = "test",
- Description = "description"
+ StorageId = storageId,
+ Name = name,
+ Description = description
};
- var projectEnties = new List();
- IDbSet projectEntities = GetDbSetTest(projectEnties);
+ ProjectEntity projectEntity = new ProjectEntity();
+ ProjectEntityConverter converter = new ProjectEntityConverter();
// Call
- ProjectEntity projectEntity = ProjectEntityConverter.InsertProjectEntity(projectEntities, project);
+ converter.ConvertModelToEntity(project, projectEntity);
// Assert
- Assert.AreNotEqual(project.StorageId, projectEntity.ProjectEntityId); // Insert will decide the id of the entity
- Assert.AreEqual(project.Name, projectEntity.Name);
- Assert.AreEqual(project.Description, projectEntity.Description);
- Assert.AreNotEqual(project, projectEntity);
+ Assert.AreNotEqual(projectEntity, project);
+ Assert.AreEqual(storageId, projectEntity.ProjectEntityId);
+ Assert.AreEqual(name, projectEntity.Name);
+ Assert.AreEqual(description, projectEntity.Description);
+ Assert.IsNotNull(projectEntity.LastUpdated);
}
-
- private static IDbSet GetDbSetTest(IList data) where T : class
- {
- var queryable = data.AsQueryable();
-
- var dbSet = MockRepository.GenerateMock, IQueryable>();
-
- dbSet.Stub(m => m.Provider).Return(queryable.Provider);
- dbSet.Stub(m => m.Expression).Return(queryable.Expression);
- dbSet.Stub(m => m.ElementType).Return(queryable.ElementType);
- dbSet.Stub(m => m.GetEnumerator()).Return(queryable.GetEnumerator());
- return dbSet;
- }
}
}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityStorageTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityStorageTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityStorageTest.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,227 @@
+using System;
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Linq;
+using Application.Ringtoets.Storage.Converters;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Application.Ringtoets.Storage.Test.Converter
+{
+ [TestFixture]
+ public class ProjectEntityStorageTest
+ {
+ [Test]
+ public void GetProject_DbSetWithValidProjectEntity_ReturnsTheProjectEntityAsProject()
+ {
+ // Setup
+ const long projectId = 1;
+ var projectEntity = new ProjectEntity()
+ {
+ ProjectEntityId = projectId,
+ Name = "test",
+ Description = "description"
+ };
+
+ var projectEntities = GetDbSetTest(new List
+ {
+ projectEntity
+ });
+
+ // Call
+ Project project = ProjectEntityConverter.GetProject(projectEntities);
+
+ // Assert
+ Assert.IsInstanceOf(project);
+ Assert.AreEqual(project.StorageId, projectId);
+ Assert.AreEqual(project.Name, projectEntity.Name);
+ Assert.AreEqual(project.Description, projectEntity.Description);
+ Assert.IsEmpty(project.Items);
+ }
+
+ [Test]
+ public void GetProject_NullDataSet_ThrowsArgumentNullException()
+ {
+ // Setup
+ TestDelegate test = () => ProjectEntityConverter.GetProject(null);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateProjectEntity_NullDataValidProject_ThrowsArgumentNullException()
+ {
+ // Setup
+ var project = new Project();
+ TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(null, project);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateProjectEntity_ValidDataSetNullProject_ThrowsArgumentNullException()
+ {
+ // Setup
+ var projectEntities = GetDbSetTest(new List());
+ TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, null);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateProjectEntity_DuplicateProjectEntityId_ThrowsInvalidOperationException()
+ {
+ // Setup
+ const long projectId = 1;
+ var project = new Project
+ {
+ StorageId = projectId
+ };
+ var projectEnties = new List
+ {
+ new ProjectEntity()
+ {
+ ProjectEntityId = projectId
+ },
+ new ProjectEntity()
+ {
+ ProjectEntityId = projectId
+ }
+ };
+ var projectEntities = GetDbSetTest(projectEnties);
+
+ // Call
+ TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateProjectEntity_UnknownProjectEntityId_ThrowsEntityNotFoundException()
+ {
+ // Setup
+ const long projectId = 1;
+ const long projectEntityId = 2;
+ var project = new Project
+ {
+ StorageId = projectId
+ };
+ var projectEnties = new List
+ {
+ new ProjectEntity()
+ {
+ ProjectEntityId = projectEntityId
+ }
+ };
+ var projectEntities = GetDbSetTest(projectEnties);
+
+ // Call
+ TestDelegate test = () => ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateProjectEntity_WithSingleProject_ProjectEntriesEqualToProject()
+ {
+ // Setup
+ const long projectId = 1;
+ var project = new Project
+ {
+ StorageId = projectId,
+ Name = "test",
+ Description = "description"
+ };
+ var projectEnties = new List
+ {
+ new ProjectEntity()
+ {
+ ProjectEntityId = projectId
+ }
+ };
+ IDbSet projectEntities = GetDbSetTest(projectEnties);
+
+ // Call
+ ProjectEntityConverter.UpdateProjectEntity(projectEntities, project);
+
+ // Assert
+ Assert.IsInstanceOf(project);
+ List projectEntitiesArray = projectEntities.ToList();
+ Assert.AreEqual(projectEntitiesArray.Count, 1);
+
+ ProjectEntity projectEntity = projectEntitiesArray[0];
+
+ Assert.AreEqual(project.StorageId, projectEntity.ProjectEntityId);
+ Assert.AreEqual(project.Name, projectEntity.Name);
+ Assert.AreEqual(project.Description, projectEntity.Description);
+ Assert.AreNotEqual(project, projectEntity);
+ }
+
+ [Test]
+ public void InsertProjectEntity_NullDataValidProject_ThrowsArgumentNullException()
+ {
+ // Setup
+ var project = new Project();
+ TestDelegate test = () => ProjectEntityConverter.InsertProjectEntity(null, project);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void InsertProjectEntity_ValidDataSetNullProject_ThrowsArgumentNullException()
+ {
+ // Setup
+ var projectEntities = GetDbSetTest(new List());
+ TestDelegate test = () => ProjectEntityConverter.InsertProjectEntity(projectEntities, null);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void InsertProjectEntity_ValidProject_ReturnsTheProjectAsProjectEntity()
+ {
+ // Setup
+ const long projectId = 1;
+ var project = new Project
+ {
+ StorageId = projectId,
+ Name = "test",
+ Description = "description"
+ };
+ var projectEnties = new List();
+ IDbSet projectEntities = GetDbSetTest(projectEnties);
+
+ // Call
+ ProjectEntity projectEntity = ProjectEntityConverter.InsertProjectEntity(projectEntities, project);
+
+ // Assert
+ Assert.AreNotEqual(project.StorageId, projectEntity.ProjectEntityId); // Insert will decide the id of the entity
+ Assert.AreEqual(project.Name, projectEntity.Name);
+ Assert.AreEqual(project.Description, projectEntity.Description);
+ Assert.AreNotEqual(project, projectEntity);
+ }
+
+ private static IDbSet GetDbSetTest(IList data) where T : class
+ {
+ var queryable = data.AsQueryable();
+
+ var dbSet = MockRepository.GenerateMock, IQueryable>();
+
+ dbSet.Stub(m => m.Provider).Return(queryable.Provider);
+ dbSet.Stub(m => m.Expression).Return(queryable.Expression);
+ dbSet.Stub(m => m.ElementType).Return(queryable.ElementType);
+ dbSet.Stub(m => m.GetEnumerator()).Return(queryable.GetEnumerator());
+ return dbSet;
+ }
+ }
+}
\ No newline at end of file
Fisheye: Tag 6a639792869015e8e135a6bd40bdad1893ac2970 refers to a dead (removed) revision in file `Application/Ringtoets/test/Application.Ringtoets.Storage.Test/DbContext/DbSet.cs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/DbContext/DbTestSet.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/DbContext/DbTestSet.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/DbContext/DbTestSet.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,22 @@
+using System.Collections.Generic;
+using System.Data.Entity;
+using System.Linq;
+using Rhino.Mocks;
+
+namespace Application.Ringtoets.Storage.Test.DbContext
+{
+ public static class DbTestSet
+ {
+ public static IDbSet GetDbTestSet(IList data) where T : class
+ {
+ var queryable = data.AsQueryable();
+ var dbSet = MockRepository.GenerateMock, IQueryable>();
+
+ dbSet.Stub(m => m.Provider).Return(queryable.Provider);
+ dbSet.Stub(m => m.Expression).Return(queryable.Expression);
+ dbSet.Stub(m => m.ElementType).Return(queryable.ElementType);
+ dbSet.Stub(m => m.GetEnumerator()).Return(queryable.GetEnumerator());
+ return dbSet;
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/ProjectEntityPersistorTest.cs
===================================================================
diff -u
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/ProjectEntityPersistorTest.cs (revision 0)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Persistors/ProjectEntityPersistorTest.cs (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -0,0 +1,214 @@
+using System;
+using System.Collections.Generic;
+using Application.Ringtoets.Storage.DbContext;
+using Application.Ringtoets.Storage.Exceptions;
+using Application.Ringtoets.Storage.Persistors;
+using Application.Ringtoets.Storage.Test.DbContext;
+using Core.Common.Base.Data;
+using NUnit.Framework;
+using Rhino.Mocks;
+
+namespace Application.Ringtoets.Storage.Test.Persistors
+{
+ [TestFixture]
+ public class ProjectEntityPersistorTest
+ {
+ private MockRepository mocksRepository;
+
+ [SetUp]
+ public void SetUp()
+ {
+ mocksRepository = new MockRepository();
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void Constructor_NullDataSet_ThrowsArgumentNullException()
+ {
+ // Call
+ ProjectEntityPersistor p = new ProjectEntityPersistor(null);
+ }
+
+ [Test]
+ public void Constructor_EmptyDataset_NewInstance()
+ {
+ // Call
+ var dbset = DbTestSet.GetDbTestSet(new List());
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Assert
+ Assert.IsInstanceOf>(persistor);
+ }
+
+ [Test]
+ public void GetEntityAsModel_EmptyDataset_DoesNotThrowException()
+ {
+ // Setup
+ var dbset = DbTestSet.GetDbTestSet(new List());
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ TestDelegate test = () => persistor.GetEntityAsModel();
+
+ // Assert
+ Assert.DoesNotThrow(test);
+ }
+
+ [Test]
+ public void GetEntityAsModel_SingleEntityInDataSet_ProjectEntityFromDataSet()
+ {
+ // Setup
+ const long storageId = 1234L;
+ const string name = "test";
+ const string description = "description";
+ var dbset = DbTestSet.GetDbTestSet(new List
+ {
+ new ProjectEntity
+ {
+ ProjectEntityId = storageId,
+ Name = name,
+ Description = description
+ }
+ });
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ Project model = persistor.GetEntityAsModel();
+
+ // Assert
+ Assert.IsInstanceOf(model);
+ Assert.AreEqual(storageId, model.StorageId);
+ Assert.AreEqual(name, model.Name);
+ Assert.AreEqual(description, model.Description);
+ }
+
+ [Test]
+ public void GetEntityAsModel_MultipleEntitiesInDataSet_ThrowsInvalidOperationException()
+ {
+ // Setup
+ var dbset = DbTestSet.GetDbTestSet(new List
+ {
+ new ProjectEntity
+ {
+ ProjectEntityId = 1
+ },
+ new ProjectEntity
+ {
+ ProjectEntityId = 2
+ }
+ });
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ TestDelegate test = () => persistor.GetEntityAsModel();
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void AddEntity_NullData_ThrowsArgumentNullException()
+ {
+ // Setup
+ var dbset = DbTestSet.GetDbTestSet(new List());
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ TestDelegate test = () => persistor.AddEntity(null);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void AddEntity_ValidProject_UpdatedDataSet()
+ {
+ // Setup
+ var dbSetMethodAddWasHit = 0;
+ const long storageId = 1234L;
+ const string name = "test";
+ const string description = "description";
+ var dbset = DbTestSet.GetDbTestSet(new List());
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+ ProjectEntity projectEntity = new ProjectEntity();
+ Project project = new Project
+ {
+ StorageId = storageId,
+ Name = name,
+ Description = description
+ };
+ dbset.Stub(m => m.Add(projectEntity)).IgnoreArguments().Return(projectEntity)
+ .WhenCalled(invocation => dbSetMethodAddWasHit++);
+
+ // Call
+ persistor.AddEntity(project);
+
+ // Assert
+ Assert.AreEqual(1, dbSetMethodAddWasHit);
+ }
+
+ [Test]
+ public void UpdateEntity_NullData_ThrowsArgumentNullException()
+ {
+ // Setup
+ var dbset = DbTestSet.GetDbTestSet(new List());
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ TestDelegate test = () => persistor.UpdateEntity(null);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateEntity_UnknownProject_ThrowsException()
+ {
+ // Setup
+ Project project = new Project
+ {
+ StorageId = 1
+ };
+ var dbset = DbTestSet.GetDbTestSet(new List
+ {
+ new ProjectEntity
+ {
+ ProjectEntityId = 2
+ }
+ });
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ TestDelegate test = () => persistor.UpdateEntity(project);
+
+ // Assert
+ Assert.Throws(test);
+ }
+
+ [Test]
+ public void UpdateEntity_ValidProject_ReturnsTheProjectAsProjectEntity()
+ {
+ // Setup
+ const long storageId = 1234L;
+ Project project = new Project
+ {
+ StorageId = storageId
+ };
+ var dbset = DbTestSet.GetDbTestSet(new List
+ {
+ new ProjectEntity
+ {
+ ProjectEntityId = storageId
+ }
+ });
+ ProjectEntityPersistor persistor = new ProjectEntityPersistor(dbset);
+
+ // Call
+ ProjectEntity entity = persistor.UpdateEntity(project);
+
+ // Assert
+ Assert.IsInstanceOf(entity);
+ Assert.AreEqual(project.StorageId, entity.ProjectEntityId);
+ }
+ }
+}
\ No newline at end of file
Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs
===================================================================
diff -u -r985570095b487598c6c2ae93b92e2bce65bf7e90 -r6a639792869015e8e135a6bd40bdad1893ac2970
--- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 985570095b487598c6c2ae93b92e2bce65bf7e90)
+++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSqLiteTest.cs (.../StorageSqLiteTest.cs) (revision 6a639792869015e8e135a6bd40bdad1893ac2970)
@@ -163,7 +163,7 @@
}
[Test]
- public void SaveProjectAs_ValidPathToLockedFile_ThrowsException()
+ public void SaveProjectAs_ValidPathToLockedFile_ThrowsUpdateStorageException()
{
// Setup
var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd");
@@ -222,7 +222,7 @@
}
[Test]
- public void SaveProject_InvalidProject_ThrowsCouldNotConnectException()
+ public void SaveProject_InvalidProject_ThrowsStorageExceptionAndCouldNotConnectException()
{
// Setup
var tempFile = Path.Combine(testDataPath, "tempProjectFile.rtd");