public async Task Handler_Calculates_Stats_For_All_Months()
        {
            AppUser user = null;

            using (var context = new AppDbContext(_options))
            {
                context.WorkDays.AddRange(new WorkDaySeeder(new Contract {
                    Id = 1, HoursPerWeek = 40
                }).AddWorkDayRange("2020-01-01", "2021-02-14").Seed());
                context.SaveChanges();

                user = await context.Users.Include(x => x.Contracts.Where(c => c.IsCurrent)).FirstOrDefaultAsync(x => x.Id == 1);
            }

            var response = await _testObject.Handle(new RecalculateMyMonthsRequest()
            {
                User = user, CurrentContract = user.Contracts.First()
            }, CancellationToken.None);

            using (var context = new AppDbContext(_options))
            {
                var months = await context.WorkMonths.ToListAsync();

                months.Count.Should().Be(14);
                var daysAssigned = await context.WorkDays.Where(x => x.WorkMonthId.HasValue).ToListAsync();

                daysAssigned.Count.Should().Be(284);
            }
        }
Exemple #2
0
        public async Task Handler_Gets_Monthly_Stats()
        {
            var currentContract = new Contract {
                Id = 1, IsCurrent = true, UserId = 1
            };
            var user = new AppUser {
                Id = 1, Contracts = new List <Contract>()
                {
                    currentContract
                }
            };

            var workMonthCalculation = new RecalculateMyMonthsHandler(new AppDbContext(_options), new LoggerMock <RecalculateMyMonthsHandler>());
            await workMonthCalculation.Handle(new RecalculateMyMonthsRequest { User = user, CurrentContract = currentContract }, CancellationToken.None);

            using (var context = new AppDbContext(_options))
            {
                var workdays = await context.WorkDays.Include(x => x.Contract).ToListAsync();
            }

            var request = new GetWorkMonthsRequest()
            {
                User = user, CurrentContract = currentContract
            };

            var response = await _testObject.Handle(request, CancellationToken.None);

            response.Months.Count.Should().Be(15);
            response.Months.Sum(x => x.TotalHours).Should().Be(2656.3);
        }