Beispiel #1
0
        UserForgotPasswordCommand_ValidAndNotFoundUser_Handle_ShouldDoNothingAndReturnEmptyResponse()
        {
            //Arrange
            DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn));

            var validCommand = new UserForgotPasswordCommandBuilder()
                               .WithEmail("*****@*****.**");

            _mocker.GetMock <IPersonRepository>()
            .Setup(u => u.GetByEmail(It.IsAny <string>()))
            .Returns(() => null);

            var handler = _mocker.Resolve <UserCommandHandler>();

            //Act
            var commandResult = handler.Handle(validCommand);

            //Assert
            _notifications.Should()
            .BeEmpty();

            _mocker.GetMock <IPersonRepository>().Verify(x => x.Update(It.IsAny <Person>()), Times.Never());

            commandResult.Should()
            .BeEquivalentTo(new UserForgotPasswordCommandResult()
            {
                SerialKey = string.Empty
            });
        }
Beispiel #2
0
        UserForgotPasswordCommand_ValidAndFoundUser_Handle_ShouldResetPasswordRaiseEventAndReturnProperResponse()
        {
            //Arrange
            DomainEvent.Register <UserForgotPasswordRequestedEvent>(ev => {
                _eventUserForgotPasswordRequestedFired = true;
            });

            DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn));

            var validCommand = new UserForgotPasswordCommandBuilder()
                               .WithEmail("*****@*****.**");

            var currentUserPassword = "******";

            Person person = new PersonBuilder()
                            .WithPassword(currentUserPassword);

            _mocker.GetMock <IPersonRepository>()
            .Setup(u => u.GetByEmail(It.IsAny <string>()))
            .Returns(() => person);

            _mocker.GetMock <IPersonRepository>()
            .Setup(u => u.Update(It.IsAny <Person>()))
            .Returns(() => person);

            _mocker.GetMock <IUnitOfWork>()
            .Setup(u => u.Commit())
            .Returns(CommandResponse.Ok);

            var handler = _mocker.Resolve <UserCommandHandler>();

            //Act
            var commandResult = handler.Handle(validCommand);

            //Assert
            _notifications.Should()
            .BeEmpty();

            person.Password.Should()
            .NotBe(currentUserPassword);

            _mocker.GetMock <IPersonRepository>().Verify(x => x.Update(It.IsAny <Person>()), Times.Once());
            _mocker.GetMock <IUnitOfWork>().Verify(uow => uow.Commit(), Times.Once());
            _eventUserForgotPasswordRequestedFired.Should().BeTrue();

            commandResult.Should()
            .BeEquivalentTo(new UserForgotPasswordCommandResult()
            {
                SerialKey = person.SerialKey
            });
        }
Beispiel #3
0
        UserForgotPasswordCommand_WithInvalidPropertiesNotFromRepositories_Handle_ShouldReturnAllErrors()
        {
            //Arrange
            DomainEvent.Register <DomainNotification>(dn => _notifications.Add(dn));

            var invalidCommand = new UserForgotPasswordCommandBuilder()
                                 .WithEmail("abc");

            var handler = _mocker.Resolve <UserCommandHandler>();

            //Act
            handler.Handle(invalidCommand);

            //Assert
            _notifications.Should()
            .NotBeEmpty()
            .And.HaveCount(1)
            .And.Contain(n => n.Value == Domain.Main.Resources.Messages.UserForgotPasswordEmailProper);

            _mocker.GetMock <IPersonRepository>().Verify(x => x.GetByEmail(It.IsAny <string>()), Times.Never());
        }