public dynamic DashboardStatistics()
        {
            DashboardModel data       = this.Bind <DashboardModel>();
            string         connString = _appSettings.GetConnectionStringByName(data.ConnName);

            Task <int>      totalReportCountTask                   = Task.Run(() => _reportJobRepository.GetTotalReportCount(connString, data.StartDate, data.EndDate));
            Task <TimeSpan> avgExecutionTimeTask                   = Task.Run(() => _reportJobRepository.GetAverageExecutionTime(connString, data.StartDate, data.EndDate));
            Task <TimeSpan> avgGenerationTimeTask                  = Task.Run(() => _reportJobRepository.GetAverageGenerationTime(connString, data.StartDate, data.EndDate));
            Task <IEnumerable <ReportCount> > activeUsersTask      = Task.Run(() => _reportJobRepository.GetMostActiveUsers(connString, 10, data.StartDate, data.EndDate));
            Task <IEnumerable <ReportCount> > mostRunReportsTask   = Task.Run(() => _reportJobRepository.GetMostRunReports(connString, 10, data.StartDate, data.EndDate));
            Task <IEnumerable <ReportCount> > reportCountByDayTask = Task.Run(() => _reportJobRepository.GetReportCountByDay(connString, data.StartDate, data.EndDate));
            Task <int> errorCountTask = Task.Run(() => _reportJobRepository.GetErrorCount(connString, data.StartDate, data.EndDate));

            Task.WaitAll(totalReportCountTask, avgExecutionTimeTask, avgGenerationTimeTask, activeUsersTask, mostRunReportsTask, reportCountByDayTask, errorCountTask);

            StatisticsViewModel viewModel = new StatisticsViewModel();

            viewModel.TotalReportCount         = totalReportCountTask.Result;
            viewModel.AverageExecutionSeconds  = avgExecutionTimeTask.Result.TotalSeconds;
            viewModel.AverageGenerationSeconds = avgGenerationTimeTask.Result.TotalSeconds;
            viewModel.MostActiveUsers          = activeUsersTask.Result;
            viewModel.MostRunReports           = mostRunReportsTask.Result;
            viewModel.ReportCountByDay         = reportCountByDayTask.Result;
            viewModel.ErrorCount = errorCountTask.Result;

            return(Response.AsJson(viewModel));
        }
Exemplo n.º 2
0
        public void DashboardStatistics_OnExecute_PopulatesModel()
        {
            // setup
            Random   r                    = new Random();
            string   connName             = Guid.NewGuid().ToString();
            string   connString           = Guid.NewGuid().ToString();
            int      totalReportCount     = r.Next();
            DateTime startDate            = DateTime.Now.AddMonths(-3).AddMinutes(r.Next(10, 50));
            DateTime endDate              = DateTime.Now;
            double   avgExecutionSeconds  = r.Next(1, 10);
            double   avgGenerationSeconds = avgExecutionSeconds + 2;
            int      errorCount           = r.Next();

            DateTime startDateReceived = DateTime.MinValue;
            DateTime endDateReceived   = DateTime.MinValue;

            _appSettings.GetConnectionStringByName(connName).Returns(connString);
            _reportJobRepository.GetTotalReportCount(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(totalReportCount);
            _reportJobRepository.When(x => x.GetTotalReportCount(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>())).Do((ci) => {
                startDateReceived = ci.ArgAt <DateTime>(1);
                endDateReceived   = ci.ArgAt <DateTime>(2);
            });
            _reportJobRepository.GetAverageExecutionTime(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(TimeSpan.FromSeconds(avgExecutionSeconds));
            _reportJobRepository.GetAverageGenerationTime(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(TimeSpan.FromSeconds(avgGenerationSeconds));

            ReportCount[] activeUsers = CreateDummyReportResult();
            _reportJobRepository.GetMostActiveUsers(connString, 10, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(activeUsers);

            ReportCount[] mostRunReports = CreateDummyReportResult();
            _reportJobRepository.GetMostRunReports(connString, 10, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(mostRunReports);

            ReportCount[] reportCountByDay = CreateDummyReportResult();
            _reportJobRepository.GetReportCountByDay(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(reportCountByDay);

            _reportJobRepository.GetErrorCount(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>()).Returns(errorCount);

            var browser = CreateBrowser();

            // execute
            var response = browser.Post(Actions.Dashboard.Statistics, (with) =>
            {
                with.HttpRequest();
                with.FormValue("ConnName", connName);
                with.FormValue("StartDate", startDate.ToString(DateFormatForPost));
                with.FormValue("EndDate", endDate.ToString(DateFormatForPost));
            });
            StatisticsViewModel result = JsonConvert.DeserializeObject <StatisticsViewModel>(response.Body.AsString());

            // assert
            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            Assert.AreEqual(totalReportCount, result.TotalReportCount);
            Assert.That(startDate, Is.EqualTo(startDateReceived).Within(TimeSpan.FromSeconds(1.0)));
            Assert.That(endDate, Is.EqualTo(endDateReceived).Within(TimeSpan.FromSeconds(1.0)));
            Assert.AreEqual(avgExecutionSeconds, result.AverageExecutionSeconds);
            Assert.AreEqual(avgGenerationSeconds, result.AverageGenerationSeconds);
            Assert.AreEqual(activeUsers.Length, result.MostActiveUsers.Count());
            Assert.AreEqual(mostRunReports.Length, result.MostRunReports.Count());
            Assert.AreEqual(reportCountByDay.Length, result.ReportCountByDay.Count());
            Assert.AreEqual(errorCount, result.ErrorCount);

            _appSettings.Received(1).GetConnectionStringByName(connName);
            _reportJobRepository.Received(1).GetTotalReportCount(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetAverageExecutionTime(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetAverageGenerationTime(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetMostActiveUsers(connString, 10, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetMostRunReports(connString, 10, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetReportCountByDay(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>());
            _reportJobRepository.Received(1).GetErrorCount(connString, Arg.Any <DateTime>(), Arg.Any <DateTime>());
        }
Exemplo n.º 3
0
 public void MostRunReports_Executes_WithoutSqlErrors()
 {
     _reportJobRepository.GetMostRunReports(TestUtility.TestDbConnectionString(TestUtility.TestRootFolder), 10, DateTime.Now.AddMonths(-3), DateTime.Now);
 }