Exemplo n.º 1
0
        public void ChangeUserEmailCommandHandler_Fails_For_Existing_New_Email()
        {
            var handler = new ChangeUserEmailCommandHandler(_repository, _mailClient, new ConfirmEmailMailTemplate(_appSettings));
            var command = new ChangeUserEmailCommand("*****@*****.**", "test", "*****@*****.**");
            var user    = Substitute.For <User>();

            user.Email.Returns("*****@*****.**");
            user.Password.Returns(new Password("test"));
            user.Status.Returns(UserStatus.Active);

            _context.Users.Add(user);

            var user2 = Substitute.For <User>();

            user2.Email.Returns("*****@*****.**");

            _context.Users.Add(user2);

            var result = handler.Execute(command);

            result.Errors.Should().HaveCount(1);
            result.Errors[0].Expression.ToString().Should().Be("c => c.NewEmail");
            result.Errors[0].Message.Should().Be("Email address already exists");
            user.DidNotReceive().RequestEmailChange(Arg.Any <string>());
            user.Received().RequestEmailChangeFailed();
            _mailClient.SentMessages.Should().BeEmpty();
        }
Exemplo n.º 2
0
        public void ChangeUserEmailCommandHandler_Sends_Email()
        {
            var handler = new ChangeUserEmailCommandHandler(_repository, _mailClient, new ConfirmEmailMailTemplate(_appSettings));
            var command = new ChangeUserEmailCommand("*****@*****.**", "test", "*****@*****.**");
            var user    = new User("*****@*****.**", "test");

            user.Activate();
            _context.Users.Add(user);

            handler.Execute(command);

            _mailClient.SentMessages.Should().HaveCount(1);
            _mailClient.SentMessages[0].Subject.Should().Be("Please confirm your email address");
            _mailClient.SentMessages[0].To.Should().Be("*****@*****.**");
        }
Exemplo n.º 3
0
        public void ChangeUserEmailCommandHandler_Succeeds()
        {
            var handler = new ChangeUserEmailCommandHandler(_repository, _mailClient, new ConfirmEmailMailTemplate(_appSettings));
            var command = new ChangeUserEmailCommand("*****@*****.**", "test", "*****@*****.**");
            var user    = Substitute.For <User>();

            user.Email.Returns("*****@*****.**");
            user.NewEmailConfirmationCode.Returns(999999);
            user.Password.Returns(new Password("test"));
            user.Status.Returns(UserStatus.Active);

            _context.Users.Add(user);

            handler.Execute(command);

            user.Received().RequestEmailChange("*****@*****.**");
            user.DidNotReceive().RequestEmailChangeFailed();
        }
Exemplo n.º 4
0
        public void ChangeUserEmailCommandHandler_Throws_Exception_For_Invalid_User()
        {
            var handler = new ChangeUserEmailCommandHandler(_repository, _mailClient, new ConfirmEmailMailTemplate(_appSettings));
            var command = new ChangeUserEmailCommand("*****@*****.**", "test", "*****@*****.**");
            var user    = Substitute.For <User>();

            user.Email.Returns("*****@*****.**");
            user.Password.Returns(new Password("test"));
            user.Status.Returns(UserStatus.Inactive);

            _context.Users.Add(user);

            Action commandAction = () => {
                var result = handler.Execute(command);
            };

            commandAction.Should().Throw <InvalidOperationException>();

            _mailClient.SentMessages.Should().BeEmpty();
        }
Exemplo n.º 5
0
 internal void InstantiateChangeUserEmailCommandHandler()
 {
     ChangeUserEmailCommandHandler = new ChangeUserEmailCommandHandler(DomainEvents, EventStore);
 }