/// <inheritdoc/> public WorkItemPublic CreateWorkItem(WorkItemPublic workItem) { Ensure.ParamNotNull(workItem, nameof(workItem)); WorkItemLogic workItemLogic = new WorkItemLogic(mDBContext); WorkItemConverter converter = new WorkItemConverter(mDBContext); WorkItem result = workItemLogic.CreateWorkItem(converter.Convert(workItem)); mDBContext.SaveChanges(); return(converter.Convert(result)); }
public void CreateWorkItem_OnWalidWorkItem_CreatesEntryInDB() { // ARRANGE DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; IDatabaseContext context = new TestDatabaseContext(options); WorkItemLogic logic = new WorkItemLogic(context); WorkItem request = new WorkItem() { Name = Guid.NewGuid().ToString(), Color = Guid.NewGuid().ToString(), Description = Guid.NewGuid().ToString(), WorkItemCollectionId = 1, WorkItemStart = DateTime.Now.AddDays(-1), WorkItemEnd = DateTime.Now }; context.WorkItemCollections.Add(new WorkItemCollection() { ID = 1, TaskBoardId = 1 }); context.TaskBoards.Add(new TaskBoard() { ID = 1, UserID = 1 }); context.Users.Add(new User() { ID = 1 }); context.SaveChanges(); // ACT WorkItem result = logic.CreateWorkItem(request); context.SaveChanges(); request.ID = result.ID; // ASSERT result.Should().BeEquivalentTo <WorkItem>(request); }
public void CreateWorkItem_OnInvalidID_ThrowsArgumentException() { // ARRANGE DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; IDatabaseContext context = new TestDatabaseContext(options); WorkItemLogic logic = new WorkItemLogic(context); WorkItem request = new WorkItem() { ID = 123 }; context.SaveChanges(); // ACT Action act = () => logic.CreateWorkItem(request); // ASSERT act.Should().Throw <ArgumentException>().Where(e => e.Message.Contains("ID can't be set on entity")); }
public void CreateWorkItem_OnNonExistingCollection_ThrowsArgumentException() { // ARRANGE DbContextOptions <TestDatabaseContext> options = new DbContextOptionsBuilder <TestDatabaseContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; IDatabaseContext context = new TestDatabaseContext(options); WorkItemLogic logic = new WorkItemLogic(context); WorkItem request = new WorkItem() { WorkItemCollectionId = 1 }; context.SaveChanges(); // ACT Action act = () => logic.CreateWorkItem(request); // ASSERT act.Should().Throw <ArgumentException>().Where(e => e.Message.Contains("doesn't exist")); }