public ActionResult Index(int? beginMonth, int? beginDay, int? beginYear, int? endMonth, int? endDay, int? endYear, string stationState, string stationName) { // preserve form entries ViewBag.BeginMonth = beginMonth; ViewBag.BeginDay = beginDay; ViewBag.BeginYear = beginYear; ViewBag.EndMonth = endMonth; ViewBag.EndDay = endDay; ViewBag.EndYear = endYear; ViewBag.StationState = stationState; ViewBag.StationName = stationName; // validation logic - combination of begin month and day must be greater than or equal to the end month and day // validation logic - end year must be greater than or equal to the begin year // cannot us data datatype validation as this won't work with the day-range logic of the datasets // end validation errors to the view if (endYear < beginYear) { ModelState.AddModelError("Years", "ERROR - The end year must be greater than or equal to begin year"); } else if (endMonth < beginMonth) { ModelState.AddModelError("Months", "ERROR - The end month must be greater than or equal to the begin month."); } else if ((endMonth == beginMonth) && (endDay < beginDay)) { ModelState.AddModelError("Days", "ERROR - The end day must be greater than or equal to the begin day."); } // choose view based on model validation if (ModelState.IsValid) { // build request objects and table view ISummaryRequest summaryRequest = new SummaryRequest(stationName, beginMonth, beginDay, beginYear, endMonth, endDay, endYear); ITablesView tableView = new TablesView(summaryRequest); return View("SummaryTables", tableView); } else { // build request objects and table view // null all values sent to SummaryRequest to avoid data errors ISummaryRequest summaryRequest = new SummaryRequest(null, null, null, null, null, null, null); ITablesView tableView = new TablesView(summaryRequest); return View("SummaryTables", tableView); } }
public void BuildTablesViewObject() { // this test attempts to build a tables view object // and verify the data properties returned // arrange - mock up ISummaryRequest Mock<ISummaryRequest> mockSR = new Mock<ISummaryRequest>(); // build dictionary for mock ISummaryRequest IDictionary<string, int?> dateDict = new Dictionary<string, int?>(); // populate mock dictionary dateDict.Add("beginMonth", 7); dateDict.Add("beginDay", 5); dateDict.Add("beginYear", 2013); dateDict.Add("endMonth", 7); dateDict.Add("endDay", 10); dateDict.Add("endYear", 2013); // define mock properties for mock ISummaryRequest mockSR.SetupGet(m => m.StationName).Returns("13904"); mockSR.SetupGet(m => m.DateDict).Returns(dateDict); //act - build a tables view from mock ISummaryRequest ITablesView tv = new TablesView(mockSR.Object); //assert - count returned list rows - should each be 6 Assert.AreEqual(tv.PrecipSummary.Count(), 6); Assert.AreEqual(tv.TempSummary.Count(), 6); Assert.AreEqual(tv.WindSummary.Count(), 6); }