Esempio n. 1
0
        public IActionResult Index(int?year, int?weeknumber)
        {
            var cursusListViewModel = new CursusListViewModel();

            // If year has a value, check if it is a valid one
            if (year.HasValue)
            {
                if (Convert.ToInt32(cursusListViewModel.Years.Last().Value) < year || Convert.ToInt32(cursusListViewModel.Years.First().Value) > year)
                {
                    year = null;
                }
            }

            // If weeknumber has a value, check if it is a valid one
            if (weeknumber.HasValue)
            {
                if (weeknumber < 1 || weeknumber > 53)
                {
                    weeknumber = null;
                }
            }

            // Check if year and weeknumber have been set, if not,
            var selectedWeekNumber = weeknumber ?? DateTime.Now.GetIso8601WeekOfYear();
            var selectedYear       = year ?? DateTime.Now.Year;
            var cursussen          = _casService.ApiV1CursusByYearByWeeknumberGet(selectedWeekNumber, selectedYear) as List <Cursus>;

            // Initialize model
            cursusListViewModel
            .Cursussen = cursussen.Select(x => new CursusViewModel {
                Id        = x.Id.Value, Title = x.Title,
                StartDate = x.StartDate, DateCount = x.AmountOfDays, CursistCount = x.AmountOfCursisten
            }).ToList();
            cursusListViewModel.WeekNumber = selectedWeekNumber;
            cursusListViewModel.Year       = selectedYear;

            return(View(cursusListViewModel));
        }
Esempio n. 2
0
        public void CursusListViewModelInitializationIsCorrect()
        {
            // Arrange
            var target = new CursusListViewModel();

            // Act - Assert
            Assert.AreNotEqual(null, target.Years);
            Assert.AreNotEqual(null, target.WeekNumbers);
            Assert.AreNotEqual(null, target.Cursussen);

            Assert.IsInstanceOfType(target.Years, typeof(IEnumerable <SelectListItem>));
            Assert.IsInstanceOfType(target.WeekNumbers, typeof(IEnumerable <SelectListItem>));
            Assert.IsInstanceOfType(target.Cursussen, typeof(List <CursusViewModel>));

            Assert.IsTrue(target.Years.First().Value == "1980");
            Assert.IsTrue(target.Years.First().Text == "1980");

            Assert.IsTrue(target.WeekNumbers.First().Value == "1");
            Assert.IsTrue(target.WeekNumbers.First().Text == "1");
            Assert.IsTrue(target.WeekNumbers.Last().Value == "53");
            Assert.IsTrue(target.WeekNumbers.Last().Text == "53");

            Assert.IsTrue(target.Cursussen.FirstOrDefault() == null);
        }