Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
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());
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
0
        public void Authenticate()
        {
            var status_messages = new Dictionary <AuthStatus, string>();

            status_messages.Add(AuthStatus.AccountValidated, "Account validated successfully.");
            status_messages.Add(AuthStatus.UserNotFound, "Username not found.");
            status_messages.Add(AuthStatus.IncorrectPasswd, "Incorrect password.");

            AuthStatus status;

            var userAccount = userAccountsManager.Find(uiService.GetUIField("Username").Value);

            if (userAccount == null)
            {
                status = AuthStatus.UserNotFound;
            }
            else
            if (userAccount.Passwd != uiService.GetUIField("Password").Value)
            {
                status = AuthStatus.IncorrectPasswd;
            }
            else
            {
                status = AuthStatus.AccountValidated;
            }

            if (status == AuthStatus.AccountValidated)
            {
                this.result = ServiceExecutionResult.Success;
            }
            else
            {
                remainingAttempts--;
                if (remainingAttempts == 0)
                {
                    this.result = ServiceExecutionResult.Failure;
                }
            }

            uiService.BreakLine();
            uiService.OutputInfo(status_messages[status], InfoCategory.FixedResponse);

            if (this.result != ServiceExecutionResult.Undefined)
            {
                this.status = ServiceExecutionStatus.Completed;
            }
        }
        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);
        }
        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);
        }
Ejemplo n.º 11
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());
        }