예제 #1
0
        public void return_ok()
        {
            const int someTodoId = 4;

            service
            .Setup(x => x.Delete(someTodoId))
            .Returns(ServiceExecutionResult.WithSucess());

            var response = controller.Delete(someTodoId) as OkResult;

            response.StatusCode.ShouldBe((int)HttpStatusCode.OK);
        }
예제 #2
0
        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());
        }
예제 #3
0
        public void return_ok_when_todo_is_created()
        {
            createTodoService
            .Setup(x => x.Create(It.IsAny <TodoCreationArgs>()))
            .Returns(ServiceExecutionResult.WithSucess());
            var request = new TodoCreationRequest {
                Title = "title", Description = "simple description"
            };

            var response = controller.Create(request) as OkResult;

            response.StatusCode.ShouldBe((int)HttpStatusCode.OK);
        }
예제 #4
0
        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());
        }
예제 #5
0
        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_ok()
        {
            const int someId  = 1;
            var       service = new Mock <IUpdateTodoService>();

            service
            .Setup(x => x.Update(It.Is <TodoUpdatingArgs>(y => y.Id == someId)))
            .Returns(ServiceExecutionResult.WithSucess());
            var controller = new UpdateTodoController(service.Object);
            var request    = new TodoUpdatingRequest {
                Id = someId, Title = "some title", Description = "some description"
            };

            var response = controller.Update(request) as OkResult;

            response.StatusCode.ShouldBe((int)HttpStatusCode.OK);
        }
예제 #7
0
        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());
        }