public void Handle_ThrowsInvalidCredentialException_WhenUserIdIsFound_ButPasswordDontMatch() { //Arrange var command = fixture.Create <AuthenticateWithCredentialsCommand>(); var readUser = fixture.Create <Budget.Users.Domain.ReadModel.User>(); readModelUserRepository.GetByUserName(Arg.Any <string>()).Returns(readUser); var subscription = new UserSubscribed( Guid.NewGuid(), fixture.Create <string>(), fixture.Create <string>(), fixture.Create <string>(), "*****@*****.**" ); var passwordChange = new PasswordChanged(subscription.AggregateId, command.UserName); var userEvents = new Event[] { subscription, passwordChange }; var writeModelUser = writeModelUserFactory.Load(subscription.AggregateId, userEvents); writeModelUserRepository.Get(Arg.Any <Guid>()).Returns(writeModelUser); var cancellationToken = new CancellationToken(); //Act Assert.ThrowsAsync <InvalidCredentialException>(() => handler.Handle(command, cancellationToken)); //Assert }
public void Load_AssignsId_AppliesAllChanges() { //Arrange Guid id = Guid.NewGuid(); UserSubscribed subscriptionEvent = new UserSubscribed( id, fixture.Create <string>(), fixture.Create <string>(), fixture.Create <string>(), "*****@*****.**" ); PasswordChanged passwordChangeEvent = new PasswordChanged(id, fixture.Create <string>()); IEnumerable <Event> changes = new List <Event>() { subscriptionEvent, passwordChangeEvent }; //Act User user = factory.Load(id, changes); //Assert user.Should().NotBeNull(); user.Id.Should().Be(id); user.Changes.Should().BeEquivalentTo(changes); user.UserName.Should().Be(subscriptionEvent.UserName); user.FirstName.Should().Be(subscriptionEvent.FirstName); user.LastName.Should().Be(subscriptionEvent.LastName); user.Email.Address.Should().Be(subscriptionEvent.Email); user.EncryptedPassword.Should().Be(passwordChangeEvent.EncryptedPassword); }
public void Save_ReplacesUser_WhenIsNotNewUser() { //Arrange var domainUser = userFactory.Load(Guid.NewGuid(), new List <Event>() { fixture.Create <UserSubscribed>(), fixture.Create <PasswordChanged>() }); //Act var saveTask = repository.Save(domainUser); saveTask.Wait(); //Assert userCollection.Received(1).FindOneAndReplaceAsync <User>(Arg.Any <FilterDefinition <User> >(), Arg.Any <User>()); }