public async Task LoginUser_ValidUser(SignInResult expectedResult, UserLoginResponse expectedUserLoginResponse) { //Arrange expectedResult.SetProperty(s => s.Succeeded, true); _userLoginProviderMock.Setup(s => s.UserSignInAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(expectedResult); _userLoginProviderMock.Setup(s => s.TokenGenerator(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <double>())).ReturnsAsync(expectedUserLoginResponse); var command = new UserLoginCommand("*****@*****.**", "password123"); _sut = new UserLoginCommandHandler(_userLoginProviderMock.Object, _mediatorHandlerMock.Object, _userProviderMock.Object); //Act var response = await _sut.Handle(command, CancellationToken.None); //Assert response.Payload.Should().NotBeNull(); response.ValidationResult.Should().BeNull(); response.Payload.UserToken.Should().BeEquivalentTo(expectedUserLoginResponse.UserToken); }
public async Task LoginUser_InvalidUserOrPassword(SignInResult expectedResult) { //Arrange expectedResult.SetProperty(s => s.Succeeded, false); var validationResult = new ValidationResult(); validationResult.Errors.Add(CreateValidationFailure(null, "User or password invalid!")); _userLoginProviderMock.Setup(s => s.UserSignInAsync(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(expectedResult); var command = new UserLoginCommand("*****@*****.**", "password123"); _sut = new UserLoginCommandHandler(_userLoginProviderMock.Object, _mediatorHandlerMock.Object, _userProviderMock.Object); //Act var response = await _sut.Handle(command, CancellationToken.None); //Assert response.Payload.Should().BeNull(); response.ValidationResult.Errors.Should().HaveCount(1); response.ValidationResult.Errors.Select(s => s.ErrorMessage).Should().Contain(validationResult.Errors.Select(s => s.ErrorMessage)); }