public void WeekDays_ShouldReturnCorrectResult(IFixture fixture, TimesheetWeek sut)
        {
            // arrange..
            var startDate = new DateTime(2017, 12, 18); // Monday..

            for (var dt = startDate; dt < startDate.AddDays(7); dt = dt.AddDays(1))
            {
                var workDay = fixture.Build <WorkDay>()
                              .With(wd => wd.Date, dt)
                              .Create();
                sut.AddDay(workDay);
            }

            // act..
            var actual = sut.WorkDays;

            // assert..
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Monday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Tuesday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Wednesday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Thursday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Friday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Saturday);
            actual.ShouldContain(wd => wd.Date.DayOfWeek == DayOfWeek.Sunday);
        }
        public ActionResult New(long agreementId, DateTime weekEnding)
        {
            var booking = bookingService.GetBookingByReference(agreementId.ToString());

            if (booking != null && booking.CarerID.HasValue)
            {
                var timesheet = timesheetService.GetTimesheets(booking.CarerID.Value, null, null, null, null, null, null, null)
                                .Where(x => x.WeekEnding == weekEnding && x.AgreementID == agreementId)
                                .FirstOrDefault();

                if (timesheet == null)
                {
                    timesheet = new TimesheetWeek(weekEnding)
                    {
                        AgreementID = agreementId,
                        CarerID     = booking.CarerID.Value
                    };

                    timesheetService.Save(timesheet);
                }

                return(RedirectToAction("Edit", new { Id = timesheet.ID }));
            }

            return(RedirectToSamePage());
        }
        public static TimesheetWeekViewModel ToViewModel(TimesheetWeek timesheet)
        {
            var viewModel = new TimesheetWeekViewModel()
            {
                Notes                    = timesheet.Notes,
                Status                   = timesheet.Status,
                Reference                = timesheet.Reference,
                WeekEnding               = timesheet.WeekEnding,
                CarerID                  = timesheet.CarerID,
                AgreementID              = timesheet.AgreementID,
                CarerPaymentGenerated    = timesheet.CarerPaymentGenerated,
                CreatedDate              = timesheet.CreatedDate,
                CustomerPaymentGenerated = timesheet.CustomerPaymentGenerated,
                ID = timesheet.ID,
                TimesheetStatusID = timesheet.TimesheetStatusID,
                SubmittedBy       = timesheet.SubmittedBy,
                SubmittedDate     = timesheet.SubmittedDate,
                Days = new List <TimesheetDayViewModel>()
            };

            foreach (TimesheetDay day in timesheet.Days)
            {
                viewModel.Days.Add(TimesheetDayViewModel.ToViewModel(day));
            }

            return(viewModel);
        }
        private void SubmitTimesheet(TimesheetWeek timesheet)
        {
            timesheet.SubmittedByAdmin = true;
            timesheetService.Submit(timesheet);
            timesheetService.Approve(timesheet);

            timesheet.Expenses.ForEach(expense =>
            {
                expensesService.Submit(expense);
                expensesService.Approve(expense);
            });
        }
Пример #5
0
        public ITimesheet Initialize(IEnumerable <IWorkDay> workDays)
        {
            var timesheet = new Timesheet();
            var dates     = new List <DateTime>();

            workDays = workDays.ToList();

            var startDate = workDays.Min(wd => wd.Date);
            var endDate1  = workDays.Max(wd => wd.Date);

            var dt = startDate;

            while (dt <= endDate1)
            {
                dates.Add(dt = dt.AddDays(1));
            }

            while (dates.Min().DayOfWeek != DayOfWeek.Monday)
            {
                dates.Insert(0, dates.Min().AddDays(-1));
            }

            while (dates.Max().DayOfWeek != DayOfWeek.Sunday)
            {
                dates.Add(dates.Max().AddDays(1));
            }

            var date    = dates.Min();
            var endDate = dates.Max();

            var timesheetWeek = new TimesheetWeek();

            timesheet.AddWeek(timesheetWeek);

            while (date <= endDate)
            {
                if (timesheetWeek.IsFull)
                {
                    timesheetWeek = new TimesheetWeek();
                    timesheet.AddWeek(timesheetWeek);
                }

                var matchedWorkDay = workDays.SingleOrDefault(wd => wd.Date == date);

                var workDay = matchedWorkDay == null ? new TimesheetDay(date) : new TimesheetDay(matchedWorkDay);
                timesheetWeek.AddDay(workDay);

                date = date.AddDays(1);
            }

            return(timesheet);
        }
        public void WeekDays_ShouldReturnDataInCorrectOrder(IFixture fixture, DateTime startDate, TimesheetWeek sut)
        {
            // arrange..
            for (var dt = startDate; dt < startDate.AddDays(7); dt = dt.AddDays(1))
            {
                var workDay = fixture.Build <WorkDay>()
                              .With(wd => wd.Date, dt)
                              .Create();
                sut.AddDay(workDay);
            }

            // act..
            var actual = sut.WorkDays;

            // assert..
            actual.ElementAt(0).Date.DayOfWeek.ShouldBe(DayOfWeek.Monday);
            actual.ElementAt(1).Date.DayOfWeek.ShouldBe(DayOfWeek.Tuesday);
            actual.ElementAt(2).Date.DayOfWeek.ShouldBe(DayOfWeek.Wednesday);
            actual.ElementAt(3).Date.DayOfWeek.ShouldBe(DayOfWeek.Thursday);
            actual.ElementAt(4).Date.DayOfWeek.ShouldBe(DayOfWeek.Friday);
            actual.ElementAt(5).Date.DayOfWeek.ShouldBe(DayOfWeek.Saturday);
            actual.ElementAt(6).Date.DayOfWeek.ShouldBe(DayOfWeek.Sunday);
        }
        public void Add_ShouldThrowExceptionWhenTryingToAddSameWeekDayTwice(IFixture fixture, DateTime startDate, TimesheetWeek sut)
        {
            // arrange..
            var workDay = fixture.Build <WorkDay>()
                          .With(wd => wd.Date, startDate)
                          .Create();

            sut.AddDay(workDay);

            // act..
            var actual = Record.Exception(() => sut.AddDay(fixture.Build <WorkDay>()
                                                           .With(wd => wd.Date, startDate.AddDays(7))
                                                           .Create()));

            // assert..
            actual.ShouldNotBeNull();
            actual.ShouldBeOfType <ArgumentException>();
        }
        public void Add_ShouldThrowExceptionWhenTryingToAddMoreThanSevenDaysToTheWeek(IFixture fixture, DateTime startDate, TimesheetWeek sut)
        {
            // arrange..
            for (var dt = startDate; dt < startDate.AddDays(7); dt = dt.AddDays(1))
            {
                var workDay = fixture.Build <WorkDay>()
                              .With(wd => wd.Date, dt)
                              .Create();
                sut.AddDay(workDay);
            }

            // act..
            var actual = Record.Exception(() => sut.AddDay(fixture.Create <WorkDay>()));

            // assert..
            actual.ShouldNotBeNull();
            actual.ShouldBeOfType <ArgumentException>();
            actual.Message.ShouldBe("Attempt on adding more than 7 days to a week");
        }