コード例 #1
0
        public void FindLeapYears()
        {
            var ly = new LeapYears();
            ly.StartYear = 1899;
            ly.EndYear = 1908;

            var leapFinder = new LeapYearFinder();
               var leaps = leapFinder.SearchForLeapYears(ly);

            int[] exp = {1904, 1908};

            for (int i = 0; i < ly.Years.Count; i++)
            {
               Assert.AreEqual(exp[i], ly.Years[i]);
            }

            Assert.AreEqual(leaps.Years.Count, 2);
        }
コード例 #2
0
        public ActionResult LeapYears(LeapYearSearchTool searchTool)
        {
            if (ModelState.IsValidField("EndYear") && searchTool.StartYear >= searchTool.EndYear)
            {
                ModelState.AddModelError("EndYear", "Please make sure your end date is later than your start date");
            }
            if (ModelState.IsValid)
            {
                var leapFinder = new LeapYearFinder();
                var leapYears = new LeapYears();

                leapYears.StartYear = searchTool.StartYear.Value;
                leapYears.EndYear = searchTool.EndYear.Value;

                var result = leapFinder.SearchForLeapYears(leapYears);

                searchTool.Years = result.Years;
                searchTool.IsPostback = true;
                return View("LeapYears", searchTool);

            }
            else
            {
                searchTool.Years = new List<int>(); //not sure why this is necessary but I get null ref exception on View without it.

                return View("LeapYears", searchTool);
            }
        }