public async Task Create_WhenUserIsValid_ReturnsUserDTO() { // Arrange var userToCreate = UserFixture.CreateValidUserDTO(); var encryptedPassword = new Lorem().Sentence(); var userCreated = _mapper.Map <User>(userToCreate); userCreated.SetPassword(encryptedPassword); _userRepositoryMock.Setup(x => x.GetAsync( It.IsAny <Expression <Func <User, bool> > >(), It.IsAny <bool>())) .ReturnsAsync(() => null); _rijndaelCryptographyMock.Setup(x => x.Encrypt(It.IsAny <string>())) .Returns(encryptedPassword); _userRepositoryMock.Setup(x => x.CreateAsync(It.IsAny <User>())) .ReturnsAsync(() => userCreated); // Act var result = await _sut.CreateAsync(userToCreate); // Assert result.Value.Should() .BeEquivalentTo(_mapper.Map <UserDTO>(userCreated)); }
public async Task Update_WhenUserIsValid_ReturnsUserDTO() { // Arrange var oldUser = UserFixture.CreateValidUser(); var userToUpdate = UserFixture.CreateValidUserDTO(); var userUpdated = _mapper.Map <User>(userToUpdate); var encryptedPassword = new Lorem().Sentence(); _userRepositoryMock.Setup(x => x.GetAsync(oldUser.Id)) .ReturnsAsync(() => oldUser); _rijndaelCryptographyMock.Setup(x => x.Encrypt(It.IsAny <string>())) .Returns(encryptedPassword); _userRepositoryMock.Setup(x => x.UpdateAsync(It.IsAny <User>())) .ReturnsAsync(() => userUpdated); // Act var result = await _sut.UpdateAsync(userToUpdate); // Assert result.Value.Should() .BeEquivalentTo(_mapper.Map <UserDTO>(userUpdated)); }
public async Task Update_WhenUserNotExists_ReturnsEmptyOptional() { // Arrange var userToUpdate = UserFixture.CreateValidUserDTO(); _userRepositoryMock.Setup(x => x.GetAsync( It.IsAny <Expression <Func <User, bool> > >(), It.IsAny <bool>())) .ReturnsAsync(() => null); // Act var result = await _sut.UpdateAsync(userToUpdate); // Act result.HasValue.Should() .BeFalse(); }