public void SendUserActivationCommandHandler_Does_Nothing_For_Nonexistent_User()
        {
            var handler = new SendUserActivationCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new SendUserActivationCommand("*****@*****.**");

            var result = handler.Execute(command);

            result.Success.Should().BeTrue();
            _mailClient.SentMessages.Should().BeEmpty();
        }
        public void SendUserActivationCommandHandler_Sends_Email()
        {
            var handler = new SendUserActivationCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new SendUserActivationCommand("*****@*****.**");

            _context.Users.Add(new User("*****@*****.**", "test"));

            var result = handler.Execute(command);

            result.Success.Should().BeTrue();
            _mailClient.SentMessages.Should().HaveCount(1);
            _mailClient.SentMessages[0].Subject.Should().Be("Please activate your account");
            _mailClient.SentMessages[0].To.Should().Be("*****@*****.**");
        }
        public void SendUserActivationCommandHandler_Does_Nothing_For_Inactive_User()
        {
            var handler = new SendUserActivationCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new SendUserActivationCommand("*****@*****.**");
            var user    = Substitute.For <User>();

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

            _context.Users.Add(user);

            var result = handler.Execute(command);

            result.Success.Should().BeTrue();
            user.DidNotReceive().GenerateActivationCode();
            _mailClient.SentMessages.Should().BeEmpty();
        }
        public void SendUserActivationCommandHandler_Succeeds()
        {
            var handler = new SendUserActivationCommandHandler(_repository, _mailClient, new ActivationMailTemplate(_appSettings));
            var command = new SendUserActivationCommand("*****@*****.**");
            var user    = Substitute.For <User>();

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

            _context.Users.Add(user);

            var result = handler.Execute(command);

            result.Success.Should().BeTrue();
            user.Received().GenerateActivationCode();
        }