示例#1
0
        public void GetPeriods_should_return_zero_periods()
        {
            const int expected = 0;
            var       actual   = PeriodsHelper.GetPeriods(DateTime.Now, TimelogsPeriod.Daily, expected).Length;

            Assert.AreEqual(expected, actual);
        }
示例#2
0
        public ActionResult Timelogs()
        {
            var sesSelectedPeople = Session[SessionTags.SelectedPeople];
            var sesPeriod         = Session[SessionTags.Period];

            TimelogsViewModel model;

            try
            {
                #region get all people

                IProxyPeople apiPeople = new TwClient.Api.TwClient
                {
                    SiteName = Settings.Config.Account,
                    ApiToken = Settings.Config.Token
                };
                var people = apiPeople.Get();

                #endregion

                var selectedPeople = (sesSelectedPeople as IEnumerable <PersonViewModel>) ?? Enumerable.Empty <PersonViewModel>();
                var timelogsPeriod = sesPeriod != null ? (TimelogsPeriod)sesPeriod : TimelogsPeriod.Daily;
                var periods        = PeriodsHelper.GetPeriods(DateTime.Now, timelogsPeriod);
                model = new TimelogsViewModel
                {
                    People = people.Select(p => new PersonViewModel
                    {
                        FullName = string.Format("{0} {1}", p.FirstName, p.LastName),
                        Id       = p.Id.ToString(),
                        Selected = selectedPeople.Any(sp => sp.Id == p.Id.ToString())
                    }),
                    SelectedPeople = selectedPeople,
                    Grid           = new TimelogsGridViewModel
                    {
                        Headers = periods.ConvertToNames(timelogsPeriod, DateTime.Now)
                    }
                };

                GetUserTimelogs(model, periods);
            }
            catch (Exception)
            {
                model = new TimelogsViewModel();
            }

            return(View(model));
        }
示例#3
0
        public ActionResult Timelogs(TimelogsViewModel options)
        {
            options.SelectedPeople = options.SelectedPeople ?? new PersonViewModel[] {};

            Session[SessionTags.SelectedPeople] = options.SelectedPeople;
            Session[SessionTags.Period]         = options.Period;

            var periods = PeriodsHelper.GetPeriods(DateTime.Now, options.Period);

            options.Grid = new TimelogsGridViewModel
            {
                Headers = periods.ConvertToNames(options.Period, DateTime.Now)
            };
            GetUserTimelogs(options, periods);

            return(PartialView("_TimelogGrid", options));
        }
示例#4
0
        public void GetPeriods_should_return_date_for_Daily()
        {
            var currentDate = DateTime.Now;
            var expected    = new[]
            {
                currentDate.AddDays(-8).Date,
                currentDate.AddDays(-7).Date,
                currentDate.AddDays(-6).Date,
                currentDate.AddDays(-5).Date,
                currentDate.AddDays(-4).Date,
                currentDate.AddDays(-3).Date,
                currentDate.AddDays(-2).Date,
                currentDate.AddDays(-1).Date,
                currentDate
            };
            var actual = PeriodsHelper.GetPeriods(currentDate, TimelogsPeriod.Daily, 9);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#5
0
        public void ConvertToNames_for_Monthly_periods()
        {
            var currentDate = new DateTime(2015, 4, 9);
            var expected    = new[]
            {
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-8)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-7)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-6)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-5)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-4)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-3)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-2)),
                PeriodsHelper.GetMonthName(currentDate.AddMonths(-1)),
                PeriodsHelper.GetMonthName(currentDate)
            };
            var periods = PeriodsHelper.GetPeriods(currentDate, TimelogsPeriod.Monthly, 9);
            var actual  = periods.ConvertToNames(TimelogsPeriod.Monthly, DateTime.Now);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#6
0
        public void ConvertToNames_for_Daily_periods()
        {
            var currentDate = DateTime.Now;
            var expected    = new[]
            {
                currentDate.AddDays(-8).ToString("dd/MM/yy"),
                currentDate.AddDays(-7).ToString("dd/MM/yy"),
                currentDate.AddDays(-6).ToString("dd/MM/yy"),
                currentDate.AddDays(-5).ToString("dd/MM/yy"),
                currentDate.AddDays(-4).ToString("dd/MM/yy"),
                currentDate.AddDays(-3).ToString("dd/MM/yy"),
                currentDate.AddDays(-2).ToString("dd/MM/yy"),
                currentDate.AddDays(-1).ToString("dd/MM/yy"),
                currentDate.ToString("dd/MM/yy")
            };
            var periods = PeriodsHelper.GetPeriods(currentDate, TimelogsPeriod.Daily, 9);
            var actual  = periods.ConvertToNames(TimelogsPeriod.Daily, DateTime.Now);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#7
0
        public void GetPeriods_should_return_date_for_Monthly()
        {
            var currentDate    = DateTime.Now;
            var monthStartDate = new DateTime(currentDate.Year, currentDate.Month, 1);

            // expected periods should include the current one even if it is not finished yet
            var expected = new[]
            {
                monthStartDate.AddMonths(-8),
                monthStartDate.AddMonths(-7),
                monthStartDate.AddMonths(-6),
                monthStartDate.AddMonths(-5),
                monthStartDate.AddMonths(-4),
                monthStartDate.AddMonths(-3),
                monthStartDate.AddMonths(-2),
                monthStartDate.AddMonths(-1),
                monthStartDate
            };
            var actual = PeriodsHelper.GetPeriods(DateTime.Now, TimelogsPeriod.Monthly, 9);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#8
0
        public void GetPeriods_should_return_date_for_Weekly()
        {
            var currentDate   = DateTime.Now;
            var weekStartDate = PeriodsHelper.GetWeekStart(currentDate);

            // expected periods should include the current one even if it is not finished yet
            var expected = new[]
            {
                weekStartDate.AddDays(-7 * 8),
                weekStartDate.AddDays(-7 * 7),
                weekStartDate.AddDays(-7 * 6),
                weekStartDate.AddDays(-7 * 5),
                weekStartDate.AddDays(-7 * 4),
                weekStartDate.AddDays(-7 * 3),
                weekStartDate.AddDays(-7 * 2),
                weekStartDate.AddDays(-7 * 1),
                weekStartDate
            };
            var actual = PeriodsHelper.GetPeriods(DateTime.Now, TimelogsPeriod.Weekly, 9);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }
示例#9
0
        public void ConvertToNames_for_Weekly_periods()
        {
            // chose the current date so that
            // #1 the current week is not finished yet
            // #2 some of the previous weeks is starting and ending in different monthes

            var currentDate = new DateTime(2015, 4, 9); // thu
            var expected    = new[]
            {
                "09-15,Feb",
                "16-22,Feb",
                "23,Feb-01,Mar",
                "02-08,Mar",
                "09-15,Mar",
                "16-22,Mar",
                "23-29,Mar",
                "30,Mar-05,Apr",
                "06-09,Apr"
            };
            var periods = PeriodsHelper.GetPeriods(currentDate, TimelogsPeriod.Weekly, 9);
            var actual  = periods.ConvertToNames(TimelogsPeriod.Weekly, currentDate);

            Assert.IsTrue(expected.SequenceEqual(actual));
        }