コード例 #1
0
        public void checkForDataForMpyTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            bool shouldBeFalse = reportC.checkForDataForMpy(4, 2011, 2014);
            bool shouldBeTrue = reportC.checkForDataForMpy(4, 1980, 1981);

            Assert.AreEqual(true, shouldBeTrue,
                            "Data found for Mar 1980-1981?! Data shouldn't exist");
            Assert.AreEqual(false, shouldBeFalse,
                            "Data is not found for Mar 2011-2014! Data should exist");
        }
コード例 #2
0
        public void checkForDataForFyTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            bool shouldBeTrue = reportC.checkForDataForFy(1980, 1982);
            bool shouldBeFalse = reportC.checkForDataForFy(2012, 2014);

            Assert.AreEqual(true, shouldBeTrue,
                            "Data found for 1980-1982? Data shouldn't exist");
            Assert.AreEqual(false, shouldBeFalse,
                            "Data not found for 2012-2014! Data should exist");
        }
コード例 #3
0
 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");
 }
コード例 #4
0
        public void generateMonthlyNoStratificationTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthlyReport(new DateTime(2013, 02, 01),
                                              new DateTime(2013, 06, 01),
                                              _dataTypes,
                                              Constants.StratifyOption.None);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[0]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable generalReport = results[Constants.DATATABLE_TITLES[0]];
            Assert.AreEqual(85, generalReport.Rows[0][2]);
            Assert.AreEqual(3, generalReport.Rows[2][1]);
            Assert.AreNotEqual(0, generalReport.Rows[1][1]);
            //Tests the table size:
            Assert.AreEqual(4, generalReport.Rows.Count);
            Assert.AreEqual(5, generalReport.Columns.Count);
        }
コード例 #5
0
ファイル: ReportController.cs プロジェクト: vladzaharia/cairs
        /// <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();
        }
コード例 #6
0
        public void generateMonthlyStratifiedByCallerTypeTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthlyReport(new DateTime(2013, 02, 01),
                                              new DateTime(2013, 06, 01),
                                              _dataTypes,
                                              Constants.StratifyOption
                                                       .RequestorType);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[5]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[6]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[7]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[8]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByCallerType =
                results[Constants.DATATABLE_TITLES[5]];
            Assert.AreEqual(85, avgTimeByCallerType.Rows[3][2]);
            Assert.AreEqual(70, avgTimeByCallerType.Rows[2][1]);
            Assert.AreEqual(0, avgTimeByCallerType.Rows[0][1]);
            //Tests the table size:
            Assert.AreEqual(4, avgTimeByCallerType.Rows.Count);
            Assert.AreEqual(5, avgTimeByCallerType.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByCallerType =
                results[Constants.DATATABLE_TITLES[6]];
            Assert.AreEqual(5, avgTimeToCompleteByCallerType.Rows[0][3]);
            Assert.AreEqual(0, avgTimeToCompleteByCallerType.Rows[0][4]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalRequestsByCallerType =
                results[Constants.DATATABLE_TITLES[7]];
            Assert.AreEqual(2, totalRequestsByCallerType.Rows[2][1]);
            Assert.AreEqual(0, totalRequestsByCallerType.Rows[2][3]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByCallerType =
                results[Constants.DATATABLE_TITLES[8]];
            Assert.AreEqual(40, totalTimeSpentByCallerType.Rows[1][4]);
            Assert.AreEqual(0, totalTimeSpentByCallerType.Rows[3][3]);
        }
コード例 #7
0
        public void generateYearlyStratifiedByTumourGroupTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateYearlyReport(2011, 2013,
                                             _dataTypes,
                                             Constants.StratifyOption.TumorGroup);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[9]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[10]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[11]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[12]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByTumourGroup =
                results[Constants.DATATABLE_TITLES[9]];
            Assert.AreEqual(50, avgTimeByTumourGroup.Rows[0][2]);
            Assert.AreEqual(30, avgTimeByTumourGroup.Rows[1][3]);
            Assert.AreEqual(0, avgTimeByTumourGroup.Rows[2][1]);
            //Tests the table size:
            Assert.AreEqual(3, avgTimeByTumourGroup.Rows.Count);
            Assert.AreEqual(4, avgTimeByTumourGroup.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByTumourGroup =
                results[Constants.DATATABLE_TITLES[10]];
            Assert.AreEqual(5, avgTimeToCompleteByTumourGroup.Rows[1][2]);
            Assert.AreEqual(0, avgTimeToCompleteByTumourGroup.Rows[0][3]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalQuestionsByTumourGroup =
                results[Constants.DATATABLE_TITLES[11]];
            Assert.AreEqual(2, totalQuestionsByTumourGroup.Rows[2][2]);
            Assert.AreEqual(0, totalQuestionsByTumourGroup.Rows[2][1]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByTumourGroup =
                results[Constants.DATATABLE_TITLES[12]];
            Assert.AreEqual(30, totalTimeSpentByTumourGroup.Rows[1][3]);
            Assert.AreEqual(0, totalTimeSpentByTumourGroup.Rows[1][1]);
        }
コード例 #8
0
        public void generateMpyStratifiedByRegionTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthPerYearReport(2,
                                                   2012, 2013,
                                                   _dataTypes,
                                                   Constants.StratifyOption
                                                            .Region);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[1]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[2]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[3]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[4]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByRegion = results[Constants.DATATABLE_TITLES[1]];
            Assert.AreEqual(70, avgTimeByRegion.Rows[1][2]);
            Assert.AreEqual(0, avgTimeByRegion.Rows[2][1]);
            //Tests the table size:
            Assert.AreEqual(3, avgTimeByRegion.Rows.Count);
            Assert.AreEqual(3, avgTimeByRegion.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByRegion =
                results[Constants.DATATABLE_TITLES[2]];
            Assert.AreEqual(5, avgTimeToCompleteByRegion.Rows[1][2]);
            Assert.AreEqual(0, avgTimeToCompleteByRegion.Rows[0][1]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalRequestsByRegion =
                results[Constants.DATATABLE_TITLES[3]];
            Assert.AreEqual(1, totalRequestsByRegion.Rows[1][2]);
            Assert.AreEqual(0, totalRequestsByRegion.Rows[0][1]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByRegion =
                results[Constants.DATATABLE_TITLES[4]];
            Assert.AreEqual(90, totalTimeSpentByRegion.Rows[2][2]);
            Assert.AreEqual(0, totalTimeSpentByRegion.Rows[1][1]);
        }
コード例 #9
0
        public void generateMonthlyStratifiedByRegionTest()
        {
            var reportC = new ReportManagementController(_iDataContext);
            Dictionary<string, DataTable> results =
                reportC.generateMonthlyReport(new DateTime(2013, 02, 01),
                                              new DateTime(2013, 06, 01),
                                              _dataTypes,
                                              Constants.StratifyOption.Region);

            //DataTable expectedAvgTimeByRegion = new DataTable();
            //string stratifyGroupString = Enum.GetName(typeof(Constants.StratifyOption),
            //                 Constants.StratifyOption.Region);
            //expectedAvgTimeByRegion.Columns.Add(stratifyGroupString);
            //MonthYearPair startMonthYearPair = new MonthYearPair(02, 2013);
            //for (int i = 0; i < 4; i++) {
            //    DataColumn monthColumn = new DataColumn(startMonthYearPair.ToString(), typeof(Int64)) {
            //        DefaultValue = 0
            //    };
            //    expectedAvgTimeByRegion.Columns.Add(monthColumn);
            //    startMonthYearPair.addmonth(1);
            //}

            //DataRow noRegionRow = expectedAvgTimeByRegion.NewRow();
            //noRegionRow[stratifyGroupString] = "No " + stratifyGroupString;
            //noRegionRow["Feb/2013"] = 50;
            //noRegionRow["Mar/2013"] = 110;
            //expectedAvgTimeByRegion.Rows.Add(noRegionRow);

            //DataRow bcRow = expectedAvgTimeByRegion.NewRow();
            //bcRow[stratifyGroupString] = "BC";
            //bcRow["Feb/2013"] = 70;
            //bcRow["Mar/2013"] = 60;
            //bcRow["Apr/2013"] = 50;
            //expectedAvgTimeByRegion.Rows.Add(bcRow);

            //DataRow onRow = expectedAvgTimeByRegion.NewRow();
            //onRow[stratifyGroupString] = "ON";
            //onRow["Feb/2013"] = 90;
            //onRow["Apr/2013"] = 40;
            //expectedAvgTimeByRegion.Rows.Add(onRow);

            //Tests if all dataTable is included
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[1]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[2]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[3]));
            Assert.True(results.ContainsKey(Constants.DATATABLE_TITLES[4]));

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeByRegion = results[Constants.DATATABLE_TITLES[1]];
            Assert.AreEqual(60, avgTimeByRegion.Rows[1][2]);
            Assert.AreEqual(40, avgTimeByRegion.Rows[2][4]);
            //Tests the table size:
            Assert.AreEqual(3, avgTimeByRegion.Rows.Count);
            Assert.AreEqual(5, avgTimeByRegion.Columns.Count);

            //Tests the values of random cells created to the expected value of the cell
            DataTable avgTimeToCompleteByRegion =
                results[Constants.DATATABLE_TITLES[2]];
            Assert.AreEqual(5, avgTimeToCompleteByRegion.Rows[1][1]);
            Assert.AreEqual(0, avgTimeToCompleteByRegion.Rows[0][4]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalRequestsByRegion =
                results[Constants.DATATABLE_TITLES[3]];
            Assert.AreEqual(1, totalRequestsByRegion.Rows[1][2]);
            Assert.AreEqual(0, totalRequestsByRegion.Rows[2][3]);

            //Tests the values of random cells created to the expected value of the cell
            DataTable totalTimeSpentByRegion =
                results[Constants.DATATABLE_TITLES[4]];
            Assert.AreEqual(0, totalTimeSpentByRegion.Rows[2][2]);
            Assert.AreEqual(110, totalTimeSpentByRegion.Rows[0][2]);
        }