public async Task ValidateCreateUserFailsForDuplicatedUser() { // arrange var user = TestObjectCreationUtility.CreateUser(); mocker .GetMock <IUsersRepository>() .Setup(x => x.GetByEmailAsync(It.IsAny <string>())) .ReturnsAsync(user); // act, assert await Assert.ThrowsAsync <ResourceAlreadyExistsException>(() => service.RegisterUserAsync(user)); mocker.VerifyAll(); }
public async Task ValidateCanGetUser() { // arrange var user = TestObjectCreationUtility.CreateUser(); mocker .GetMock <IUsersRepository>() .Setup(x => x.GetByEmailAsync(It.IsAny <string>())) .ReturnsAsync(user); // act var savedUser = await service.GetUserAsync(user.Email); // assert Assert.NotNull(savedUser); Assert.Null(savedUser.Password); mocker.VerifyAll(); }
public async Task ValidateCanLogin() { // arrange var user = TestObjectCreationUtility.CreateUser(); mocker .GetMock <IEncryptionSerice>() .Setup(x => x.Encrypt(It.Is <string>(x => x == user.Password))) .Returns("some-value"); mocker .GetMock <IUsersRepository>() .Setup(x => x.GetByEmailAndPasswordAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(user); // act var savedUser = await service.LoginAsync(user.Email, user.Password); // assert Assert.NotNull(savedUser); mocker.VerifyAll(); }