public async Task On_Task_Finish_All_Documents_Are_In_Status_Of_BLOCAT(DocumentTaskStatus status, bool isBlocked) { var user = new User { UserGroup = new UserGroup() }; var dbContextOptions = CreateNewContextOptions(); using (var context = new ApplicationDbContext(dbContextOptions)) { context.Users.Add(user); context.DocumentTasks.Add(new DocumentTask { DocumentTaskStates = new List <DocumentTaskState> { new DocumentTaskState { DocumentTaskStatus = DocumentTaskStatus.Accepted, DocumentTaskTypePath = new DocumentTaskTypePath() } }, Documents = new List <Document> { new Document { DocumentStates = new List <DocumentState> { new DocumentState() } }, new Document { DocumentStates = new List <DocumentState> { new DocumentState() } } } }); await context.SaveChangesAsync(); } using (var context = new ApplicationDbContext(dbContextOptions)) { var service = new DocumentTasksService(context); await service.ChangeStatus(1, status); await context.SaveChangesAsync(); } using (var context = new ApplicationDbContext(dbContextOptions)) { var documents = await context.Documents.Include(it => it.DocumentStates).ToListAsync(); if (isBlocked) { Assert.True(documents.All(it => it.DocumentStates.Last().DocumentStatus == DocumentStatus.Blocat)); } else { Assert.False(documents.All(it => it.DocumentStates.Last().DocumentStatus == DocumentStatus.Blocat)); } } }
public async Task Can_Change_Status(DocumentTaskStatus taskStatus, DocumentTaskStatus expectedStatus, int count) { var now = DateTime.Now; var dbContextOptions = CreateNewContextOptions(); using (var context = new ApplicationDbContext(dbContextOptions)) { context.DocumentTasks.Add(new DocumentTask { LastModified = now, DocumentTaskStates = new List <DocumentTaskState> { new DocumentTaskState { DocumentTaskStatus = DocumentTaskStatus.RequireAction, DocumentTaskTypePath = new DocumentTaskTypePath { NextPath = new DocumentTaskTypePath() } } } }); await context.SaveChangesAsync(); } using (var context = new ApplicationDbContext(dbContextOptions)) { var service = new DocumentTasksService(context); await service.ChangeStatus(1, taskStatus); await context.SaveChangesAsync(); } using (var context = new ApplicationDbContext(dbContextOptions)) { var task = await context.DocumentTasks.Include(it => it.DocumentTaskStates).FirstAsync(); var newState = task.DocumentTaskStates.Last(); Assert.NotEqual(now, task.LastModified); Assert.Equal(count, task.DocumentTaskStates.Count); Assert.Equal(expectedStatus, newState.DocumentTaskStatus); } }