public async Task UpdateAsync_ValidUserAndTaskDto_Successful() { // Arrange var validUserThatIsRouteEditor = ValidUserWithRouteEditorRole; Seed(TripFlipDbContext, validUserThatIsRouteEditor); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TaskListEntityToSeed); Seed(TripFlipDbContext, TaskEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberRoleEntitiesToSeed); CurrentUserService = CreateCurrentUserService( id: validUserThatIsRouteEditor.Id, email: validUserThatIsRouteEditor.Email); var taskService = new TaskService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: CurrentUserService); var validUpdateTaskDto = UpdateTaskDto; var comparer = new TaskDtoComparer(); var expectedTaskDto = TaskDto; // Act var resultTaskDto = await taskService.UpdateAsync(validUpdateTaskDto); // Assert Assert.AreEqual(0, comparer.Compare(resultTaskDto, expectedTaskDto)); }
public async Task GetById_GivenValidId_Successful() { // Arrange. Seed(TripFlipDbContext, TaskEntityToSeed); var validTaskId = 1; CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var taskService = new TaskService(TripFlipDbContext, Mapper, CurrentUserService); var comparer = new TaskDtoComparer(); // Act. var resultTaskDto = await taskService.GetByIdAsync(validTaskId); // Assert. Assert.AreEqual(0, comparer.Compare(_expectedGotByIdTaskDto, resultTaskDto)); }
public async Task UpdatePriorityAsync_ValidData_Successful() { // Arrange. var taskEntityToSeed = TaskEntityToSeed; Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TaskListEntityToSeed); Seed(TripFlipDbContext, taskEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEditorRoleEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var updateTaskPriorityDto = GetUpdateTaskPriorityDto(); var taskService = new TaskService(TripFlipDbContext, Mapper, CurrentUserService); var expectedTaskDto = new TaskDto() { Id = updateTaskPriorityDto.Id, PriorityLevel = updateTaskPriorityDto.PriorityLevel, Description = taskEntityToSeed.Description, IsCompleted = taskEntityToSeed.IsCompleted, TaskListId = taskEntityToSeed.TaskListId }; var taskDtoComparer = new TaskDtoComparer(); // Act. var resultTaskDto = await taskService.UpdatePriorityAsync(updateTaskPriorityDto); // Assert. Assert.AreEqual(0, taskDtoComparer.Compare(expectedTaskDto, resultTaskDto)); }
public async Task CreateAsync_ValidData_Successful() { // Arrange. var taskListEntityToSeed = TaskListEntityToSeed; Seed(TripFlipDbContext, ValidUser); Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, taskListEntityToSeed); Seed(TripFlipDbContext, TripSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberEntitiesToSeed); Seed(TripFlipDbContext, RouteRoleEntitiesToSeed); Seed(TripFlipDbContext, RouteSubscriberAdminRoleEntityToSeed); CurrentUserService = CreateCurrentUserService(ValidUser.Id, ValidUser.Email); var createTaskDto = GetCreateTaskDto(); var taskService = new TaskService(TripFlipDbContext, Mapper, CurrentUserService); var expectedTaskDto = new TaskDto() { Id = 1, IsCompleted = false, Description = createTaskDto.Description, PriorityLevel = createTaskDto.PriorityLevel, TaskListId = createTaskDto.TaskListId }; // Act. var resultTaskDto = await taskService.CreateAsync(createTaskDto); var taskDtoComparer = new TaskDtoComparer(); // Assert. Assert.AreEqual(0, taskDtoComparer.Compare(expectedTaskDto, resultTaskDto)); }
public async Task GetAllByTaskListIdAsync_ValidTaskListId_Successful() { // Arrange Seed(TripFlipDbContext, TripEntityToSeed); Seed(TripFlipDbContext, RouteEntityToSeed); Seed(TripFlipDbContext, TaskListEntityToSeed); Seed(TripFlipDbContext, TaskEntityToSeed); int validTaskListId = 1; var taskService = new TaskService( tripFlipDbContext: TripFlipDbContext, mapper: Mapper, currentUserService: null); var comparer = new TaskDtoComparer(); var expectedPagedTaskDto = ExpectedPagedTaskDto; var expectedTaskDtoList = expectedPagedTaskDto.Items.ToList(); // Act var resultPagedTaskDto = await taskService.GetAllByTaskListIdAsync( taskListId : validTaskListId, searchString : null, paginationDto : PaginationDto); // Assert var resultTaskDtoList = resultPagedTaskDto.Items.ToList(); int resultTaskDtoListCount = resultTaskDtoList.Count; Assert.AreEqual(resultTaskDtoListCount, expectedTaskDtoList.Count); for (int i = 0; i < resultTaskDtoListCount; i++) { Assert.AreEqual(0, comparer.Compare(resultTaskDtoList[i], expectedTaskDtoList[i])); } }