public void Assure_holidays_can_be_Saved()
        {
            var norwegianConstitutionDay = new Holiday() {Date = new DateTime(2010, 05, 17), Description = "17. Mai"};
            dbRepo.Save(norwegianConstitutionDay);

            RecreateSessionFactory();
            var newDbRepo = new HolidayDatabaseRepository(sessionFactory);
            var holidays = newDbRepo.Get(new AllSpecification<Holiday>());

            holidays.First().Date.ShouldBe(norwegianConstitutionDay.Date);
            holidays.First().Description.ShouldBe(norwegianConstitutionDay.Description);
        }
 public void Save(IEnumerable<Holiday> holidays)
 {
     HolidayDatabaseRepository repo = new HolidayDatabaseRepository(DefaultSessionFactory.Instance);
     try
     {
         repo.Save(holidays);
     }
     catch (Exception exception)
     {
         ILog logger = new Logger(new LogEntryDatabaseRepository(DefaultSessionFactory.Instance));
         logger.WriteEntry(new ErrorLogEntry(this.GetType().ToString(), exception.ToString()));
     }
 }
        public IEnumerable<Holiday> Get(Specification<Holiday> specification)
        {
            HolidayDatabaseRepository repo = new HolidayDatabaseRepository(DefaultSessionFactory.Instance);
            IEnumerable<Holiday> result = new List<Holiday>();
            try
            {
                result = repo.Get(specification);
            }
            catch (Exception exception)
            {
                ILog logger = new Logger(new LogEntryDatabaseRepository(DefaultSessionFactory.Instance));
                logger.WriteEntry(new ErrorLogEntry(this.GetType().ToString(), exception.ToString()));
            }

            return result;
        }
        public void Assure_repository_can_save_multiple_holidays()
        {
            var norwegianConstitutionDay = new Holiday() { Date = new DateTime(2010, 05, 17), Description = "17. Mai" };
            var someOldDate = new Holiday() {Date = new DateTime(10, 10, 10), Description = "This is an old old date"};
            dbRepo.Save(norwegianConstitutionDay);
            dbRepo.Save(someOldDate);

            RecreateSessionFactory();
            var newDbRepo = new HolidayDatabaseRepository(sessionFactory);
            var holidays = newDbRepo.Get(new AllSpecification<Holiday>());

            holidays.Count().ShouldBe(2);

            holidays.First().Date.ShouldBe(norwegianConstitutionDay.Date);
            holidays.First().Description.ShouldBe(norwegianConstitutionDay.Description);

            holidays.ElementAt(1).Date.ShouldBe(someOldDate.Date);
            holidays.ElementAt(1).Description.ShouldBe(someOldDate.Description);
        }
        public void Assure_saving_list_replaces_data_in_repository()
        {
            var norwegianConstitutionDay = new Holiday() { Date = new DateTime(2010, 05, 17), Description = "17. Mai" };
            var someOldDate = new Holiday() { Date = new DateTime(10, 10, 10), Description = "This is an old old date" };

            var firstList = new List<Holiday>() { norwegianConstitutionDay };
            var secondList = new List<Holiday>() { someOldDate };

            dbRepo.Save(firstList);
            dbRepo.Save(secondList);

            RecreateSessionFactory();
            var newDbRepo = new HolidayDatabaseRepository(sessionFactory);
            var holidays = newDbRepo.Get(new AllSpecification<Holiday>());

            holidays.Count().ShouldBe(1);

            holidays.First().Date.ShouldBe(someOldDate.Date);
            holidays.First().Description.ShouldBe(someOldDate.Description);
        }
示例#6
0
        public void save_holidays_to_database()
        {
            var inclusiveStart = DateTime.MinValue;
            var inclusiveEnd = DateTime.MaxValue;

            var holidaysList = parser.GenerateHolidays(inclusiveStart, inclusiveEnd);

            var db = new HolidayDatabaseRepository();
            db.Save(holidaysList);
            db = new HolidayDatabaseRepository();

            var holidaysFromDb = db.Get(new AllSpecification<Holiday>());
            foreach (var holiday in holidaysList)
            {
                Assert.IsTrue( holidaysFromDb.Any(h=> h.Date == holiday.Date && h.Description == holiday.Description) );
            }

        }
 public void Setup()
 {
     DeleteDatabaseIfExists();
     RecreateSessionFactory();
     this.dbRepo = new HolidayDatabaseRepository(sessionFactory);
 }