public void DeactivateUserCommandHandler_Succeeds()
        {
            var handler = new DeactivateUserCommandHandler(_repository);
            var command = new DeactivateUserCommand("*****@*****.**", "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 result = handler.Execute(command);

            result.Errors.Should().BeEmpty();
            user.Received().Deactivate();
            user.DidNotReceive().DeactivationFailed();
        }
        public void DeactivateUserCommandHandler_Throws_Exception_For_Invalid_User()
        {
            var handler = new DeactivateUserCommandHandler(_repository);
            var command = new DeactivateUserCommand("*****@*****.**", "test");
            var user    = Substitute.For <User>();

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

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

            _context.Users.Add(user);

            commandAction.Should().Throw <InvalidOperationException>();
            user.DidNotReceive().Deactivate();
            user.DidNotReceive().DeactivationFailed();
        }
        public void DeactivateUserCommandHandler_Fails_For_Wrong_Password()
        {
            var handler = new DeactivateUserCommandHandler(_repository);
            var command = new DeactivateUserCommand("*****@*****.**", "wrong");
            var user    = Substitute.For <User>();

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

            _context.Users.Add(user);

            var result = handler.Execute(command);

            result.Errors.Should().HaveCount(1);
            result.Errors[0].Expression.ToString().Should().Be("p => p.Password");
            result.Errors[0].Message.Should().Be("Invalid password");
            user.DidNotReceive().Deactivate();
            user.Received().DeactivationFailed();
        }