예제 #1
0
        public void LoadMsaData()
        {
            //Load Msa Data
            var csvReader = GetReaderForUrl(MsaDataUrl);

            var msaRecords = new List <MsaData>();

            using (var csv = csvReader)
            {
                csv.Read();
                csv.ReadHeader();
                while (csv.Read())
                {
                    try
                    {
                        var record = csv.GetRecord <MsaData>();
                        msaRecords.Add(record);
                    }
                    catch (Exception e)
                    {
                        var x = e;
                        csv.Read();
                    }
                }
            }

            var msas = msaRecords.Select(x => new MsaEntity
            {
                Cbsa            = x.CBSA,
                Mdiv            = x.MDIV,
                Lsad            = x.LSAD,
                PopEstimate2014 = x.POPESTIMATE2014,
                PopEstimate2015 = x.POPESTIMATE2015,
                Name            = x.NAME
            })
                       .ToList();

            _context.RemoveRange(_context.Msas.ToList());
            _context.Msas.AddRange(msas);

            _context.SaveChanges();
        }
예제 #2
0
        public void GetLocationShouldPulNo()
        {
            var options = new DbContextOptionsBuilder <ZipDbContext>()
                          .UseInMemoryDatabase(databaseName: "my_db")
                          .Options;

            string zip  = "90403";
            string name = "LA";
            string alt  = "54321";

            // Run the test against one instance of the context
            using (var context = new ZipDbContext(options))
            {
                context.Cbsas.Add(new CbsaEntity
                {
                    Zip  = zip,
                    Cbsa = "12345"
                });

                context.Msas.Add(new MsaEntity
                {
                    Cbsa            = alt,
                    Mdiv            = "12345",
                    Lsad            = "Metropolitan Statistical Area",
                    PopEstimate2014 = "100",
                    PopEstimate2015 = "200",
                    Name            = name
                });

                context.SaveChanges();

                LocationService service = new LocationService(context);

                List <Location> locationData = service.GetLocationData(zip);

                Assert.True(locationData.Any(x => x.Cbsa == alt));
            }
        }