Index: Application/Ringtoets/src/Application.Ringtoets.Storage/App.config =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/App.config (.../App.config) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/App.config (.../App.config) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -19,6 +19,6 @@ - + \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Application.Ringtoets.Storage.csproj (.../Application.Ringtoets.Storage.csproj) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -41,7 +41,6 @@ True - ..\..\..\..\packages\System.Data.SQLite.Core.1.0.99.0\lib\net40\System.Data.SQLite.dll @@ -64,7 +63,7 @@ Properties\GlobalAssembly.cs - + RingtoetsDBContext.tt @@ -105,7 +104,7 @@ EntityModelCodeGenerator RingtoetsDBContext.Designer.cs - + Always Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Converter/ProjectEntityConverter.cs =================================================================== diff -u --- Application/Ringtoets/src/Application.Ringtoets.Storage/Converter/ProjectEntityConverter.cs (revision 0) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/Converter/ProjectEntityConverter.cs (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -0,0 +1,66 @@ +using System; +using System.Data.Entity; +using System.Linq; +using Core.Common.Base.Data; + +namespace Application.Ringtoets.Storage.Converter +{ + /// + /// Converter for ProjectEntity. + /// + public static class ProjectEntityConverter + { + /// + /// Gets a new , based on the found in the database. + /// + /// Database set of . + /// Unique identifier to find the . + /// A new or null when not found. + public static Project GetProject(IDbSet dbSet, long projectId) + { + var entry = dbSet.SingleOrDefault(db => db.ProjectEntityId == projectId); + return entry == null ? null : ProjectEntityToProject(entry); + } + + /// + /// Updates the , based upon the , in the database. + /// + /// Database set of . + /// to be saved in the database. + public static void UpdateProjectEntity(IDbSet dbSet, Project project) + { + var entry = dbSet.SingleOrDefault(db => db.ProjectEntityId == project.StorageId); + ProjectToProjectEntity(project, entry); + } + + /// + /// 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. + public static void ProjectToProjectEntity(Project project, ProjectEntity projectEntity) + { + projectEntity.Name = project.Name; + projectEntity.Description = project.Description; + projectEntity.LastUpdated = new DateTime().Ticks; + } + + } +} Index: Application/Ringtoets/src/Application.Ringtoets.Storage/IRingtoetsDBContext.cs =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/IRingtoetsDBContext.cs (.../IRingtoetsDBContext.cs) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/IRingtoetsDBContext.cs (.../IRingtoetsDBContext.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -1,9 +1,22 @@ using System.Data.Entity; +using System.Data.Entity.Core.Objects; namespace Application.Ringtoets.Storage { + /// + /// Interface that describes the properties and methods that must be implemented on classes that use a database context. + /// public interface IRingtoetsDbContext { - DbSet ProjectEntities { get; set; } + /// + /// of + /// + IDbSet ProjectEntities { get; set; } + + /// + /// + /// + /// The number of objects in an Added, Modified, or Deleted state when SaveChanges was called. + int SaveChanges(); } -} +} \ No newline at end of file Fisheye: Tag 0155f2f233aefc7951782b302e1398e02c00f298 refers to a dead (removed) revision in file `Application/Ringtoets/src/Application.Ringtoets.Storage/IStoreProject.cs'. Fisheye: No comparison available. Pass `N' to diff? Index: Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntity.cs =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntity.cs (.../ProjectEntity.cs) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/ProjectEntity.cs (.../ProjectEntity.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -17,6 +17,6 @@ public long ProjectEntityId { get; set; } public string Name { get; set; } public string Description { get; set; } - public Nullable LastUpdated { get; set; } + public long LastUpdated { get; set; } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Ringtoets.rt =================================================================== diff -u Binary files differ Index: Application/Ringtoets/src/Application.Ringtoets.Storage/Ringtoets.sqlite =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 Binary files differ Index: Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.cs =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.cs (.../RingtoetsDBContext.Context.cs) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.cs (.../RingtoetsDBContext.Context.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -26,6 +26,6 @@ throw new UnintentionalCodeFirstException(); } - public virtual DbSet ProjectEntities { get; set; } + public virtual IDbSet ProjectEntities { get; set; } } } Index: Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.tt =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.tt (.../RingtoetsDBContext.Context.tt) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.Context.tt (.../RingtoetsDBContext.Context.tt) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -308,7 +308,7 @@ { return string.Format( CultureInfo.InvariantCulture, - "{0} virtual DbSet<{1}> {2} {{ get; set; }}", + "{0} virtual IDbSet<{1}> {2} {{ get; set; }}", Accessibility.ForReadOnlyProperty(entitySet), _typeMapper.GetTypeName(entitySet.ElementType), _code.Escape(entitySet)); Index: Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx (.../RingtoetsDBContext.edmx) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx (.../RingtoetsDBContext.edmx) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -4,15 +4,15 @@ - + - + @@ -23,15 +23,15 @@ - + - + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx.diagram =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx.diagram (.../RingtoetsDBContext.edmx.diagram) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/RingtoetsDBContext.edmx.diagram (.../RingtoetsDBContext.edmx.diagram) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -5,7 +5,7 @@ - + Index: Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs =================================================================== diff -u -r7980edee4d818aa3759b179c8af269f4f1f23597 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 7980edee4d818aa3759b179c8af269f4f1f23597) +++ Application/Ringtoets/src/Application.Ringtoets.Storage/StorageSqLite.cs (.../StorageSqLite.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -1,25 +1,21 @@ -using System; -using System.Linq; +using Application.Ringtoets.Storage.Converter; using Core.Common.Base.Data; namespace Application.Ringtoets.Storage { - public class StorageSqLite : IStoreProject + public class StorageSqLite { + /// + /// Saves the at the default location. + /// + /// to save. + /// Returns the number of changes, see . public int SaveProject(Project project) { using (var dbContext = new RingtoetsEntities()) { - var entry = dbContext.ProjectEntities.SingleOrDefault(db => db.ProjectEntityId == project.StorageId); - if (entry == null) - { - return 0; - } + ProjectEntityConverter.UpdateProjectEntity(dbContext.ProjectEntities, project); - entry.Name = project.Name; - entry.Description = project.Description; - entry.LastUpdated = new DateTime().Ticks; - return dbContext.SaveChanges(); } } @@ -33,22 +29,8 @@ { using (var dbContext = new RingtoetsEntities()) { - var entry = dbContext.ProjectEntities.SingleOrDefault(db => db.ProjectEntityId == projectId); - if (entry == null) - { - return null; - } - - var project = new Project - { - StorageId = entry.ProjectEntityId, - Name = entry.Name, - Description = entry.Description - }; - - return project; + return ProjectEntityConverter.GetProject(dbContext.ProjectEntities, projectId); } } - } } \ No newline at end of file Index: Application/Ringtoets/src/Application.Ringtoets/app.config =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/src/Application.Ringtoets/app.config (.../app.config) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/src/Application.Ringtoets/app.config (.../app.config) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -120,6 +120,6 @@ - + \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/App.config =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/App.config (.../App.config) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/App.config (.../App.config) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -2,16 +2,23 @@ -
+
- - - - - + - + + + + + + + + + + \ No newline at end of file Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Application.Ringtoets.Storage.Test.csproj (.../Application.Ringtoets.Storage.Test.csproj) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -19,7 +19,7 @@ bin\Debug\ DEBUG;TRACE prompt - x86 + x86 4 @@ -35,7 +35,7 @@ true x86 MinimumRecommendedRules.ruleset - x86 + x86 pdbonly @@ -65,6 +65,10 @@ + + ..\..\..\..\packages\System.Data.SQLite.EF6.1.0.99.0\lib\net40\System.Data.SQLite.EF6.dll + True + @@ -75,13 +79,19 @@ {3bbfd65b-b277-4e50-ae6d-bd24c3434609} Core.Common.Base + + {F49BD8B2-332A-4C91-A196-8CCE0A2C7D98} + Core.Common.Utils + {50963f12-448c-41ba-a62c-cdb0ab8d21e0} Application.Ringtoets.Storage - + + Designer + Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSQLiteTest.cs =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSQLiteTest.cs (.../StorageSQLiteTest.cs) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/StorageSQLiteTest.cs (.../StorageSQLiteTest.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -1,8 +1,86 @@ -using NUnit.Framework; +using System.Collections.Generic; +using System.Data.Entity; +using System.Linq; +using Application.Ringtoets.Storage.Converter; +using Core.Common.Base.Data; +using NUnit.Framework; +using Rhino.Mocks; namespace Application.Ringtoets.Storage.Test { + [TestFixture] public class StorageSqLiteTest { + + [Test] + public void ProjectEntityMapping_ProjectEntity_Project() + { + // Setup + const long projectId = 1; + var projectEntity = new ProjectEntity() + { + ProjectEntityId = projectId, + Name = "test", + Description = "description" + }; + + var projectEntities = GetDbSetTest(new List { projectEntity }); + + // Call + var project = ProjectEntityConverter.GetProject(projectEntities, projectId); + + // Assert + Assert.IsInstanceOf(project); + Assert.AreEqual(project.StorageId, projectId); + Assert.That(project.Name == projectEntity.Name); + Assert.That(project.Description == projectEntity.Description); + Assert.IsEmpty(project.Items); + } + + [Test] + public void ProjectEntityMapping_Project_ProjectEntity() + { + // Setup + const long projectId = 1; + var project = new Project + { + StorageId = projectId, + Name = "test", + Description = "description" + }; + var projectEnties = new List + { + new ProjectEntity() + { + ProjectEntityId = projectId + } + }; + var projectEntities = GetDbSetTest(projectEnties); + + // Call + ProjectEntityConverter.UpdateProjectEntity(projectEntities, project); + + // Assert + Assert.IsInstanceOf(project); + var projectEntitiesArray = projectEntities.ToList(); + Assert.AreEqual(projectEntitiesArray.Count, 1); + Assert.AreEqual(project.StorageId, projectEntitiesArray[0].ProjectEntityId); + Assert.AreEqual(project.Name, projectEntitiesArray[0].Name); + Assert.AreEqual(project.Description, projectEntitiesArray[0].Description); + } + + private static IDbSet GetDbSetTest(IList data) where T : class + { + IQueryable queryable = data.AsQueryable(); + + IDbSet 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/packages.config =================================================================== diff -u -rc4ec466640c331e3dbf5c4fc31c8f048ab3d8651 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/packages.config (.../packages.config) (revision c4ec466640c331e3dbf5c4fc31c8f048ab3d8651) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/packages.config (.../packages.config) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -4,4 +4,5 @@ + \ No newline at end of file Index: Core/Common/src/Core.Common.Base/IStorable.cs =================================================================== diff -u -r7980edee4d818aa3759b179c8af269f4f1f23597 -r0155f2f233aefc7951782b302e1398e02c00f298 --- Core/Common/src/Core.Common.Base/IStorable.cs (.../IStorable.cs) (revision 7980edee4d818aa3759b179c8af269f4f1f23597) +++ Core/Common/src/Core.Common.Base/IStorable.cs (.../IStorable.cs) (revision 0155f2f233aefc7951782b302e1398e02c00f298) @@ -1,7 +1,13 @@ namespace Core.Common.Base { - interface IStorable + /// + /// Interface that describes the methods that need to be implemented on classes that are stored in the storage. + /// + public interface IStorable { - long StorageId { get; set; } + /// + /// Gets or sets the unique identifier for the storage of the class. + /// + long StorageId { get; } } }