public async Task CreateUser_With_Duplicated_Email_Should_Return_Validation_Error() { var response = await Some.UserService(Some.MockedContext().With(Some.User().With(userName: "******", email: "*****@*****.**").ToList())) .CreateUserAsync(Some.CreateUserCommand().With(userName: "******", email: "*****@*****.**")); response.ValidationResult.Errors.Should().ContainKey(PropertyName.Get((CreateUserCommand x) => x.Email)); }
public async Task CreateUser_With_Correct_Command_Should_Create_User() { var context = Some.MockedContext().With(new List <User>()).Build(); var userRepository = Substitute.For <Repository <User> >(context); var command = Some.CreateUserCommand().With(password: "******", rePassword: "******").Build(); var response = await Some.UserService(context, userRepository).CreateUserAsync(command); response.ValidationResult.Errors.Should().BeEmpty(); userRepository.Received(1).Add(Arg.Is <User>(x => !string.IsNullOrEmpty(x.HashedPassword) && x.HashedPassword != command.Password)); }