public async Task WhenProviderIdIsProvidedAndIsValid_TheStatusOfTheExistingRequestIsUpdated()
        {
            string pid = "someId";
            var request = new Request
            {
                ProviderId = pid,
                Status = RequestStatus.Assigned
            };
            var command = new AddRequestCommand{Request = request};

            var options = this.CreateNewContextOptions();

            using (var context = new AllReadyContext(options)) {
                context.Requests.Add(new Request {
                    ProviderId = pid,
                    Status = RequestStatus.Assigned
                });
                await context.SaveChangesAsync();
            }

            using (var context = new AllReadyContext(options)) {
                var geocoder = new Mock<IGeocoder>();
                AddRequestCommandHandler sut = new AddRequestCommandHandler(context, geocoder.Object);


                await sut.Handle(command);
            }

            using (var context = new AllReadyContext(options)) {
                var entity = context.Requests.FirstOrDefault(x => x.ProviderId == pid);
                Assert.Equal(entity.Status, RequestStatus.Assigned);
            }
        }
Exemplo n.º 2
0
        public Request ToModel(RequestViewModel requestViewModel, IMediator mediator)
        {
            var request = new Request
            {
                ProviderId = requestViewModel.ProviderId,
                ProviderData = requestViewModel.ProviderData,
                Address = requestViewModel.Address,
                City = requestViewModel.City,
                DateAdded = DateTime.UtcNow,
                Email = requestViewModel.Email,
                Name = requestViewModel.Name,
                Phone = requestViewModel.Phone,
                State = requestViewModel.State,
                Zip = requestViewModel.Zip,
                Status = RequestStatus.Unassigned,
                Latitude = requestViewModel.Latitude,
                Longitude = requestViewModel.Longitude
            };

            RequestStatus status;
            if (Enum.TryParse(requestViewModel.Status, out status))
            {
                request.Status = status;
            }

            return request;
        }
        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 WhenProviderIdIsProvidedAndIsValid_TheStatusOfTheExistingRequestIsUpdated()
        {
            string pid = "someId";
            Guid rid = Guid.NewGuid();
            var request = new Request
            {
                ProviderId = pid,
                Status = RequestStatus.Assigned
            };
            var command = new AddRequestCommandAsync
            {
                Request = request
            };

            Request returnedRequest = new Request
            {
                ProviderId = pid,
                RequestId = rid,
                Status = RequestStatus.UnAssigned
            };
            _dataAccess.Setup(x => x.GetRequestByProviderIdAsync(pid)).ReturnsAsync(returnedRequest);

            await _sut.Handle(command);

            Assert.Equal(RequestStatus.Assigned, returnedRequest.Status);
            _dataAccess.Verify(x => x.AddRequestAsync(returnedRequest));

        }
        public void NotSendSetRequstsToUnassignedCommand_WhenRequestIdsMatchExistingRequests_AndThoseRequestsDoNotHaveAStatusOfPendingConfirmation()
        {
            var request = new Request {RequestId = Guid.NewGuid(), Status = RequestStatus.Assigned};

            var mediator = new Mock<IMediator>();

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

            var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, Mock.Of<ISmsSender>(), mediator.Object);
            sut.SendSms(new List<Guid> {request.RequestId}, It.IsAny<int>());
        }
        public async Task WhenNoProviderIdIsProvided_TheStatusIsUnassignedAndIdIsNotNull()
        {
            var request = new Request();
            var command = new AddRequestCommand {Request = request};

            var geocoder = new Mock<IGeocoder>();
            AddRequestCommandHandler sut = new AddRequestCommandHandler(this.Context, geocoder.Object);
            var result = await sut.Handle(command);

            Assert.NotNull(request.RequestId);
            Assert.Equal(RequestStatus.Unassigned, request.Status);

        }
        public async void UpdateTheRequestWithTheCorrectStatus()
        {
            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.Unassigned };
            Context.Requests.Add(request);
            Context.SaveChanges();

            var message = new ChangeRequestStatusCommand { RequestId = request.RequestId, NewStatus = RequestStatus.Assigned };

            var sut = new ChangeRequestStatusCommandHandler(Context, Mock.Of<IMediator>());
            await sut.Handle(message);

            var newStatus = Context.Requests.Single(x => x.RequestId == request.RequestId).Status;
            Assert.Equal(newStatus, request.Status);
        }
        public void NotScheduleISendRequestConfirmationMessagesADayBeforeAnItineraryDate_WhenRequestIdsDoNotMatchExistingRequests()
        {
            var request = new Request { RequestId = Guid.NewGuid() };

            var backgroundJobClient = new Mock<IBackgroundJobClient>();

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

            var sut = new SendRequestConfirmationMessagesAWeekBeforeAnItineraryDate(Context, backgroundJobClient.Object, Mock.Of<ISmsSender>());
            sut.SendSms(new List<Guid> { Guid.NewGuid() }, It.IsAny<int>());

            backgroundJobClient.Verify(x => x.Create(It.IsAny<Job>(), It.IsAny<EnqueuedState>()), Times.Never);
        }
        public void NotSendRequestConfirmations_WhenRequestIdsMatchExistingRequests_AndThoseRequestsDoNotHaveAStatusOfPendingConfirmation()
        {
            var request = new Request { RequestId = Guid.NewGuid(), Status = RequestStatus.Assigned };

            var smsSender = new Mock<ISmsSender>();

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

            var sut = new SendRequestConfirmationMessagesAWeekBeforeAnItineraryDate(Context, Mock.Of<IBackgroundJobClient>(), smsSender.Object);
            sut.SendSms(new List<Guid> { request.RequestId }, It.IsAny<int>());

            smsSender.Verify(x => x.SendSmsAsync(It.IsAny<string>(), It.IsAny<string>()), Times.Never);
        }
        public void NotSendSetRequstsToUnassignedCommand_WhenRequestIdsDoNotMatchExistingRequests()
        {
            var request = new Request {RequestId = Guid.NewGuid()};

            var mediator = new Mock<IMediator>();

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

            var sut = new SendRequestConfirmationMessagesTheDayOfAnItineraryDate(Context, Mock.Of<ISmsSender>(), mediator.Object);
            sut.SendSms(new List<Guid> {Guid.NewGuid()}, It.IsAny<int>());

            mediator.Verify(x => x.Send(It.IsAny<IRequest>()), Times.Never);
        }
        public async Task WhenNoProviderIdIsProvided_TheStatusIsUnassignedAndIdIsNotNull()
        {
            var request = new Request();
            var command = new AddRequestCommandAsync
            {
                Request = request
            };

            var result = await _sut.Handle(command);

            Assert.NotNull(request.RequestId);
            Assert.Equal(RequestStatus.UnAssigned, request.Status);

        }
        public void NotSendRequestConfirmations_WhenRequestIdsDoNotMatchExistingRequests()
        {
            var request = new Request { RequestId = Guid.NewGuid() };

            var smsSender = new Mock<ISmsSender>();

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

            var sut = new SendRequestConfirmationMessagesADayBeforeAnItineraryDate(Context, Mock.Of<IBackgroundJobClient>(), smsSender.Object);
            sut.SendSms(new List<Guid> { Guid.NewGuid() }, It.IsAny<int>());

            smsSender.Verify(x => x.SendSmsAsync(It.IsAny<List<string>>(), It.IsAny<string>()), Times.Never);
        }
        public void ReturnsTrueWhenRequestExists()
        {
            const string providerRequestId = "ProviderId";

            var request = new Request { ProviderId = providerRequestId };
            Context.Requests.Add(request);
            Context.SaveChanges();

            var message = new RequestExistsByProviderIdQuery { ProviderRequestId = providerRequestId };

            var sut = new RequestExistsByProviderIdQueryHandler(Context);
            var result = sut.Handle(message);

            Assert.True(result);
        }
        public async void PublishRequestStatusChangedNotificationWithTheCorrectDataOnTheMessage()
        {
            const RequestStatus originalRequestStatus = RequestStatus.Unassigned;
            var originalRequest = new Request { RequestId = Guid.NewGuid(), Status = originalRequestStatus };
            Context.Requests.Add(originalRequest);
            Context.SaveChanges();

            var message = new ChangeRequestStatusCommand { RequestId = originalRequest.RequestId, NewStatus = RequestStatus.Assigned };

            var mediator = new Mock<IMediator>();

            var sut = new ChangeRequestStatusCommandHandler(Context, mediator.Object);
            await sut.Handle(message);

            mediator.Verify(x => x.PublishAsync(It.Is<RequestStatusChangedNotification>(y => y.RequestId == originalRequest.RequestId &&
                y.OldStatus == originalRequestStatus &&
                y.NewStatus == message.NewStatus)));
        }
        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))));
        }
        protected override void LoadTestData()
        {
            _existingRequest = new Request
            {
                Address = "1234 Nowhereville",
                City = "Seattle",
                Name = "Request unit test",
                DateAdded = DateTime.MinValue,
                EventId = 1,
                Phone = "555-555-5555",
                Email = "*****@*****.**",
                State = "WA",
                Zip = "55555",
                Latitude = 10,
                Longitude = 10
            };

            Context.Requests.Add(_existingRequest);
            Context.SaveChanges();
        }
        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));
        }
Exemplo n.º 19
0
        public void Process(RequestApiViewModel viewModel)
        {
            //since this is Hangfire job code, it needs to be idempotent, this could be re-tried if there is a failure
            var requestExists = context.Requests.Any(x => x.ProviderRequestId == viewModel.ProviderRequestId);
            if (!requestExists)
            {
                var request = new Request
                {
                    RequestId = NewRequestId(),
                    //TODO mgmccarthy: this is hard-coded for now to 1, which is HTBox Org's Id in dev b/c SampleDataGenerator always creates it first. We'll need something more robust when we go to production.
                    OrganizationId = 1,
                    ProviderRequestId = viewModel.ProviderRequestId,
                    ProviderData = viewModel.ProviderData,
                    Address = viewModel.Address,
                    City = viewModel.City,
                    DateAdded = DateTimeUtcNow(),
                    Email = viewModel.Email,
                    Name = viewModel.Name,
                    Phone = viewModel.Phone,
                    State = viewModel.State,
                    Zip = viewModel.Zip,
                    Status = RequestStatus.Unassigned,
                    Source = RequestSource.Api
                };

                //FYI, this is a web service call
                var address = geocoder.Geocode(viewModel.Address, viewModel.City, viewModel.State, viewModel.Zip, string.Empty).FirstOrDefault();
                request.Latitude = address?.Coordinates.Latitude ?? 0;
                request.Longitude = address?.Coordinates.Longitude ?? 0;

                context.Add(request);
                context.SaveChanges();

                mediator.Publish(new ApiRequestProcessedNotification { RequestId = request.RequestId });
            }   
        }
Exemplo n.º 20
0
        protected override void LoadTestData()
        {
            var req1 = new Request
            {
                RequestId = _existingRequestId1,
                Name = "New Request 1",
                Status = RequestStatus.Assigned
            };

            var req2= new Request
            {
                RequestId = _existingRequestId2,
                Name = "New Request 2",
                Status = RequestStatus.Completed
            };

            Context.Requests.Add(req1);
            Context.Requests.Add(req2);
            Context.SaveChanges();

            // We must do this so that the context change tracker is not already tracking the item when we come to attach it from out subject under test
            Context.Entry(req1).State = EntityState.Detached;
            Context.Entry(req2).State = EntityState.Detached;
        }
        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 AddRequestAsync( Request request )
        {
            _dbContext.Requests.Add(request);

            await _dbContext.SaveChangesAsync();
        }
        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 async Task WhenEitherLatitudeOrLogitudeAreProvided_DoNotChangeThem()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address = "1 Happy Street",
                City = "Happytown",
                State = "HP",
                Zip = "12345",
                Latitude = 13,
                Longitude = 14,
                Status = RequestStatus.Unassigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                    new [] { Geocoding.Google.GoogleAddressType.Country },
                    "",
                    "")},
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            var geocoder = new Mock<IGeocoder>();
            AddRequestCommandHandler sut = new AddRequestCommandHandler(this.Context, geocoder.Object);

            geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
                .Returns(new[] { address });

            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear latitude and re-test
            request.Latitude = 0;
            request.Longitude = 14;
            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(0, request.Latitude);
            Assert.Equal(14, request.Longitude);

            //Clear longitude and re-test
            request.Latitude = 13;
            request.Longitude = 0;
            await sut.Handle(new AddRequestCommand { Request = request });

            Assert.Equal(13, request.Latitude);
            Assert.Equal(0, request.Longitude);
        }
        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 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 async Task WhenLatitudeAndLogitudeAreNotProvided_SetsThemWithGeocodingAPI()
        {
            var request = new Request
            {
                ProviderId = "someId",
                Address = "1 Happy Street",
                City = "Happytown",
                State = "HP",
                Zip = "12345",
                Status = RequestStatus.UnAssigned
            };

            var address = new Geocoding.Google.GoogleAddress(
                Geocoding.Google.GoogleAddressType.Premise,
                "formatted address",
                new[] { new Geocoding.Google.GoogleAddressComponent(
                    new [] { Geocoding.Google.GoogleAddressType.Country },
                    "",
                    "")},
                new Geocoding.Location(42, 24), //This is the only part that matters: the coordinates
                null,
                false,
                Geocoding.Google.GoogleLocationType.Rooftop);

            _geocoder.Setup(g => g.Geocode(request.Address, request.City, request.State, request.Zip, string.Empty))
                .Returns(new[] { address });

            await _sut.Handle(new AddRequestCommandAsync { Request = request });

            Assert.Equal(42, request.Latitude);
            Assert.Equal(24, request.Longitude);
        }
        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."));
        }