public void GetNamesAsyncTest()
        {
            string hrefGB = @"http://www.thomas-bayer.com:80/restnames/namesincountry.groovy?country=Great+Britain";
            var sut = new NameService();

            List<BabyName> names = sut.GetNamesAsync(hrefGB).Result;

            Assert.IsTrue(names.Any());
        }
        public void ImportCountriesAndNamesIntoDB()
        {
            var countryService = new CountryService();
            var nameService = new NameService();

            Trace.WriteLine("Create DB if not exists");
            System.Data.Entity.Database.SetInitializer(new DBInitializer());

            Trace.WriteLine("Start DB sync");

            List<Country> countries = countryService.GetCountriesAsync().Result;

            using (var dbContext = new DBContext())
            {
                dbContext.BulkInsert(countries);
                dbContext.SaveChanges();

                int totalCountries = countries.Count();
                int countriesCount = 0;
                Trace.WriteLine($"DB sync: {totalCountries} countries downloaded");

                foreach (Country country in dbContext.Countries)
                {
                    Trace.WriteLine($"DB sync: start country {country.Name} ({countriesCount++} of {totalCountries})");
                    BabyName[] names = nameService.GetNamesAsync(country.HRef).Result.ToArray();

                    foreach (BabyName name in names)
                    {
                        name.CountryId = country.Id;
                    }

                    using (var nameContext = new DBContext())
                    {
                        nameContext.BulkInsert(names);
                        nameContext.SaveChanges();
                    }

                    Trace.WriteLine($"DB sync: end country {country.Name}: {names.Count()} names downloaded");
                }
            }

            Trace.WriteLine("End DB sync");
        }