Index: Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs =================================================================== diff -u -r3a8bff057967bdb42389382472f6ce55789a0ced -ra01c8d560f9fc30520fc717d83888a3bf6974cc9 --- Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision 3a8bff057967bdb42389382472f6ce55789a0ced) +++ Application/Ringtoets/test/Application.Ringtoets.Storage.Test/Converter/ProjectEntityConverterTest.cs (.../ProjectEntityConverterTest.cs) (revision a01c8d560f9fc30520fc717d83888a3bf6974cc9) @@ -1,18 +1,21 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Data.Entity; using System.Linq; using Application.Ringtoets.Storage.Converter; +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] - class ProjectEntityConverterTest + public class ProjectEntityConverterTest { [Test] - public void ProjectEntityMapping_ProjectEntity_Project() + public void GetProject_ProjectEntity_Project() { // Setup const long projectId = 1; @@ -23,7 +26,10 @@ Description = "description" }; - var projectEntities = GetDbSetTest(new List { projectEntity }); + var projectEntities = GetDbSetTest(new List + { + projectEntity + }); // Call var project = ProjectEntityConverter.GetProject(projectEntities); @@ -37,12 +43,99 @@ } [Test] - public void ProjectEntityMapping_Project_ProjectEntity() + 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 = 1; + 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_Project_ProjectEntity() + { + // Setup + const long projectId = 1; + var project = new Project + { StorageId = projectId, Name = "test", Description = "description" @@ -68,8 +161,6 @@ Assert.AreEqual(project.Description, projectEntitiesArray[0].Description); } - - private static IDbSet GetDbSetTest(IList data) where T : class { var queryable = data.AsQueryable(); @@ -84,4 +175,4 @@ return dbSet; } } -} +} \ No newline at end of file