public void when_sending_receipt_with_no_dropoff_should_geocode_vehicle_position()
        {
            var orderId = Guid.NewGuid();

            using (var context = new BookingDbContext(DbName))
            {
                context.Save(new OrderStatusDetail
                {
                    OrderId          = orderId,
                    VehicleLatitude  = 45.531608,
                    VehicleLongitude = -73.622791,
                    PickupDate       = DateTime.Now,
                });
            }

            Sut.When(new SendReceipt
            {
                OrderId       = orderId,
                EmailAddress  = "*****@*****.**",
                PickupAddress = new Address
                {
                    FullAddress = "5250, rue Ferrier, Montreal, H1P 4L4",
                    Latitude    = 1.23456,
                    Longitude   = 7.890123
                },
                ClientLanguageCode = "fr"
            });

            // verify templateData (2 times for subject + body)
            TemplateServiceMock.Verify(x => x.Render(It.IsAny <string>(), It.Is <object>(o => ObjectPropertyEquals(o, "DropOffAddress", "7250 Rue du Mile End, Montréal, QC H2R 2W1"))), Times.Exactly(2));
            TemplateServiceMock.Verify(x => x.Render(It.IsAny <string>(), It.Is <object>(o => ObjectPropertyContains(o, "StaticMapUri", "?markers=color:0x1EC022%7Csize:medium%7C1.23456,7.890123&markers=color:0xFF0000%7Csize:medium%7C45.531608,-73.622791"))), Times.Exactly(2));
        }
 private void AssertTemplateValueContains(string key, string expectedValue)
 {
     // verify templateData (2 times for subject + body)
     TemplateServiceMock.Verify(x => x.Render(It.IsAny <string>(), It.Is <object>(o => ObjectPropertyContains(o, key, expectedValue))), Times.Exactly(2));
 }
        public void Setup()
        {
            base.Setup();

            _geocodingMock = new Mock <IGeocoding>();
            var taxihailNetworkServiceClientMock = new Mock <ITaxiHailNetworkServiceClient>();

            var notificationService = new NotificationService(() => new BookingDbContext(DbName),
                                                              null,
                                                              TemplateServiceMock.Object,
                                                              EmailSenderMock.Object,
                                                              ConfigurationManager,
                                                              new ConfigurationDao(() => new ConfigurationDbContext(DbName)),
                                                              new OrderDao(() => new BookingDbContext(DbName), new TestServerSettings()),
                                                              new AccountDao(() => new BookingDbContext(DbName)),
                                                              new StaticMap(),
                                                              null,
                                                              _geocodingMock.Object,
                                                              taxihailNetworkServiceClientMock.Object,
                                                              new Logger(),
                                                              new CryptographyService(WinRTCrypto.CryptographicEngine, WinRTCrypto.SymmetricKeyAlgorithmProvider, WinRTCrypto.HashAlgorithmProvider, new Logger()));

            notificationService.SetBaseUrl(new Uri("http://www.example.net"));

            Sut.Setup(new EmailCommandHandler(notificationService));

            var returnAddressValue = new Address {
                FullAddress = "full dropoff"
            };

            _geocodingMock
            .Setup(x => x.TryToGetExactDropOffAddress(It.IsAny <OrderStatusDetail>(), 45, -73, It.IsAny <Address>(), It.IsAny <string>()))
            .Returns(returnAddressValue);

            _geocodingMock
            .Setup(x => x.TryToGetExactDropOffAddress(It.Is <OrderStatusDetail>(
                                                          o => o.VehicleLatitude.GetValueOrDefault() == 45 && o.VehicleLongitude.GetValueOrDefault() == -73),
                                                      null,
                                                      null,
                                                      It.IsAny <Address>(),
                                                      It.IsAny <string>())
                   )
            .Returns(returnAddressValue);

            _geocodingMock
            .Setup(x => x.TryToGetExactDropOffAddress(
                       It.Is <OrderStatusDetail>(o => !o.VehicleLongitude.HasValue && !o.VehicleLatitude.HasValue),
                       null,
                       null,
                       It.IsAny <Address>(),
                       It.IsAny <string>())
                   )
            .Returns(new Address()
            {
                FullAddress = "hardcoded dropoff"
            });

            _geocodingMock
            .Setup(x => x.TryToGetExactDropOffAddress(
                       It.Is <OrderStatusDetail>(o => !o.VehicleLongitude.HasValue && !o.VehicleLatitude.HasValue),
                       null,
                       null,
                       null,
                       It.IsAny <string>())
                   )
            .Returns(new Address()
            {
                FullAddress = "-"
            });

            TemplateServiceMock
            .Setup(x => x.InlineCss(It.IsAny <string>()))
            .Returns(string.Empty);
        }