Ejemplo n.º 1
0
        public void CountriesCRUDTest()
        {
            var sessionFactory = SessionFactory.CreateSessionFactory(true);

            const string country1 = "CountryName1";
            const string country2 = "CountryName2";

            var countries = new List<Country>
                                          { TestEntities.CreateCountry(10000, "EnglishName1", country1),
                                            TestEntities.CreateCountry(10001, "EnglishName2", country2)
                                          };
            var session = SessionManager.CurrentSession;
            var repository = new CountryRepository(session);
            repository.SaveUpdateCountries(countries);

            var fromDb = repository.GetAll();
            Assert.True(fromDb.ToList().Count(c => c.CountryName == country1 || c.CountryName == country2) == 2 );

            var updateCountry = countries.First();

            const string country3 = "CountryName3";
            const string englishName3 = "EnglishName3";
            updateCountry.EnglishName = englishName3;
            updateCountry.CountryName = country3;

            repository.SaveUpdate(updateCountry);

            var updatedCountry = repository.GetById(updateCountry.CountryId);
            Assert.True(updatedCountry.CountryName == updateCountry.CountryName);
            Assert.True(updatedCountry.EnglishName == updateCountry.EnglishName);

            foreach (var country in countries)
            {
                repository.Delete(country);
            }
            session.Flush();

            fromDb = repository.GetAll();
            Assert.True(fromDb.ToList().Count(c => c.CountryName == country1 || c.CountryName == country2) == 0);
        }
        public override void MigrateWorldDetails()
        {
            var repository = new CountryRepository(Session);
            var wsCountries = repository.GetAll().ToList();

            var countryList = ReadWorldDetails();

            foreach (var htCountry in countryList)
            {
                var country = wsCountries.FirstOrDefault(c => c.HtCountryId == htCountry.LeagueID);
                if (country == null)
                {
                    country = new Country { IsNewValue = true };
                    wsCountries.Add(country);
                }
                country.HtCountryId = htCountry.LeagueID;
                country.CountryName = htCountry.LeagueName;
                country.EnglishName = htCountry.EnglishName;
                country.SeasonOffset = htCountry.SeasonOffset;
                country.NumberOfLevels = htCountry.NumberOfLevels;
                country.CountryInWhoScored = htCountry.LeagueInWhoScored;
                country.SeriesMatchTime = DateTime.Parse(htCountry.SeriesMatchDate).TimeOfDay;
                country.SeriesMatchWeekDay = (short)DateTime.Parse(htCountry.SeriesMatchDate).DayOfWeek;
                if (htCountry.SeriesIdList != null)
                    country.AddSeriesIdRange(htCountry.SeriesIdList);
            }

            repository.SaveUpdateCountries(wsCountries);
        }