Beispiel #1
0
        public async Task <IActionResult> Register([FromBody] AuthorRegistrationRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(new AuthFailedResponse
                {
                    Errors = ModelState.Values.SelectMany(x =>
                                                          x.Errors.Select(e => e.ErrorMessage))
                }));
            }

            var author = _mapper.Map <Author>(request);

            var authResponse = await _authService
                               .RegisterAsync(author)
                               .ConfigureAwait(false);

            if (!authResponse.Success)
            {
                return(BadRequest(new AuthFailedResponse
                {
                    Errors = authResponse.Errors
                }));
            }

            return(Ok(new AuthSuccessResponse
            {
                Token = authResponse.Token
            }));
        }
        public RegisterTest(CustomWebApplicationFactory factory,
                            ITestOutputHelper output) : base(factory)
        {
            _output = output;
            _faker  = new Faker("pt_BR");

            _authorRegistrationhorRequest = new AuthorRegistrationRequest
            {
                FirstName = _faker.Person.FirstName,
                LastName  = _faker.Person.LastName,
                Username  = _faker.Person.UserName,
                Email     = _faker.Person.Email,
                Password  = _faker.Internet.Password(memorable: true, prefix: "Y#10")
            };
        }