Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <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();
        }
Esempio n. 3
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]);
        }
Esempio n. 4
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]);
        }