public async Task Return_Password_InCorrect_When_Password_Does_Not_Match() { var expectedResult = new AccessToken("access-token", 100); _userRepositoryMock .Setup(x => x.SelectByEmailAsync( It.IsAny <Email>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new User( UserId.NewUserId(), new Name("name"), new Email("*****@*****.**"), new Password("cmKaQbB25Yj7qMcco3+tyazcjnMhuctOpV/Qv5/o7XI="), new PasswordSalt("salt"))); _tokenGeneratorMock .Setup(x => x.CreateAccessToken( It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())) .Returns(expectedResult); var actualResult = await _sut.Handle(new LoginUserCommand("*****@*****.**", "incorrect-password"), CancellationToken.None); actualResult.Should().BeOfType <PasswordInCorrectResult>(); }
public async Task Return_200_With_Users() { const string expectedName1 = "name-1"; const string expectedEmail1 = "*****@*****.**"; const string expectedPassword1 = "password1"; const string expectedName2 = "name-2"; const string expectedEmail2 = "*****@*****.**"; const string expectedPassword2 = "password2"; const string expectedName3 = "name-3"; const string expectedEmail3 = "*****@*****.**"; const string expectedPassword3 = "password3"; var expectedUserId1 = UserId.NewUserId().Value; var expectedUserId2 = UserId.NewUserId().Value; var expectedUserId3 = UserId.NewUserId().Value; var expectedResponse = new List <ListUsersResponse> { new() { Id = expectedUserId1, Name = expectedName1, Email = expectedEmail1 }, new() { Id = expectedUserId2, Name = expectedName2, Email = expectedEmail2 }, new() { Id = expectedUserId3, Name = expectedName3, Email = expectedEmail3 }, }; var expectedUser = new List <User> { GivenUser(expectedUserId1, expectedName1, expectedEmail1, expectedPassword1), GivenUser(expectedUserId2, expectedName2, expectedEmail2, expectedPassword2), GivenUser(expectedUserId3, expectedName3, expectedEmail3, expectedPassword3) }; _mediatorMock .Setup(x => x.Send(It.IsAny <ListUsersQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new ListUsersQueryResult(expectedUser)); var actualResult = await _sut.ListUsersAsync(new ListUsersRequest { Offset = 0, Limit = 10 }); actualResult.Should() .BeOfType <OkObjectResult>() .Which.Value.Should().BeOfType <List <ListUsersResponse> >() .Which.Should().NotBeEmpty() .And.Contain(expectedResponse) .And.HaveCount(3); _mediatorMock.Verify(x => x.Send(It.IsAny <ListUsersQuery>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task Save_User() { var expectedUser = new User( UserId.NewUserId(), new Name("name"), new Email("*****@*****.**"), new Password("pass"), new PasswordSalt(Salt.Create())); var sut = new UserRepository(_fixture.UserManagementDataContext); await sut.SaveAsync(expectedUser, _cancellationToken); await sut.CommitChangesAsync(_cancellationToken); var actualUser = await sut.SelectByEmailAsync(expectedUser.Email, _cancellationToken); actualUser.Should().BeEquivalentTo(expectedUser); }
public async Task Return_List_Of_Users() { var expectedUsers = new List <User> { GivenUser(UserId.NewUserId().Value, "name1", "*****@*****.**", "password1"), GivenUser(UserId.NewUserId().Value, "name2", "*****@*****.**", "password2"), GivenUser(UserId.NewUserId().Value, "name3", "*****@*****.**", "password3"), }; _repositoryMock .Setup(x => x.SelectAllAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>())) .ReturnsAsync(expectedUsers); var sut = new ListUsersQueryHandler(_repositoryMock.Object); var actualResult = await sut.Handle(new ListUsersQuery(0, 10), CancellationToken.None); actualResult.Should() .BeOfType <ListUsersQueryResult>() .Which.Users .Should().NotBeEmpty() .And.Contain(expectedUsers) .And.HaveCount(3); _repositoryMock.Verify(x => x.SelectAllAsync(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <CancellationToken>()), Times.Once); }
public User NewUser(Name name, Email email, Password password, PasswordSalt passwordSalt) { return(new(UserId.NewUserId(), name, email, password, passwordSalt)); }