Exemple #1
0
        public void Test_3VacationDaysOnAlvDays_3VacationDaysUsed()
        {
            var timeEntryStorage = new TimeEntryStorage(context);
            var absenseService   = new AbsenseDaysService(timeEntryStorage, options);

            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = new DateTime(2021, 3, 29),
                Value  = 7.5M,
                TaskId = options.CurrentValue.PaidHolidayTask
            }, 1);

            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = new DateTime(2021, 3, 30),
                Value  = 7.5M,
                TaskId = options.CurrentValue.PaidHolidayTask
            }, 1);

            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = new DateTime(2021, 3, 31),
                Value  = 7.5M,
                TaskId = options.CurrentValue.PaidHolidayTask
            }, 1);

            var holidayOverview = absenseService.GetVacationDays(1, 2021, 6, 1);

            Assert.Equal(3, holidayOverview.UsedVacationDays);
            Assert.Equal(25, holidayOverview.AvailableVacationDays);
        }
Exemple #2
0
        public void TestConcurrentDays_MoreThanThree()
        {
            var timeEntryStorage = new TimeEntryStorage(context);
            var absenseService   = new AbsenseDaysService(timeEntryStorage, options);

            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = DateTime.Now.AddDays(-9),
                Value  = 5,
                TaskId = options.CurrentValue.SickDaysTask
            }, 1);
            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = DateTime.Now.AddDays(-10),
                Value  = 5,
                TaskId = options.CurrentValue.SickDaysTask
            }, 1);
            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = DateTime.Now.AddDays(-11),
                Value  = 5,
                TaskId = options.CurrentValue.SickDaysTask
            }, 1);
            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = DateTime.Now.AddDays(-12),
                Value  = 5,
                TaskId = options.CurrentValue.SickDaysTask
            }, 1);

            var days = absenseService.GetAbsenseDays(1, 2021, null);

            // We withdraw three whole days
            Assert.Equal(6, days.UsedAbsenseDays);
        }
Exemple #3
0
        public void UpdateTimeEntry_ExistingTimeEntry_TimeEntryUpdated()
        {
            var context = new AlvTimeDbContextBuilder()
                          .WithTimeEntries()
                          .WithTasks()
                          .WithUsers()
                          .CreateDbContext();

            var storage = new TimeEntryStorage(context);

            storage.UpdateTimeEntry(new CreateTimeEntryDto
            {
                Date   = new DateTime(2020, 05, 02),
                TaskId = 1,
                Value  = 10
            }, 1);

            var timeEntry = storage.GetTimeEntry(new TimeEntryQuerySearch
            {
                UserId            = 1,
                FromDateInclusive = new DateTime(2020, 05, 02),
                ToDateInclusive   = new DateTime(2020, 05, 02),
                TaskId            = 1
            });

            Assert.True(timeEntry.Value == 10);
        }
Exemple #4
0
        public void GetTimeEntries_TaskSpecified_AllEntriesWithSpecifiedTask()
        {
            var context = new AlvTimeDbContextBuilder().CreateDbContext();

            var storage = new TimeEntryStorage(context);

            var timeEntries = storage.GetTimeEntries(new TimeEntryQuerySearch
            {
                UserId = 1,
                TaskId = 2
            });

            var contextEntriesWithTask = context.Hours
                                         .Where(x => x.TaskId == 2 && x.User == 1)
                                         .ToList();

            Assert.Equal(contextEntriesWithTask.Count(), timeEntries.Count());
        }
Exemple #5
0
        public void GetTimeEntries_DatesSpecified_AllEntriesBetweenDates()
        {
            var context = new AlvTimeDbContextBuilder().CreateDbContext();

            var storage = new TimeEntryStorage(context);

            var timeEntries = storage.GetTimeEntries(new TimeEntryQuerySearch
            {
                UserId            = 1,
                FromDateInclusive = new DateTime(2019, 01, 01),
                ToDateInclusive   = new DateTime(2020, 01, 01)
            });

            var contextCountInPeriod = context.Hours
                                       .Where(x => x.Date.Date <= new DateTime(2020, 01, 01) && x.Date.Date >= new DateTime(2019, 01, 01) && x.User == 1)
                                       .ToList();

            Assert.Equal(contextCountInPeriod.Count(), timeEntries.Count());
        }
Exemple #6
0
        public void CheckRemainingHolidays_SickdaysTaken()
        {
            var timeEntryStorage = new TimeEntryStorage(context);
            var absenseService   = new AbsenseDaysService(timeEntryStorage, options);

            // One day of sick leave
            timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = DateTime.Now.AddDays(-2),
                Value  = 5,
                TaskId = options.CurrentValue.SickDaysTask
            }, 1);


            var days = absenseService.GetAbsenseDays(1, 2021, null);

            Assert.Equal(3, days.UsedAbsenseDays);


            // These two withdrawals of sick days should also count as 3 as they are concurrent
        }
Exemple #7
0
        public void Test_PlannedVacationDayOnAlvDay_PlannedDaysNotDoubled()
        {
            var timeEntryStorage = new TimeEntryStorage(context);
            var absenseService   = new AbsenseDaysService(timeEntryStorage, options);

            for (int i = 0; i < 5; i++)
            {
                timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
                {
                    Date   = new DateTime(2021, 12, 27).AddDays(i),
                    Value  = 7.5M,
                    TaskId = options.CurrentValue.PaidHolidayTask
                }, 1);
            }

            var holidayOverview = absenseService.GetVacationDays(1, 2021, 6, 1);

            Assert.Equal(3, holidayOverview.UsedVacationDays);
            Assert.Equal(5, holidayOverview.PlannedVacationDays);
            Assert.Equal(25, holidayOverview.AvailableVacationDays);
        }
Exemple #8
0
        public void Test_Complicated_HolidayCalculations()
        {
            var timeEntryStorage = new TimeEntryStorage(context);
            var absenseService   = new AbsenseDaysService(timeEntryStorage, options);

            // Create both planned and used holiday
            for (int i = 0; i < 10; i++)
            {
                timeEntryStorage.CreateTimeEntry(new CreateTimeEntryDto
                {
                    Date   = new DateTime(2020, 6, 5).AddDays(i * -1),
                    Value  = 5,
                    TaskId = options.CurrentValue.PaidHolidayTask
                }, 1);
            }

            var holidayOverview = absenseService.GetVacationDays(1, 2020, 6, 1);

            Assert.Equal(9, holidayOverview.UsedVacationDays);
            Assert.Equal(8, holidayOverview.PlannedVacationDays);
            Assert.Equal(15, holidayOverview.AvailableVacationDays);
        }
Exemple #9
0
        public void CreateTimeEntry_NewTimeEntry_TimeEntryCreated()
        {
            var context = new AlvTimeDbContextBuilder().WithUsers().CreateDbContext();

            var storage = new TimeEntryStorage(context);

            var previousAmountOfEntries = context.Hours.Count();

            storage.CreateTimeEntry(new CreateTimeEntryDto
            {
                Date   = new DateTime(2020, 01, 01),
                TaskId = 2,
                Value  = 7.5M
            }, 1);

            var timeEntries = storage.GetTimeEntries(new TimeEntryQuerySearch
            {
                UserId            = 1,
                FromDateInclusive = new DateTime(2010, 01, 01),
                ToDateInclusive   = new DateTime(2030, 01, 01)
            });

            Assert.Equal(previousAmountOfEntries + 1, timeEntries.Count());
        }