Exemple #1
0
        public void Test(int year, int month, int expectedWorkingDays)
        {
            var calculator  = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator());
            var workingDays = calculator.GetWorkingDaysByMonth(year, month);

            Assert.Equal(expectedWorkingDays, workingDays);
        }
        public void WorkingDaysCalculator_PeriodWithTwoHolidaysAndWithAWeekend_CountsAllTheDaysMinusTheWeekendAndTheHolidays_Test()
        {
            const int expected           = 4;
            const int officeId           = 1;
            var       startDate          = new DateTime(2013, 6, 17); //monday
            var       endDateDate        = new DateTime(2013, 6, 23); //sunday
            var       calendarRepository = new Data.Repositories.Fakes.StubICalendarRepository();

            calendarRepository.GetOfficeCalendarInt32 = i => new Calendar
            {
                CalendarHolidays = new Collection <CalendarHolidays>
                {
                    new CalendarHolidays {
                        Day = new DateTime(2013, 6, 17)
                    },
                    new CalendarHolidays {
                        Day = new DateTime(2013, 6, 23)
                    }
                }
            };
            var workingDaysCalculator = new WorkingDaysCalculator(calendarRepository);

            int result = workingDaysCalculator.GetWorkingDays(officeId, startDate, endDateDate);

            Assert.AreEqual(expected, result);
        }
        void CreateVacationRequests(MyCompanyContext context)
        {
            var workingDaysCalculator = new WorkingDaysCalculator(new CalendarRepository(context));

            var now   = DateTime.UtcNow.Date;
            int total = 0;

            foreach (var employee in context.Employees)
            {
                int requests = 2;
                for (int i = 0; i < requests; i++)
                {
                    int days = _randomize.Next(2, 4);
                    var from = now.AddDays(10 + 5 * i);
                    var to   = now.AddDays(14 + 5 * i);

                    int numDays = workingDaysCalculator.GetWorkingDays(employee.OfficeId, from, to);
                    var request = new VacationRequest()
                    {
                        From             = from,
                        To               = to,
                        NumDays          = numDays,
                        Comments         = GetComment(total),
                        CreationDate     = DateTime.UtcNow.AddDays(-1),
                        LastModifiedDate = DateTime.UtcNow,
                        Status           = (VacationRequestStatus)i + 1,
                        EmployeeId       = employee.EmployeeId,
                    };
                    total++;
                    context.VacationRequests.Add(request);
                }
            }

            context.SaveChanges();
        }
Exemple #4
0
        public void CheckDictionary2()
        {
            var frenchPublicHolidaysCalculator = new Mock <IPublicHolidaysCalculator>();
            var calculator = new WorkingDaysCalculator(frenchPublicHolidaysCalculator.Object);

            calculator.IsDayOff(new DateTime(2012, 1, 1));
            calculator.IsDayOff(new DateTime(2012, 1, 1));
            calculator.IsDayOff(new DateTime(2012, 1, 1));
            frenchPublicHolidaysCalculator.Verify(e => e.GetPublicHolidays(2012), Times.Once);
        }
Exemple #5
0
        public void CheckDictionary()
        {
            var frenchPublicHolidaysCalculator = new Mock <IPublicHolidaysCalculator>();
            var calculator = new WorkingDaysCalculator(frenchPublicHolidaysCalculator.Object);

            calculator.GetWorkingDaysByMonth(2012, 1);
            calculator.GetWorkingDaysByMonth(2012, 1);
            calculator.GetWorkingDaysByMonth(2012, 1);
            frenchPublicHolidaysCalculator.Verify(e => e.GetPublicHolidays(2012), Times.Once);
        }
        public void CalculateForPartialMonthTest()
        {
            WorkingDaysCalculator calculator = new WorkingDaysCalculator();
            DateTime endDate = new DateTime(2020, 1, 21);

            foreach (int[] pair in _january2020)
            {
                DateTime start = new DateTime(2020, 1, pair[0]);
                int      days  = calculator.Calculate(start, endDate);
                Assert.AreEqual(pair[1], days);
            }
        }
        private static void WriteDayOffOrNot()
        {
            while (true)
            {
                Console.WriteLine("Which date do you wanna try ?");
                var wdate = Console.ReadLine();
                var res   = DateTime.TryParse(wdate, out DateTime date);
                if (!res)
                {
                    Console.WriteLine("This is no date !");
                    continue;
                }

                var result = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator()).IsDayOff(date);
                Console.WriteLine($"{result}");
            }
        }
        public void WorkingDaysCalculator_PeriodWithoutHolidaysOrWeekends_CountsAllTheDays_Test()
        {
            const int expected           = 5;
            const int officeId           = 1;
            var       startDate          = new DateTime(2013, 6, 17); //monday
            var       endDateDate        = new DateTime(2013, 6, 21); //friday
            var       calendarRepository = new Data.Repositories.Fakes.StubICalendarRepository();

            calendarRepository.GetOfficeCalendarInt32 = i => new Calendar
            {
                CalendarHolidays = new Collection <CalendarHolidays>()
            };
            var workingDaysCalculator = new WorkingDaysCalculator(calendarRepository);

            int result = workingDaysCalculator.GetWorkingDays(officeId, startDate, endDateDate);

            Assert.AreEqual(expected, result);
        }
 private static void WriteWorkingDaysAMonth()
 {
     while (true)
     {
         Console.WriteLine("Which year do you wanna try ?");
         var wantedYear = Console.ReadLine();
         var res        = int.TryParse(wantedYear, out int year);
         if (!res)
         {
             Console.WriteLine("This is no year !");
             continue;
         }
         Console.WriteLine("Which month do you wanna try ?");
         var wantedMonth = Console.ReadLine();
         res = int.TryParse(wantedMonth, out int month);
         if (!res)
         {
             Console.WriteLine("This is no year !");
             continue;
         }
         var result = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator()).GetWorkingDaysByMonth(year, month);
         Console.WriteLine($"{result} working days in {month}/{year}");
     }
 }
Exemple #10
0
        public void CheckDayOffHol()
        {
            var calculator = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator());

            Assert.True(calculator.IsDayOff(new DateTime(2017, 05, 08))); // ferié
        }
Exemple #11
0
        public void CheckDayOffSaturday()
        {
            var calculator = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator());

            Assert.True(calculator.IsDayOff(new DateTime(2017, 07, 01))); // samedi
        }
Exemple #12
0
        public void CheckDayOffSunday()
        {
            var calculator = new WorkingDaysCalculator(new FrenchPublicHolidaysCalculator());

            Assert.True(calculator.IsDayOff(new DateTime(2017, 07, 02))); // dimanche
        }
Exemple #13
0
 public void TestInitialize()
 {
     _calculator = new WorkingDaysCalculator();
 }