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 GetById_WhenUserExists_ReturnsUserDTO() { // Arrange var userId = new Randomizer().Int(0, 1000); var userFound = UserFixture.CreateValidUser(); _userRepositoryMock.Setup(x => x.GetAsync(userId)) .ReturnsAsync(() => userFound); // Act var result = await _sut.GetAsync(userId); // Assert result.Value.Should() .BeEquivalentTo(_mapper.Map <UserDTO>(userFound)); }
public async Task GetByEmail_WhenUserExists_ReturnsUserDTO() { // Arrange var userEmail = new Internet().Email(); var userFound = UserFixture.CreateValidUser(); _userRepositoryMock.Setup(x => x.GetAsync( It.IsAny <Expression <Func <User, bool> > >(), It.IsAny <bool>())) .ReturnsAsync(() => userFound); // Act var result = await _sut.GetByEmailAsync(userEmail); // Assert result.Value.Should() .BeEquivalentTo(_mapper.Map <UserDTO>(userFound)); }
public async Task Create_WhenUserExists_ReturnsEmptyOptional() { // Arrange var userToCreate = UserFixture.CreateValidUserDTO(); var userExists = UserFixture.CreateValidUser(); _userRepositoryMock.Setup(x => x.GetAsync( It.IsAny <Expression <Func <User, bool> > >(), It.IsAny <bool>())) .ReturnsAsync(() => userExists); // Act var result = await _sut.CreateAsync(userToCreate); // Act result.HasValue.Should() .BeFalse(); }