public void checkForDataForMonthTest() { var reportC = new ReportManagementController(_iDataContext); bool shouldBeFalse = reportC.checkForDataForMonth(new DateTime(2013, 01, 01), new DateTime(2013, 08, 01)); bool shouldBeTrue = reportC.checkForDataForMonth(new DateTime(1980, 01, 01), new DateTime(1981, 08, 01)); Assert.AreEqual(true, shouldBeTrue, "Data found for 1980 Jan-Apr?! Data shouldn't exist"); Assert.AreEqual(false, shouldBeFalse, "Data is not found for 2013 Jan-Apr! Data should exist"); }
/// <summary> /// The Page shown when the report is generated. /// </summary> /// <param name="form">The FormCollection with the various options chosen</param> /// <returns>The Report as an XLS file</returns> /// <request type="GET">/Report/Generate</request> public ViewResult GeneratingReport(FormCollection form) { var rg = new ReportManagementController(); var eec = new ExcelExportController(); string templatePath = Path.Combine(HttpRuntime.AppDomainAppPath, "ReportTemplate.xlsx"); var markDate = new DateTime(2010, 01, 01, 00, 00, 00, 00); TimeSpan dateStamp = DateTime.Now.Subtract(markDate); string copiedPath = Path.Combine(HttpRuntime.AppDomainAppPath, "Report" + dateStamp.TotalSeconds.ToString() + ".xlsx"); var dataTableDictionary = new Dictionary<string, DataTable>(); List<string> dataTypeStrings = form[Constants.ReportFormStrings.DATATYPE].Split(',').ToList(); List<Constants.DataType> dataTypes = dataTypeStrings.Select( dType => (Constants.DataType) Enum.Parse(typeof (Constants.DataType), dType)).ToList(); List<string> stratifyOptionStrings = form[Constants.ReportFormStrings.STRATIFY_BY].Split(',') .ToList(); List<Constants.StratifyOption> stratifyOptions = stratifyOptionStrings.Select( stratify => (Constants.StratifyOption) Enum.Parse(typeof (Constants.StratifyOption), stratify)) .ToList(); Dictionary<string, DataTable> temp; switch (form[Constants.ReportFormStrings.REPORT_OPTION]) { case "Monthly": DateTime startDate = Convert.ToDateTime(form["fromdatePicker"]); DateTime endDate = Convert.ToDateTime(form["todatePicker"]).AddMonths(1); if (rg.checkForDataForMonth(startDate, endDate)) { return View("NoDataView"); } foreach ( Constants.StratifyOption stratifyOption in stratifyOptions) { temp = rg.generateMonthlyReport(startDate, endDate, dataTypes, stratifyOption); foreach (var keyValuePair in temp) { dataTableDictionary.Add(keyValuePair.Key, keyValuePair.Value); } } break; case "MonthPerYear": var month = (Constants.Month) Enum.Parse(typeof (Constants.Month), form["MPYMonth"]); int startYear = Convert.ToInt32(form["MPYStartYear"]); int endYear = Convert.ToInt32(form["MPYEndYear"]); if (rg.checkForDataForMpy((int) month, startYear, endYear)) { return View("NoDataView"); } foreach ( Constants.StratifyOption stratifyOption in stratifyOptions) { temp = rg.generateMonthPerYearReport((int) month, startYear, endYear, dataTypes, stratifyOption); foreach (var keyValuePair in temp) { dataTableDictionary.Add(keyValuePair.Key, keyValuePair.Value); } } break; case "FiscalYear": int start = Convert.ToInt32(form["FYStartYear"]); int end = Convert.ToInt32(form["FYEndYear"]); if (rg.checkForDataForFy(start, end)) { return View("NoDataView"); } foreach ( Constants.StratifyOption stratifyOption in stratifyOptions) { temp = rg.generateYearlyReport(start, end, dataTypes, stratifyOption); foreach (var keyValuePair in temp) { dataTableDictionary.Add(keyValuePair.Key, keyValuePair.Value); } } break; } eec.exportDataTable(Constants.ReportType.Report, dataTableDictionary, templatePath, copiedPath); return View(); }