Represents an itinerary for an event
        protected override void LoadTestData()
        {
            _theItinerary = new Itinerary
            {
                Id = 1
            };

            _assignedRequest = new Request
            {
                RequestId = Guid.NewGuid(),
                Status = RequestStatus.Assigned,
            };

            _notAssignedRequest = new Request
            {
                RequestId = Guid.NewGuid(),
                Status = RequestStatus.Unassigned
            };

            Context.Itineraries.Add(_theItinerary);
            Context.Requests.Add(_assignedRequest);
            Context.Requests.Add(_notAssignedRequest);
            Context.SaveChanges();

        }
        public async Task ScheduleISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDateWithTheCorrectMethodSignatureAndTheCorrectDate()
        {
            var dateTimeNow = DateTime.Today;
            var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified);

            var requestId = Guid.NewGuid();
            var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId } };
            var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified, EventId = @event.Id, Event = @event };

            Context.Requests.Add(new Request { RequestId = requestId });
            Context.Itineraries.Add(itinerary);
            Context.Events.Add(@event);
            Context.SaveChanges();

            var backgroundJobClient = new Mock<IBackgroundJobClient>();
            var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object);
            await sut.Handle(message);

            backgroundJobClient.Verify(x => x.Create(It.Is<Job>(job =>
                job.Type == typeof(ISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDate) &&
                job.Method.Name == nameof(ISendRequestConfirmationMessagesSevenDaysBeforeAnItineraryDate.SendSms) &&
                job.Args[0] == message.RequestIds &&
                (int)job.Args[1] == message.ItineraryId),
                It.Is<ScheduledState>(ss => ss.EnqueueAt.Date.AddHours(12) == itinerary.Date.Date.AddDays(-7).AddHours(12))), Times.Once);
        }
        protected override void LoadTestData()
        {
            var htb = new Organization
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>(),
                EventType = EventType.Itinerary
            };

            var itinerary = new Itinerary
            {
                Event = queenAnne,
                Name = "1st Itinerary",
                Id = 1,
                Date = new DateTime(2016, 07, 01)
            };

            var taskSignUp = new TaskSignup { Id = 1, ItineraryId = 2, TaskId = 1 };

            Context.Organizations.Add(htb);
            Context.Campaigns.Add(firePrev);
            Context.Events.Add(queenAnne);
            Context.Itineraries.Add(itinerary);
            Context.TaskSignups.Add(taskSignUp);

            Context.SaveChanges();
        }
        public async Task UpdateRequestStatusToPendingConfirmation()
        {
            var requestId = Guid.NewGuid();
            var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId } };
            var itinerary = new Itinerary { Id = 1, Date = DateTime.UtcNow };

            Context.Requests.Add(new Request { RequestId = requestId });
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var backgroundJobClient = new Mock<IBackgroundJobClient>();
            var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object);
            await sut.Handle(message);

            var result = Context.Requests.Single(x => x.RequestId == message.RequestIds.First());

            Assert.True(result.Status == RequestStatus.PendingConfirmation);
        }
        public async Task PublishInitialRequestConfirmationsSentWithCorrectValues()
        {
            var notification = new RequestsAssignedToItinerary { ItineraryId = 1, RequestIds = new List<Guid> { Guid.NewGuid() } };

            var request = new Request { RequestId = notification.RequestIds.First(), Phone = "111-111-1111" };
            var itinerary = new Itinerary { Id = notification.ItineraryId, Date = DateTime.UtcNow };

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var mediator = new Mock<IMediator>();

            var sut = new SendInitialRequestConfirmationsHandler(Context, Mock.Of<ISmsSender>(), mediator.Object);
            await sut.Handle(notification);

            mediator.Verify(x => x.PublishAsync(It.Is<InitialRequestConfirmationsSent>(y => y.RequestIds == notification.RequestIds && y.ItineraryId == itinerary.Id)));
        }
        public void SendSetRequstsToUnassignedCommandWithCorrectParameters_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsNotTheSameDateAsTheItineraryDate()
        {
            var dateTimeUtcNow = DateTime.UtcNow;

            var request = new Request {RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation};
            var itinerary = new Itinerary {Id = 1, Date = dateTimeUtcNow.Date.AddDays(1)};

            var requestIds = new List<Guid> {request.RequestId};
            var mediator = new Mock<IMediator>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, Mock.Of<ISmsSender>(), mediator.Object) {DateTimeUtcNow = () => dateTimeUtcNow.Date};
            sut.SendSms(requestIds, itinerary.Id);

            mediator.Verify(x => x.Send(It.Is<SetRequstsToUnassignedCommand>(y => y.RequestIds.Contains(request.RequestId))));
        }
        public async Task SendSmsToTheCorrectPhoneNumbersWithTheCorrectMessage()
        {
            var notification = new RequestsAssignedToItinerary { ItineraryId = 1, RequestIds = new List<Guid> { Guid.NewGuid() }};

            var requestorPhoneNumbers = new List<string> { "111-111-1111" };
            var request = new Request { RequestId = notification.RequestIds.First(), Phone = requestorPhoneNumbers.First() };
            var itinerary = new Itinerary { Id = notification.ItineraryId, Date = DateTime.UtcNow };
            var message = $@"Your request has been scheduled by allReady for {itinerary.Date.Date}. Please respond with ""Y"" to confirm this request or ""N"" to cancel this request.";

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var smsSender = new Mock<ISmsSender>();

            var sut = new SendInitialRequestConfirmationsHandler(Context, smsSender.Object, Mock.Of<IMediator>());
            await sut.Handle(notification);

            smsSender.Verify(x => x.SendSmsAsync(requestorPhoneNumbers, message));
        }
        protected override void LoadTestData()
        {
            _user = new ApplicationUser
            {
                PhoneNumber = "123",
                Email = "*****@*****.**"
            };

            _taskSignup = new TaskSignup
            {
                Id = 1,
                PreferredEmail = "*****@*****.**",
                PreferredPhoneNumber = "456",
                User = _user
            };

            _taskSignupNoContactPreferences = new TaskSignup
            {
                Id = 2,
                User = _user
            };

            _taskSignupNoContacts = new TaskSignup
            {
                Id = 3,
                User = new ApplicationUser()
            };

            _itinerary = new Itinerary
            {
                Id = 1,
                Date = _itineraryDate = new DateTime(2016, 1, 1, 10, 30, 0)
            };

            Context.Users.Add(_user);
            Context.TaskSignups.Add(_taskSignup);
            Context.TaskSignups.Add(_taskSignupNoContactPreferences);
            Context.TaskSignups.Add(_taskSignupNoContacts);
            Context.Itineraries.Add(_itinerary);
            Context.SaveChanges();
        }
        public async Task ScheduleISendRequestConfirmationMessagesAWeekBeforeAnItineraryDateWithTheCorrectMethodSignatureAndTheCorrectDate()
        {
            var requestId = Guid.NewGuid();
            var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId } };
            var itinerary = new Itinerary { Id = 1, Date = DateTime.UtcNow };

            Context.Requests.Add(new Request { RequestId = requestId });
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();
            
            var backgroundJobClient = new Mock<IBackgroundJobClient>();
            var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object);
            await sut.Handle(message);

            backgroundJobClient.Verify(x => x.Create(It.Is<Job>(job =>
                job.Type == typeof(ISendRequestConfirmationMessagesAWeekBeforeAnItineraryDate) &&
                job.Method.Name == nameof(ISendRequestConfirmationMessagesAWeekBeforeAnItineraryDate.SendSms) &&
                job.Args[0] == message.RequestIds &&
                (int)job.Args[1] == message.ItineraryId),
                It.Is<ScheduledState>(ss => ss.EnqueueAt.Date.AtNoon() == itinerary.Date.AddDays(-7).AtNoon())), Times.Once);
        }
        public void ScheduleISendRequestConfirmationMessagesADayBeforeAnItineraryDateWithCorrectParameters_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsLessThanSevenDaysBeforeTheItineraryDate()
        {
            var dateTimeUtcNow = DateTime.UtcNow;

            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeUtcNow.Date.AddDays(1) };

            var requestIds = new List<Guid> { request.RequestId };
            var backgroundJobClient = new Mock<IBackgroundJobClient>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesAWeekBeforeAnItineraryDate(Context, backgroundJobClient.Object, Mock.Of<ISmsSender>()) { DateTimeUtcNow = () => dateTimeUtcNow.Date };
            sut.SendSms(requestIds, itinerary.Id);

            backgroundJobClient.Verify(x => x.Create(It.Is<Job>(job =>
                job.Type == typeof(ISendRequestConfirmationMessagesADayBeforeAnItineraryDate) &&
                job.Method.Name == nameof(ISendRequestConfirmationMessagesADayBeforeAnItineraryDate.SendSms) &&
                job.Args[0] == requestIds &&
                (int)job.Args[1] == itinerary.Id),
                It.Is<ScheduledState>(ss => ss.EnqueueAt.Date.AtNoon() == itinerary.Date.AddDays(-1).AtNoon())), Times.Once);
        }
        public async Task UpdateRequestStatusToPendingConfirmation()
        {
            var dateTimeNow = DateTime.Today;
            var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified);

            var requestId = Guid.NewGuid();
            var message = new InitialRequestConfirmationsSent { ItineraryId = 1, RequestIds = new List<Guid> { requestId }};
            var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified, EventId = @event.Id, Event = @event };

            Context.Requests.Add(new Request { RequestId = requestId });
            Context.Itineraries.Add(itinerary);
            Context.Events.Add(@event);
            Context.SaveChanges();

            var backgroundJobClient = new Mock<IBackgroundJobClient>();

            var sut = new InitialRequestConfirmationsSentHandler(Context, backgroundJobClient.Object);
            await sut.Handle(message);

            var result = Context.Requests.Single(x => x.RequestId == message.RequestIds.First());

            Assert.True(result.Status == RequestStatus.PendingConfirmation);
        }
        public void SendRequestConfirmationsToTheCorrectPhoneNumberWithTheCorrectMessage_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsTheSameDateAsTheItineraryDate()
        {
            var dateTimeNow = DateTime.Today;
            var dateTimeNowUnspecified = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Unspecified);
            var dateTimeUtcNow = DateTime.SpecifyKind(dateTimeNow, DateTimeKind.Utc);

            var requestorPhoneNumbers = new List<string> { "111-111-1111" };

            var @event = new Event { Id = 1, TimeZoneId = "Eastern Standard Time" };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeNowUnspecified.Date, EventId = @event.Id, Event = @event };
            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation, Phone = requestorPhoneNumbers[0] };

            var requestIds = new List<Guid> { request.RequestId };
            var smsSender = new Mock<ISmsSender>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.Events.Add(@event);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, smsSender.Object, Mock.Of<IMediator>())
            {
                DateTimeUtcNow = () => dateTimeUtcNow.Date
            };
            sut.SendSms(requestIds, itinerary.Id);

            smsSender.Verify(x => x.SendSmsAsync(requestorPhoneNumbers, "sorry you couldn't make it, we will reschedule."));
        }
        protected override void LoadTestData()
        {
            var htb = new Organization
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Id = 1,
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = new Location { Id = 1 },
                RequiredSkills = new List<EventSkill>(),
                EventType = EventType.Itinerary
            };

            var itinerary = new Itinerary
            {
                Event = queenAnne,
                Name = "1st Itinerary",
                Id = 1,
                Date = new DateTime(2016, 07, 01)
            };

            var task = new AllReadyTask
            {
                Id = 1,
                Event = queenAnne,
                Name = "A Task",
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 7, 4, 18, 0, 0).ToUniversalTime()
            };

            var user = new ApplicationUser
            {
                Id = Guid.NewGuid().ToString(),
                Email = "*****@*****.**"
            };

            var taskSignup = new TaskSignup
            {
                Id = 1,
                User = user,
                Task = task,
                Itinerary = itinerary
            };

            var request = new Request
            {
                RequestId = Guid.NewGuid(),
                Name = "Request 1",
                Address = "Street Name 1",
                City = "Seattle"
            };

            var itineraryReq = new ItineraryRequest
            {
                Request = request,
                Itinerary = itinerary
            };
            
            Context.Organizations.Add(htb);
            Context.Campaigns.Add(firePrev);
            Context.Events.Add(queenAnne);
            Context.Itineraries.Add(itinerary);
            Context.Tasks.Add(task);
            Context.Users.Add(user);
            Context.Requests.Add(request);
            Context.ItineraryRequests.Add(itineraryReq);
            Context.TaskSignups.Add(taskSignup);
            Context.SaveChanges();
        }
        public void NotSendRequestConfirmations_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsLessThanSevenDaysBeforeTheItineraryDate()
        {
            var dateTimeUtcNow = DateTime.UtcNow;

            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeUtcNow.Date.AddDays(1) };

            var backgroundJobClient = new Mock<IBackgroundJobClient>();
            var smsSender = new Mock<ISmsSender>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesAWeekBeforeAnItineraryDate(Context, backgroundJobClient.Object, smsSender.Object) { DateTimeUtcNow = () => dateTimeUtcNow.Date };
            sut.SendSms(new List<Guid> { request.RequestId }, itinerary.Id);

            smsSender.Verify(x => x.SendSmsAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
        }
        public void SendRequestConfirmationsToTheCorrectPhoneNumbersWithTheCorrectMessage_WhenRequestIdsMatchExistingRequests_AndThoseRequestsArePendingConfirmation_AndTodayIsEqualToOrGreaterThanSevenDaysBeforeTheItineraryDate()
        {
            var dateTimeUtcNow = DateTime.UtcNow;

            var requestorPhoneNumbers = new List<string> { "111-111-1111" };
            
            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation, Phone = requestorPhoneNumbers[0] };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeUtcNow.Date.AddDays(8) };

            var requestIds = new List<Guid> { request.RequestId };
            var smsSender = new Mock<ISmsSender>();
            var backgroundJobClient = new Mock<IBackgroundJobClient>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesAWeekBeforeAnItineraryDate(Context, backgroundJobClient.Object, smsSender.Object) { DateTimeUtcNow = () => dateTimeUtcNow.Date };
            sut.SendSms(requestIds, itinerary.Id);

            var message = $@"Your request has been scheduled by allReady for {itinerary.Date.Date}. Please response with ""Y"" to confirm this request or ""N"" to cancel this request.";
            smsSender.Verify(x => x.SendSmsAsync(requestorPhoneNumbers, message), Times.Once);
        }
        protected override void LoadTestData()
        {
            var seattlePostalCode = "98117";
            var seattle = new Location
            {
                Address1 = "123 Main Street",
                Address2 = "Unit 2",
                City = "Seattle",
                PostalCode = seattlePostalCode,
                Country = "USA",
                State = "WA",
                Name = "Organizer name",
                PhoneNumber = "555-555-5555"
            };

            var htb = new Organization
            {
                Name = "Humanitarian Toolbox",
                LogoUrl = "http://www.htbox.org/upload/home/ht-hero.png",
                WebUrl = "http://www.htbox.org",
                Campaigns = new List<Campaign>()
            };

            var firePrev = new Campaign
            {
                Name = "Neighborhood Fire Prevention Days",
                ManagingOrganization = htb
            };
            htb.Campaigns.Add(firePrev);

            var queenAnne = new Event
            {
                Name = "Queen Anne Fire Prevention Day",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = seattle,
                RequiredSkills = new List<EventSkill>(),
                EventType = EventType.Itinerary
            };

            var rallyEvent = new Event
            {
                Name = "Queen Anne Fire Prevention Day Rally",
                Campaign = firePrev,
                CampaignId = firePrev.Id,
                StartDateTime = new DateTime(2015, 7, 4, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2015, 12, 31, 15, 0, 0).ToUniversalTime(),
                Location = seattle,
                RequiredSkills = new List<EventSkill>(),
                EventType = EventType.Rally
            };

            var task1 = new AllReadyTask
            {
                Event = rallyEvent,
                Name = "Task1",
                IsLimitVolunteers = false,
                StartDateTime = new DateTime(2016, 7, 5, 10, 0, 0).ToUniversalTime(),
                EndDateTime = new DateTime(2016, 7, 5, 15, 0, 0).ToUniversalTime()
            };

            var request1 = new Request
            {
                RequestId = Guid.NewGuid(),
                Name = "Request1",
                Status = RequestStatus.Assigned,
                Latitude = 50.768,
                Longitude = 0.2905
            };

            var request2 = new Request
            {
                RequestId = Guid.NewGuid(),
                Name = "Request2",
                Status = RequestStatus.Assigned,
                Latitude = 50.768,
                Longitude = 0.2905
            };

            var request3 = new Request
            {
                RequestId = Guid.NewGuid(),
                Name = "Request3",
                Status = RequestStatus.Assigned,
                Latitude = 50.768,
                Longitude = 0.2905
            };

            var itinerary1 = new Itinerary
            {
                Date = new DateTime(2015, 07, 5),
                Name = "Itinerary1",
                Event = queenAnne
            };

            var itinerary2 = new Itinerary
            {
                Date = new DateTime(2016, 08, 01),
                Name = "Itinerary2",
                Event = queenAnne
            };

            var itineraryReq1 = new ItineraryRequest
            {
                RequestId = request1.RequestId,
                Itinerary = itinerary1
            };

            var itineraryReq2 = new ItineraryRequest
            {
                RequestId = request2.RequestId,
                Itinerary = itinerary1
            };

            var itineraryReq3 = new ItineraryRequest
            {
                RequestId = request3.RequestId,
                Itinerary = itinerary2
            };

            var user1 = new ApplicationUser
            {
                Id = Guid.NewGuid().ToString(),
                UserName = "******"
            };

            var taskSignup = new TaskSignup
            {
                Itinerary = itinerary1,
                Task = task1,
            };
            Context.Locations.Add(seattle);
            Context.Requests.AddRange(request1, request2, request3);
            Context.Itineraries.AddRange(itinerary1, itinerary2);
            Context.ItineraryRequests.AddRange(itineraryReq1, itineraryReq2, itineraryReq3);
            Context.Organizations.Add(htb);
            Context.Events.Add(queenAnne);
            Context.Events.Add(rallyEvent);
            Context.Users.Add(user1);
            Context.Tasks.Add(task1);
            Context.TaskSignups.Add(taskSignup);

            Context.SaveChanges();
        }
        public void SendRequestConfirmationsWithCorrectParameters_WhenRequestIdsMatchExistingRequests_AndThoseRequestsHaveAStatusOfPendingConfirmation_AndTodayIsTheSameDateAsTheItineraryDate()
        {
            var dateTimeUtcNow = DateTime.UtcNow;

            var requestorPhoneNumbers = new List<string> { "111-111-1111" };

            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.PendingConfirmation, Phone = requestorPhoneNumbers[0] };
            var itinerary = new Itinerary { Id = 1, Date = dateTimeUtcNow.Date };

            var requestIds = new List<Guid> { request.RequestId };
            var smsSender = new Mock<ISmsSender>();

            Context.Requests.Add(request);
            Context.Itineraries.Add(itinerary);
            Context.SaveChanges();

            var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, smsSender.Object, Mock.Of<IMediator>()) { DateTimeUtcNow = () => dateTimeUtcNow.Date };
            sut.SendSms(requestIds, itinerary.Id);

            smsSender.Verify(x => x.SendSmsAsync(requestorPhoneNumbers, "sorry you couldn't make it, we will reschedule."));
        }
        public async Task AddNewEndLocationWhenUseStartAddressAsEndAddressIsUnchecked()
        {
            const string startAddress = "#1 Address";
            const string endAddress = "#2 Address";

            var initialItinerary = new Itinerary
            {
                Id = 2,
                EventId = 1,
                Name = "SUT Itinerary",
                Date = DateTime.Now,
                UseStartAddressAsEndAddress = true,
                StartLocation = new Location
                {
                    Address1 = startAddress
                }
            };
            initialItinerary.EndLocation = initialItinerary.StartLocation;
            Context.Itineraries.Add(initialItinerary);
            Context.SaveChanges();
            var command = new EditItineraryCommand
            {
                Itinerary = new ItineraryEditViewModel
                {
                    Id = initialItinerary.Id,
                    Date = initialItinerary.Date,
                    UseStartAddressAsEndAddress = false,
                    StartAddress1 = initialItinerary.StartLocation.Address1,
                    EndAddress1 = endAddress
                }
            };

            var sut = new EditItineraryCommandHandler(Context);
            var result = await sut.Handle(command);

            var resultItinerary = Context.Itineraries
                .Include(i => i.StartLocation)
                .Include(i => i.EndLocation)
                .Single(i => i.Id == result);
            Assert.False(resultItinerary.UseStartAddressAsEndAddress);
            Assert.NotNull(resultItinerary.StartLocation);
            Assert.NotNull(resultItinerary.EndLocation);
            Assert.NotSame(resultItinerary.StartLocation, resultItinerary.EndLocation);
            Assert.Equal(startAddress, resultItinerary.StartLocation.Address1);
            Assert.Equal(endAddress, resultItinerary.EndLocation.Address1);
        }