예제 #1
0
        public void SendMessageToAssignedVolunteers()
        {
            var expectedMessage = "This is my message for all you task peeps";
            var expectedSubject = "This is my subject";
            var command = new MessageTaskVolunteersCommand
            {
                Model = new MessageTaskVolunteersModel
                {
                    TaskId = 1,
                    Message = expectedMessage,
                    Subject = expectedSubject
                }
            };

            var bus = new Mock<IMediator>();

            var handler = new MessageTaskVolunteersCommandHandler(Context, bus.Object);
            var result = handler.Handle(command);

            bus.Verify(b => b.Send(It.Is<NotifyVolunteersCommand>(notifyCommand =>
                   notifyCommand.ViewModel != null &&
                   notifyCommand.ViewModel.EmailMessage == expectedMessage &&
                   notifyCommand.ViewModel.Subject == expectedSubject &&
                   notifyCommand.ViewModel.EmailRecipients.Count() == 2 &&
                   notifyCommand.ViewModel.EmailRecipients.Contains("*****@*****.**") &&
                   notifyCommand.ViewModel.EmailRecipients.Contains("*****@*****.**")

            )), Times.Once());
        }
        public async Task SendMessageToAssignedVolunteers()
        {
            const string expectedMessage = "This is my message for all you task peeps";
            const string expectedSubject = "This is my subject";
            var command = new MessageTaskVolunteersCommand
            {
                Model = new MessageTaskVolunteersViewModel
                {
                    TaskId = 1,
                    Message = expectedMessage,
                    Subject = expectedSubject
                }
            };

            var mediator = new Mock<IMediator>();
            
            var handler = new MessageTaskVolunteersCommandHandler(Context, mediator.Object);
            await handler.Handle(command);

            mediator.Verify(b => b.SendAsync(It.Is<NotifyVolunteersCommand>(notifyCommand =>
                   notifyCommand.ViewModel != null &&
                   notifyCommand.ViewModel.EmailMessage == expectedMessage &&
                   notifyCommand.ViewModel.Subject == expectedSubject &&
                   notifyCommand.ViewModel.EmailRecipients.Count == 2 &&
                   notifyCommand.ViewModel.EmailRecipients.Contains("*****@*****.**") &&
                   notifyCommand.ViewModel.EmailRecipients.Contains("*****@*****.**")

            )), Times.Once());   
        }