public ActionResult Index(DateDiffModel model) { //check for empty dates being passed if (!String.IsNullOrWhiteSpace(model.DateFrom) || !String.IsNullOrWhiteSpace(model.DateFrom)) { //get the to and from dates as int // varibale f is the from date int f = int.Parse(model.DateFrom.Replace("-", "")); //variable t is the to date int t = int.Parse(model.DateTo.Replace("-", "")); // Test to date should be greater than from date. if (t <= f) { //shhow error to user ModelState.AddModelError("", "To date should always be greater than from date."); } else { //convert the string dates into integer arrays //using some link code int[] from = model.DateFrom.Split('-').Select(n => Convert.ToInt32(n)).ToArray(); int[] to = model.DateTo.Split('-').Select(n => Convert.ToInt32(n)).ToArray(); //get the days model.Days = model.GetDays(from, to).ToString(); } } // If we got this far, something failed, redisplay form return(View(model)); }
public void GetDaysTest3() { DateDiffModel target = new DateDiffModel(); int[] dt_start = new int[] { 1900, 12, 01 }; int[] dt_end = new int[] { 2005, 04, 10 }; long expected = 38116; long actual; actual = target.GetDays(dt_start, dt_end); Assert.AreEqual(expected, actual); }
public void GetDaysTest1() { DateDiffModel target = new DateDiffModel(); int[] dt_start = new int[] { 1999, 01, 01 }; int[] dt_end = new int[] { 2001, 01, 01 }; long expected = 731; long actual; actual = target.GetDays(dt_start, dt_end); Assert.AreEqual(expected, actual); }
public void DateDiffModelConstructorTest() { DateDiffModel target = new DateDiffModel(); Assert.IsNotNull(target, "Target constructor fail"); }