コード例 #1
0
        public async Task signup_endpoint_should_return_error_when_email_is_invalid()
        {
            var id            = new AggregateId();
            var email         = "test@mail";
            var fullname      = "fullname";
            var password      = "******";
            var role          = Role.User;
            var securityStamp = new Guid().ToString();

            // Add user
            var user = new User(id, email, fullname, "test.nl/image", _passwordService.Hash(password), role,
                                securityStamp, 0, DateTime.MinValue, DateTime.UtcNow, new string[] { });
            await _mongoDbFixture.InsertAsync(user.AsDocument());

            var request = new SignIn(email, password);

            var response = await Act(request);

            response.Should().NotBeNull();
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);

            var content = await response.Content.ReadAsStringAsync();

            var exception = new InvalidEmailException(email);

            content.Should().Contain(exception.Code);
        }
コード例 #2
0
 public ExceptionResponse Map(Exception ex)
 {
     return(ex switch
     {
         EmailAlreadyInUseException emailAlreadyInUseException => new ExceptionResponse("email_in_use", ex.Message, HttpStatusCode.BadRequest),
         InvalidCredentialsException invalidCredentialsException => new ExceptionResponse("invalid_credentials", ex.Message, HttpStatusCode.BadRequest),
         InvalidEmailException invalidEmailException => new ExceptionResponse("invalid_email", ex.Message, HttpStatusCode.BadRequest),
         ResourceNotFoundException resourceNotFoundException => new ExceptionResponse("not_found", ex.Message, HttpStatusCode.NotFound),
         NameAlreadyExistException nameAlreadyExistException => new ExceptionResponse("name_in_use", ex.Message, HttpStatusCode.BadRequest),
         _ => null
     });
コード例 #3
0
 public object Map(Exception exception, object message)
 {
     return(exception switch
     {
         EmailInUseException ex => new SignedUpRejected(ex.Email, ex.Message, ex.Code),
         InvalidCredentialsException ex => new SignInRejected(ex.Email, ex.Message, ex.Code),
         InvalidEmailException ex => message switch
         {
             SignIn command => new SignInRejected(command.Email, ex.Message, ex.Code),
             SignedUpRejected command => new SignedUpRejected(command.Email, ex.Message, ex.Code),
             _ => null
         },
コード例 #4
0
        private void Validate()
        {
            if (string.IsNullOrWhiteSpace(Value))
            {
                throw new EmptyValueException("Email is empty");
            }

            if (!IsValidEmail())
            {
                throw InvalidEmailException.Of(Value);
            }
        }
コード例 #5
0
        public async Task forgotpassword_endpoint_should_return_error_when_user_with_email_does_not_exist()
        {
            var email = "*****@*****.**";

            var command = new ForgotPassword(email);

            // Check if exception is thrown
            var response = await Act(command);

            response.Should().NotBeNull();
            response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
            var content = await response.Content.ReadAsStringAsync();

            var exception = new InvalidEmailException(email);

            content.Should().Contain(exception.Code);
        }