Exemplo n.º 1
0
        public void ActivateUserCommandHandler_Succeeds()
        {
            var handler = new ActivateUserCommandHandler(_repository);
            var command = new ActivateUserCommand("*****@*****.**", "999999");
            var user    = Substitute.For <User>();

            user.Email.Returns("*****@*****.**");
            user.ActivationCode.Returns(999999);
            user.Status.Returns(UserStatus.New);

            _context.Users.Add(user);

            var result = handler.Execute(command);

            result.Errors.Should().BeEmpty();
            user.Received().Activate();
            user.DidNotReceive().ActivationFailed();
        }
Exemplo n.º 2
0
        public void ActivateUserCommandHandler_Fails_For_Inactive_User()
        {
            var handler = new ActivateUserCommandHandler(_repository);
            var command = new ActivateUserCommand("*****@*****.**", "999999");
            var user    = Substitute.For <User>();

            user.Email.Returns("*****@*****.**");
            user.ActivationCode.Returns(999999);
            user.Status.Returns(UserStatus.Inactive);

            _context.Users.Add(user);

            var result = handler.Execute(command);

            result.Errors.Should().HaveCount(1);
            result.Errors[0].Expression.ToString().Should().Be("p => p.ActivationCode");
            result.Errors[0].Message.Should().Be("This activation code is invalid");
            user.DidNotReceive().Activate();
            user.Received().ActivationFailed();
        }