public void ReturnsStatusEntityIfStatusExists() { TaskStatus testStatus = TestValuesProvider.GetTaskStatuses().FirstOrDefault(); _taskStatusRepoMock.Setup(repo => repo.GetSingleOrDefault( It.IsAny <Func <TaskStatus, bool> >())) .Returns(testStatus); TaskStatus result = this.TaskStatusServiceInstance.GetStatus(testStatus.Label); _taskStatusRepoMock.Verify(repo => repo.GetSingleOrDefault( It.IsAny <Func <TaskStatus, bool> >()), Times.Once); Assert.Equal(testStatus, result); }
public void ChangeStatusThrowsExceptionOnRepoFail() { List <Task> testTasks = TestValuesProvider.GetTasks(); TaskStatus testStatus = new TaskStatus() { Label = "test label" }; _taskRepositoryMock.Setup(repo => repo.Update(testTasks)) .Throws <Exception>(); Assert.Throws <StriveDatabaseException>(() => { this.TaskServiceInstance.ChangeStatus(testTasks, testStatus); }); }
public void ProjectsControllerReturnsOkResultIfNoExceptionThrown() { var requestDto = new ProjectListRequestDto() { UserId = 1 }; List <Project> testProjects = TestValuesProvider.GetProjects(); _projectServiceMock.Setup(service => service.GetProjects(It.IsAny <int>())) .Returns(testProjects); IActionResult result = this.ProjectsControllerInstance.GetProjectList(requestDto); Assert.IsType <OkObjectResult>(result); }
public void GetTasksReturnsEntitiesMappedToIdList() { var testTasksIds = new List <int>(); List <Task> testTasks = TestValuesProvider.GetTasks(); foreach (var task in testTasks) { testTasksIds.Add(task.Id); } _taskRepositoryMock.Setup(repo => repo.GetAllAsIQueryable()) .Returns(testTasks.AsQueryable()); List <Task> result = this.TaskServiceInstance.GetTasks(testTasksIds.AsEnumerable()) .ToList(); Assert.Equal(testTasks, result); }
public void ChangeStatusReturnsTasksWithUpdatedStatusOnSuccessfulUpdate() { List <Task> testTasks = TestValuesProvider.GetTasks(); TaskStatus testStatus = new TaskStatus() { Label = "test label" }; List <Task> result = this.TaskServiceInstance.ChangeStatus(testTasks, testStatus).ToList(); _taskRepositoryMock.Verify(repo => repo.Update(testTasks), Times.Once); Assert.All(result, task => { Assert.True(task.Status.Label == testStatus.Label); }); }
public void GetProjectInfoReturnsUnauthorizedOnWrongUser() { var requestData = new ProjectInfoRequestDto() { ProjectId = 1, UserId = 2 }; Project expectedProject = TestValuesProvider.GetProjects().FirstOrDefault(); _projectServiceMock.Setup(service => service.GetProjectById(requestData.ProjectId.Value)) .Returns(expectedProject); IActionResult result = this.ProjectsControllerInstance.GetProjectInfo(requestData); Assert.IsType <UnauthorizedResult>(result); }
public void GetTasksReturnsFullCollectionWhenStatusIsNull() { var requestParams = new TaskListRequestDto() { ProjectId = 1, Status = null }; List <Task> testTasks = TestValuesProvider.GetTasks(); _taskRepositoryMock.Setup(repo => repo.GetAllAsIQueryable()) .Returns(testTasks.AsQueryable()); List <Task> result = this.TaskServiceInstance.GetTasks(requestParams); _taskRepositoryMock.Verify(repo => repo.GetAllAsIQueryable(), Times.Once); Assert.Equal(testTasks.Count, result.Count); }
public void UpdateProjectReturnsOkOnSuccessfulUpdate() { var projectData = new ProjectCreateUpdateRequestDto() { Id = 1, Name = "Test", Description = "Test", UserId = 1 }; _projectServiceMock.Setup(service => service.GetProjectById(It.IsAny <int>())) .Returns(TestValuesProvider.GetProjects().FirstOrDefault()); IActionResult result = this.ProjectsControllerInstance.UpdateProject(projectData); _projectServiceMock.Verify(service => service.GetProjectById(projectData.Id.Value), Times.Once); _projectServiceMock.Verify(service => service.IsProjectExists(projectData.Name, projectData.UserId.Value), Times.Once); _projectServiceMock.Verify(service => service.Update(It.IsAny <Project>()), Times.Once); Assert.IsType <OkResult>(result); }
public void UpdateTaskChangesStatusSuccessfully() { var oldStatus = new TaskStatus() { Label = "old status" }; var newStatus = new TaskStatus() { Label = "newStatus" }; var taskData = new TaskCreateUpdateRequestDto() { Id = 1, Title = "test", Description = "test", Status = newStatus.Label }; var mappedTask = new Task() { Status = oldStatus }; var taskWithUpdatedStatus = new Task() { Status = newStatus }; _mapperMock.Setup(mapper => mapper.Map(It.IsAny <TaskCreateUpdateRequestDto>(), It.IsAny <Task>())) .Returns(mappedTask); _taskServiceMock.Setup(service => service.GetTaskById(It.IsAny <int>())) .Returns(TestValuesProvider.GetTasks().FirstOrDefault()); _taskStatusServiceMock.Setup(service => service.GetStatus(taskData.Status)) .Returns(newStatus); IActionResult result = this.TasksControllerInstance.UpdateTask(taskData); Assert.IsType <OkResult>(result); }
public void SetStatusReturnsNotFoundWhenStatusNotExists() { var setStatusData = new TaskSetStatusRequestDto() { Status = "test status", Tasks = TestValuesProvider.GetTaskListItems() }; List <Task> mappedTestTasks = TestValuesProvider.GetTasks(); _taskServiceMock.Setup(service => service.GetTasks(It.IsAny <IEnumerable <int> >())) .Returns(mappedTestTasks); _taskServiceMock.Setup(service => service.GetStatusByLabel(setStatusData.Status)) .Returns(null as TaskStatus); IActionResult result = this.TasksControllerInstance.SetStatus(setStatusData); _taskServiceMock.Verify(service => service.GetTasks(It.IsAny <IEnumerable <int> >()), Times.Once); _taskServiceMock.Verify(service => service.GetStatusByLabel(setStatusData.Status), Times.Once); _taskServiceMock.Verify(service => service.ChangeStatus(It.IsAny <IEnumerable <Task> >(), It.IsAny <TaskStatus>()), Times.Never); Assert.IsType <NotFoundObjectResult>(result); Assert.Equal(setStatusData.Status, (result as NotFoundObjectResult)?.Value); }
public void UpdateProjectReturnsBadRequestOnInvalidData() { var projectData = new ProjectCreateUpdateRequestDto() { Id = 1, Name = "Test", Description = "Test", UserId = 1 }; ProjectsController controller = this.ProjectsControllerInstance; controller.ModelState.AddModelError("error", "error"); _projectServiceMock.Setup(service => service.GetProjectById(projectData.Id.Value)) .Returns(TestValuesProvider.GetProjects().FirstOrDefault()); IActionResult result = controller.UpdateProject(projectData); _projectServiceMock.Verify(service => service.GetProjectById(projectData.Id.Value), Times.Once); _projectServiceMock.Verify(service => service.IsProjectExists(projectData.Name, projectData.UserId.Value), Times.Never); _projectServiceMock.Verify(service => service.Update(It.IsAny <Project>()), Times.Never); Assert.IsType <BadRequestObjectResult>(result); }