Ejemplo n.º 1
0
        public void UptimeScoring_ScoreMetricsAsync_NoMetricDatas()
        {
            // Arrange
            var metricDatas   = new List <MetricData>();
            var categoryScore = new CategoryScore();

            // Act & Assert
            var logic = new UptimeScoringLogic(uptimeRatingsRepository.Object, maintenanceWindowRepository.Object, logger.Object);

            Assert.ThrowsAsync <Exception>(() => logic.ScoreMetrics(categoryScore, metricDatas), "Cannot score empty list of metric data.");
        }
Ejemplo n.º 2
0
        public async Task UptimeScoring_ScoreMetricsAsync(double?webUptimeScore, double?agentUptimeScore, bool useWebUptimeMetricData, bool useAgentUptimeMetricData, double expectedResult, bool inMaintenanceWindow)
        {
            // Arrange
            var hour                = DateTime.Now;
            var webUptime           = webUptimeScore.HasValue ? Convert.ToDecimal(webUptimeScore.Value) : (decimal?)null;
            var agentUptime         = agentUptimeScore.HasValue ? Convert.ToDecimal(agentUptimeScore.Value) : (decimal?)null;
            var webUptimeMetricData = new MetricData {
                Score = webUptime, Metric = new Metric {
                    MetricType = MetricType.WebUptime, Hour = new Hour {
                        HourTimeStamp = hour
                    }
                }
            };
            var agentUptimeMetricData = new MetricData {
                Score = agentUptime, Metric = new Metric {
                    MetricType = MetricType.AgentUptime, Hour = new Hour {
                        HourTimeStamp = hour
                    }
                }
            };

            var metricDatas = new List <MetricData>();

            if (useWebUptimeMetricData)
            {
                metricDatas.Add(webUptimeMetricData);
            }
            if (useAgentUptimeMetricData)
            {
                metricDatas.Add(agentUptimeMetricData);
            }

            this.uptimeRatingsRepository.Setup(r => r.Create(It.IsAny <decimal>(), hour, It.IsAny <bool>(), inMaintenanceWindow)).Returns(Task.Delay(10));
            this.uptimeRatingsRepository.Setup(r => r.UpdateWeeklyScores()).Returns(Task.Delay(10));
            this.uptimeRatingsRepository.Setup(r => r.UpdateQuartlyScores(hour)).Returns(Task.Delay(10));
            if (metricDatas.Count > 0)
            {
                this.maintenanceWindowRepository.Setup(r => r.HourIsInMaintenanceWindowAsync(metricDatas[0].Metric.Hour)).ReturnsAsync(inMaintenanceWindow);
            }

            var categoryScore = new CategoryScore();

            // Act
            var logic  = new UptimeScoringLogic(uptimeRatingsRepository.Object, maintenanceWindowRepository.Object, logger.Object);
            var result = await logic.ScoreMetrics(categoryScore, metricDatas);

            // Assert
            Assert.That(Math.Round(result, 3), Is.EqualTo(Convert.ToDecimal(expectedResult)));
            this.uptimeRatingsRepository.Verify(r => r.Create(It.IsAny <decimal>(), hour, It.IsAny <bool>(), inMaintenanceWindow));
        }
Ejemplo n.º 3
0
        public async Task UptimeScoring_ScoreMetricsAsync_WebDowntime(double?webUptimeScore, double?agentUptimeScore, bool expectedWebDowntimeResult)
        {
            // Arrange
            var hour                = DateTime.Now;
            var webUptime           = webUptimeScore.HasValue ? Convert.ToDecimal(webUptimeScore.Value) : (decimal?)null;
            var agentUptime         = agentUptimeScore.HasValue ? Convert.ToDecimal(agentUptimeScore.Value) : (decimal?)null;
            var webUptimeMetricData = new MetricData {
                Score = webUptime, Metric = new Metric {
                    MetricType = MetricType.WebUptime, Hour = new Hour {
                        HourTimeStamp = hour
                    }
                }
            };
            var agentUptimeMetricData = new MetricData {
                Score = agentUptime, Metric = new Metric {
                    MetricType = MetricType.AgentUptime, Hour = new Hour {
                        HourTimeStamp = hour
                    }
                }
            };

            var metricDatas = new List <MetricData> {
                agentUptimeMetricData, webUptimeMetricData
            };

            this.uptimeRatingsRepository.Setup(r => r.Create(It.IsAny <decimal>(), hour, expectedWebDowntimeResult, false)).Returns(Task.Delay(1));
            this.uptimeRatingsRepository.Setup(r => r.UpdateWeeklyScores()).Returns(Task.Delay(1));
            this.uptimeRatingsRepository.Setup(r => r.UpdateQuartlyScores(hour)).Returns(Task.Delay(1));
            if (metricDatas.Count > 0)
            {
                this.maintenanceWindowRepository.Setup(r => r.HourIsInMaintenanceWindowAsync(metricDatas[0].Metric.Hour)).ReturnsAsync(false);
            }

            var categoryScore = new CategoryScore();

            // Act
            var   logic  = new UptimeScoringLogic(uptimeRatingsRepository.Object, maintenanceWindowRepository.Object, logger.Object);
            var   result = logic.ScoreMetrics(categoryScore, metricDatas);
            await result;

            // Assert
            this.uptimeRatingsRepository.Verify(r => r.Create(It.IsAny <decimal>(), hour, expectedWebDowntimeResult, false));
        }
Ejemplo n.º 4
0
        public async Task UptimeScoring_ScoreMetricsAsync_NoUptimes()
        {
            // Arrange
            var someOtherMetricData = new MetricData {
                Metric = new Metric {
                    MetricType = MetricType.Ram
                }
            };

            var metricDatas = new List <MetricData>()
            {
                someOtherMetricData
            };
            var categoryScore = new CategoryScore();
            // Act
            var logic  = new UptimeScoringLogic(uptimeRatingsRepository.Object, maintenanceWindowRepository.Object, logger.Object);
            var result = await logic.ScoreMetrics(categoryScore, metricDatas);

            // Assert
            Assert.That(result, Is.EqualTo(100m));
        }