UserAuthenticateCommand_FromRepositoriesExistingInactivePerson_Handle_ShouldReturnAllErrors() { //Arrange DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn)); _mocker.GetMock <IValidationService>() .Setup(v => v.Validate(It.IsAny <ICommand>())) .Returns(() => true); var command = new UserAuthenticateCommandBuilder() .WithUser(ValidUserName) .WithPassword(ValidPassword); _mocker.GetMock <IPersonRepository>() .Setup(u => u.GetByEmailAndPassword(It.IsAny <string>(), It.IsAny <string>())) .Returns(() => new PersonBuilder().WithPersonUserStatus(PersonUserStatus.Inactive)); var handler = _mocker.Resolve <UserCommandHandler>(); //Act handler.Handle(command); //Assert _notifications.Should() .NotBeEmpty() .And.HaveCount(1) .And.Contain(n => n.Value == Domain.Main.Resources.Messages.UserAuthenticateUserIsInactive); }
UserAuthenticateCommand_Valid_Handle_ShouldReturnSuccessAndChangeUserSerialKey() { //Arrange DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn)); _mocker.GetMock <IValidationService>() .Setup(v => v.Validate(It.IsAny <ICommand>())) .Returns(() => true); var serialKey = Guid.NewGuid().ToString(); var command = new UserAuthenticateCommandBuilder() .WithUser(ValidUserName) .WithPassword(ValidPassword); Person person = null; _mocker.GetMock <IPersonRepository>() .Setup(u => u.GetByEmailAndPassword(It.IsAny <string>(), It.IsAny <string>())) .Callback(() => { person = new PersonBuilder() .WithSerialKey(serialKey); }) .Returns(() => person); _mocker.GetMock <IPersonRepository>() .Setup(u => u.Update(It.IsAny <Person>())) .Callback((Person u) => { person.SetSerialKey(u.SerialKey); }) .Returns(() => person); var handler = _mocker.Resolve <UserCommandHandler>(); //Act handler.Handle(command); //Assert _notifications.Should() .BeEmpty(); person.SerialKey.Should() .NotBe(serialKey); _mocker.GetMock <IPersonRepository>().Verify(x => x.Update(It.IsAny <Person>()), Times.Once()); }