public void ShouldCreateValidResult()
        {
            var resultForTest = new ResultForTest(value: "test");

            var result = CreationResult <ResultForTest, ErrorForTest> .CreateValidResult(
                result : resultForTest
                );

            Assert.IsTrue(result.IsValid);
            Assert.AreEqual(result.Result.Value, resultForTest.Value);
        }
        public CreationResult <User, SignUpError> Execute(UserSignUpRequest request)
        {
            if (userRepository.Exist(email: request.Email))
            {
                return(CreationResult <User, SignUpError> .CreateInvalidResult(SignUpError.UserAlreadyExist));
            }
            var user = HashPasswordAndCreateUser(request);

            userRepository.Create(user);
            return(CreationResult <User, SignUpError> .CreateValidResult(user));
        }
Exemplo n.º 3
0
        public static CreationResult <Email, Error> CreateAndValidate(string value)
        {
            if (string.IsNullOrEmpty(value) || string.IsNullOrWhiteSpace(value))
            {
                return(CreationResult <Email, Error> .CreateInvalidResult(error : Error.Required));
            }
            if (!IsValidEmail(email: value))
            {
                return(CreationResult <Email, Error> .CreateInvalidResult(error : Error.InvalidFormat));
            }
            Email email = new Email(value: value);

            return(CreationResult <Email, Error> .CreateValidResult(result : email));
        }
        public CreationResult <User, LoginError> Execute(UserLoginRequest request)
        {
            var user = userRepository.FindBy(request.Email);

            if (user == null)
            {
                return(CreationResult <User, LoginError> .CreateInvalidResult(LoginError.UserNotFound));
            }
            if (!AreUserCredentialsValid(request: request, user: user))
            {
                return(CreationResult <User, LoginError> .CreateInvalidResult(LoginError.InvalidCredentials));
            }
            return(CreationResult <User, LoginError> .CreateValidResult(user));
        }
 public void ShouldNotCreateValidResultWithNull()
 {
     var result = CreationResult <ResultForTest, ErrorForTest> .CreateValidResult(
         result : null
         );
 }