public void ShouldCreateInvalidResult() { var result = CreationResult <ResultForTest, ErrorForTest> .CreateInvalidResult( error : ErrorForTest.AnyError ); Assert.IsFalse(result.IsValid); Assert.AreEqual(result.Error, ErrorForTest.AnyError); }
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)); }
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)); }