Пример #1
0
        public void WorkDurationsReturnProperWorkDurations()
        {
            var workDurationsArray = workTimeAnalyzer.GetWorkDurations().ToArray();

            Assert.Equal(new WorkDuration
            {
                StartDateTimeInstant = workEvents[0].DateTimeInstant,
                EndDateTimeInstant   = workEvents[1].DateTimeInstant
            }, workDurationsArray[0]);

            Assert.Equal(new WorkDuration
            {
                StartDateTimeInstant = workEvents[2].DateTimeInstant,
            }, workDurationsArray[1]);

            Assert.Equal(new WorkDuration
            {
                StartDateTimeInstant = workEvents[3].DateTimeInstant,
                EndDateTimeInstant   = workEvents[4].DateTimeInstant
            }, workDurationsArray[2]);

            Assert.Equal(new WorkDuration
            {
                StartDateTimeInstant = workEvents[5].DateTimeInstant,
                EndDateTimeInstant   = workEvents[6].DateTimeInstant
            }, workDurationsArray[3]);

            Assert.Equal(4, workDurationsArray.Length);
        }
Пример #2
0
        //todo REFACTOR
        public async Task <Result <ShortWorkSummary> > Handle(GetShortWorkSummaryOfEmployeeQuery request, CancellationToken cancellationToken)
        {
            DateTime fromInclusiveUtc = request.FromInclusive.ToUniversalTime();
            DateTime toInclusiveUtc   = request.ToInclusive.ToUniversalTime();

            var result = await persistWorkEventPort.GetWorkEventsOfEmployeeBetweenAsync(
                request.EmployeeId, fromInclusiveUtc, toInclusiveUtc);

            if (result.IsFailed)
            {
                return(result.ToResult <ShortWorkSummary>());
            }

            var workEvents = result.Value;

            WorkTimeAnalyzer workTimeAnalyzer = new WorkTimeAnalyzer(workDayEndsAt_3am);

            foreach (var workEvent in workEvents)
            {
                workTimeAnalyzer.AddWorkEvent(workEvent);
            }

            var workDurations = workTimeAnalyzer.GetWorkDurations();

            ShortWorkSummary shortWorkSummary = new ShortWorkSummary(fromInclusiveUtc, toInclusiveUtc);

            TimeSpan workDurationSum = TimeSpan.Zero;

            foreach (var workDuration in workDurations)
            {
                shortWorkSummary.SetStatusOfDay(workDuration.StartDateTimeInstant.Value.ToUniversalTime(),
                                                workDuration.Completed ?
                                                ShortWorkSummary.DayStatus.PRESENCE :
                                                ShortWorkSummary.DayStatus.PROBLEM);

                TimeSpan?timeSpan = workDuration.AsTimeSpan();
                if (timeSpan.HasValue)
                {
                    workDurationSum = workDurationSum.Add(timeSpan.Value);
                }
            }
            shortWorkSummary.MinutesOfWork = (uint)workDurationSum.TotalMinutes;

            return(Result.Ok(shortWorkSummary));
        }
Пример #3
0
        public async Task <Result <DetailedWorkSummary> > Handle(GetDetailedWorkSummaryOfEmployeeQuery request, CancellationToken cancellationToken)
        {
            DateTime fromInclusiveUtc = request.FromInclusive.ToUniversalTime();
            DateTime toInclusiveUtc   = request.ToInclusive.ToUniversalTime();

            var result = await persistWorkEventPort.GetWorkEventsOfEmployeeBetweenAsync(
                request.EmployeeId, fromInclusiveUtc, toInclusiveUtc);

            if (result.IsFailed)
            {
                return(result.ToResult <DetailedWorkSummary>());
            }

            var workEvents = result.Value;

            WorkTimeAnalyzer workTimeAnalyzer = new WorkTimeAnalyzer(workDayEndsAt_3am);

            foreach (var workEvent in workEvents)
            {
                workTimeAnalyzer.AddWorkEvent(workEvent);
            }

            var workDurations = workTimeAnalyzer.GetWorkDurations();

            DetailedWorkSummary detailedWorkSummary = new DetailedWorkSummary(
                fromInclusiveUtc, toInclusiveUtc, workDurations);

            TimeSpan workDurationSum = TimeSpan.Zero;

            foreach (var workDuration in workDurations)
            {
                TimeSpan?timeSpan = workDuration.AsTimeSpan();
                if (timeSpan.HasValue)
                {
                    workDurationSum = workDurationSum.Add(timeSpan.Value);
                }
            }
            detailedWorkSummary.MinutesOfWork = (uint)workDurationSum.TotalMinutes;

            return(Result.Ok(detailedWorkSummary));
        }