public ServiceExecutionResult Delete(int todoId) { if (!existTodoRepository.Exist(todoId)) { return(ServiceExecutionResult.WithErrors(new List <Error> { Error.With(nameof(todoId), ErrorCodes.NotFound) })); } deleteRepository.Delete(todoId); return(ServiceExecutionResult.WithSucess()); }
public void return_not_found_when_there_is_an_error() { const int someTodoId = 4; service .Setup(x => x.Delete(someTodoId)) .Returns(ServiceExecutionResult.WithErrors(new List <Error> { Error.With("title", ErrorCodes.Required) })); var response = controller.Delete(someTodoId) as NotFoundResult; response.StatusCode.ShouldBe((int)HttpStatusCode.NotFound); }
public void return_bad_request_when_there_are_errors() { createTodoService .Setup(x => x.Create(It.Is <TodoCreationArgs>(x => x.Title == string.Empty))) .Returns(ServiceExecutionResult.WithErrors(new List <Error> { Error.With(nameof(TodoCreationArgs.Title), ErrorCodes.Required) })); var request = new TodoCreationRequest { Title = string.Empty, Description = "simple description" }; var response = controller.Create(request) as BadRequestObjectResult; response.StatusCode.ShouldBe((int)HttpStatusCode.BadRequest); }
public ServiceExecutionResult SignUp(SignUpUserArgs args) { var errors = validator.Validate(args); if (errors.Any()) { return(ServiceExecutionResult.WithErrors(errors)); } var user = new User(args.Email, args.Password); saveUserRepository.Save(user); return(ServiceExecutionResult.WithSucess()); }
public ServiceExecutionResult Create(TodoCreationArgs todoCreationArgs) { var validationArgs = new ValidationArgs(todoCreationArgs.Title, todoCreationArgs.Description); var errors = validator.Validate(validationArgs); if (errors.IsNotEmpty()) { return(ServiceExecutionResult.WithErrors(errors)); } var todo = new Create.Models.Todo(todoCreationArgs.Title, todoCreationArgs.Description); repository.Save(todo); return(ServiceExecutionResult.WithSucess()); }
public void return_error_when_there_are_errors() { const string title = "title"; var service = new Mock <IUpdateTodoService>(); service .Setup(x => x.Update(It.Is <TodoUpdatingArgs>(y => y.Title == title))) .Returns(ServiceExecutionResult.WithErrors(new List <Error> { Error.With(nameof(TodoUpdatingArgs.Title), ErrorCodes.Required) })); var controller = new UpdateTodoController(service.Object); var request = new TodoUpdatingRequest { Id = 1, Title = title }; var response = controller.Update(request) as BadRequestObjectResult; response.StatusCode.ShouldBe((int)HttpStatusCode.BadRequest); }
public ServiceExecutionResult Update(TodoUpdatingArgs todoUpdatingArgs) { var validationArgs = new ValidationArgs(todoUpdatingArgs.Title, todoUpdatingArgs.Description); var errors = validator.Validate(validationArgs); if (errors.IsNotEmpty()) { return(ServiceExecutionResult.WithErrors(errors)); } if (IsNotExistTodo(todoUpdatingArgs.Id)) { return(ServiceExecutionResult.WithErrors(new List <Error> { Error.With(nameof(todoUpdatingArgs.Id), ErrorCodes.NotFound) })); } var todo = findTodoRepository.FindById(todoUpdatingArgs.Id); todo.Update(validationArgs.Title, validationArgs.Description); updateTodoRepository.Update(todo); return(ServiceExecutionResult.WithSucess()); }