Exemplo n.º 1
0
 public AddressRepository(ILogger <AddressRepository> logger,
                          LouisvilleDemographicsContext louisvilleDemographicsContext,
                          PvaSettings pvaSettings,
                          ITimeService timeService)
 {
     _logger = logger;
     _louisvilleDemographicsContext = louisvilleDemographicsContext;
     _pvaSettings = pvaSettings;
     _timeService = timeService;
 }
Exemplo n.º 2
0
 public PvaAddressLookup(ILogger <PvaAddressLookup> logger,
                         IAddressRepository addressRepository,
                         PvaSettings settings,
                         IAddressParser addressParser)
 {
     _logger            = logger;
     _addressRepository = addressRepository;
     _settings          = settings;
     _addressParser     = addressParser;
 }
        public async Task Get_ReturnsNonExpiredAttributes()
        {
            const string nowString        = "10/31/2018 10:54:30";
            const int    refreshAfterDays = 10;

            var address = new Address
            {
                Number     = 123,
                Street     = "MAIN",
                Tag        = "ST",
                Attributes = new List <AddressAttribute>
                {
                    // 11 days old. Expired.
                    new AddressAttribute {
                        Source = "PVA", VerificationTime = DateTime.Parse("10/20/2018 10:00:00"), AttributeName = "owner", AttributeValue = "JOHN DOE"
                    },
                    // 10 days old. Expired.
                    new AddressAttribute {
                        Source = "PVA", VerificationTime = DateTime.Parse("10/21/2018 10:00:00"), AttributeName = "owner", AttributeValue = "JANE DOE"
                    },
                    // 9 days old, but not the newest.
                    new AddressAttribute {
                        Source = "PVA", VerificationTime = DateTime.Parse("10/22/2018 10:00:00"), AttributeName = "owner", AttributeValue = "SAM DOE"
                    },
                    // 9 days old, should be used.
                    new AddressAttribute {
                        Source = "PVA", VerificationTime = DateTime.Parse("10/22/2018 10:00:01"), AttributeName = "owner", AttributeValue = "JUDY DOE"
                    }
                }
            };

            var options = new DbContextOptionsBuilder <LouisvilleDemographicsContext>()
                          .UseInMemoryDatabase(databaseName: "Test_Address_Attribute_Expiration")
                          .Options;

            var louisvilleDemographicsContext = new LouisvilleDemographicsContext(options);

            louisvilleDemographicsContext.Addresses.Add(address);
            louisvilleDemographicsContext.SaveChanges();

            var pvaSettings = new PvaSettings {
                RefreshAfterDays = refreshAfterDays
            };

            var timeService = new Mock <ITimeService>();

            timeService.SetupGet(t => t.Now).Returns(DateTime.Parse(nowString));

            var addressRepository = new AddressRepository(null, louisvilleDemographicsContext, pvaSettings, timeService.Object);

            var result = await addressRepository.Get(address.Number, address.Direction, address.Street, address.Tag);

            Assert.Equal("JUDY DOE", result.Owner);
        }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc()
            .SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

            var louisvilleDemographicsConnection = Configuration.GetConnectionString("LouisvilleDemographics");

            services.AddDbContext <LouisvilleDemographicsContext>(options => options.UseSqlServer(louisvilleDemographicsConnection));

            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new Info {
                    Title = "The Ville Skill API", Version = "v1"
                });
            });

            var alexaSettings = new AlexaSettings();

            Configuration.Bind("AlexaSettings", alexaSettings);
            services.AddSingleton(alexaSettings);

            var pvaSettings = new PvaSettings();

            Configuration.Bind("PVASettings", pvaSettings);
            services.AddSingleton(pvaSettings);

            var sheriffSettings = new SheriffSettings();

            Configuration.Bind("SheriffSettings", sheriffSettings);
            services.AddSingleton(sheriffSettings);

            var eventfulSettings = new EventfulSettings();

            Configuration.Bind("EventfulSettings", eventfulSettings);
            services.AddSingleton(eventfulSettings);

            var cacheSettings = new CacheSettings();

            Configuration.Bind("CacheSettings", cacheSettings);
            services.AddSingleton(cacheSettings);

            var googleMapsSettings = new GoogleMapsSettings();

            Configuration.Bind("GoogleMapsSettings", googleMapsSettings);
            services.AddSingleton(googleMapsSettings);

            switch (cacheSettings.Type)
            {
            case CacheType.None:
                services.AddSingleton <IDistributedCache>(new NoCacheDistributedCache());
                break;

            case CacheType.InMemory:
                services.AddDistributedMemoryCache();
                break;
                //case CacheType.Redis:
                //    services.AddDistributedRedisCache(option =>
                //    {
                //        option.Configuration = cacheSettings.Redis;
                //        option.InstanceName = $"{_configuration["ApplicationName"]}:{_hostingEnvironment.EnvironmentName}:";
                //    });
                //    break;
            }
            services.AddSingleton <ICacheAdapter, CacheAdapter>();

            services.AddScoped <ISkillRequestHandler, SkillRequestHandler>();

            services.AddScoped <IAddressParser, AddressParser>();

            services.AddScoped <IPvaAddressLookup, PvaAddressLookup>();

            services.AddScoped <IAddressRepository, AddressRepository>();

            services.AddScoped <ITagRepository, TagRepository>();

            services.AddScoped <IZipCodeRepository, ZipCodeRepository>();

            services.AddHttpClient <IDeviceApiHttpClient, DeviceApiHttpClient>();

            services.AddHttpClient <IEventfulHttpClient, EventfulHttpClient>();

            services.AddSingleton <IMapImageUrlGenerator, MapImageUrlGenerator>();

            services.AddSingleton <ITimeService, TimeService>();

            services.AddScoped <IPhoneticAddressHelper, PhoneticAddressHelper>();
        }