Esempio n. 1
0
        public void PingFailureNoData()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            // Act
            var actual = discrepancyService
                         .FindPingFailuresFromDataPoints(
                new List <PingDataPoint>(),
                new PingSetting {
                MaxFailures = 1
            },
                new Metric
            {
                Type   = Metrics.Ping.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Empty(actual);
        }
Esempio n. 2
0
        public void NoPingFailures()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            var input = new List <PingDataPoint>()
            {
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 0, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 1, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.ServiceUnavailable.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 2, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 3, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 4, 0)
                },
            };

            // Act
            var actual = discrepancyService
                         .FindPingFailuresFromDataPoints(
                input,
                new PingSetting {
                MaxFailures = 1
            },
                new Metric
            {
                Type   = Metrics.Ping.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Empty(actual);
        }
Esempio n. 3
0
        public void MultiplePingFailures()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            var input = new List <PingDataPoint>()
            {
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 0, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.ServiceUnavailable.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 1, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.ServiceUnavailable.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 2, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.OK.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 3, 0)
                },
                new PingDataPoint {
                    HttpStatusCode = HttpStatusCode.ServiceUnavailable.AsInt(),
                    Timestamp      = DateTime.UtcNow - new TimeSpan(0, 4, 0)
                },
            };

            var expected = new List <Discrepancy> {
                new Discrepancy
                {
                    DateFirstOffense = input[4].Timestamp,
                    Type             = DiscrepancyType.PingFailedNTimes,
                    MetricType       = Metrics.Ping,
                    MetricSource     = "the-source"
                },
                new Discrepancy
                {
                    DateFirstOffense = input[2].Timestamp,
                    Type             = DiscrepancyType.PingFailedNTimes,
                    MetricType       = Metrics.Ping,
                    MetricSource     = "the-source"
                }
            }
            .OrderBy(d => d.DateFirstOffense);;

            // Act
            var actual = discrepancyService
                         .FindPingFailuresFromDataPoints(
                input,
                new PingSetting {
                MaxFailures = 0
            },
                new Metric
            {
                Type   = Metrics.Ping.AsInt(),
                Source = "the-source"
            }
                )
                         .OrderBy(d => d.DateFirstOffense);;

            // Assert
            Assert.Equal(expected, actual);
        }
Esempio n. 4
0
        public void PingFailuresDataStartsWithFailure()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            var input = new List <PingDataPoint>()
            {
                new PingDataPoint {
                    Success   = true,
                    Timestamp = DateTime.UtcNow.AddMinutes(0)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow.AddMinutes(-1)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow.AddMinutes(-2)
                },
                new PingDataPoint {
                    Success   = true,
                    Timestamp = DateTime.UtcNow.AddMinutes(-3)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow.AddMinutes(-4)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow.AddMinutes(-5)
                }
            };

            var expected = new List <Discrepancy> {
                new Discrepancy
                {
                    DateFirstOffense = input[2].Timestamp,
                    Type             = DiscrepancyType.PingFailedNTimes,
                    MetricType       = Metrics.Ping,
                    MetricSource     = "the-source"
                }
            }
            .OrderBy(d => d.DateFirstOffense);;

            // Act
            var actual = discrepancyService
                         .FindPingFailuresFromDataPoints(
                input,
                new PingSetting {
                MaxFailures = 0
            },
                new Metric
            {
                Type   = Metrics.Ping.AsInt(),
                Source = "the-source"
            }
                )
                         .OrderBy(d => d.DateFirstOffense);;

            // Assert
            Assert.Equal(expected, actual);
        }
Esempio n. 5
0
        public void SinglePingFailure()
        {
            // Arrange
            var discrepancyService = new DiscrepancyService(
                new Mock <ILogger <DiscrepancyService> >().Object,
                new Mock <IDataContext>().Object,
                new Mock <INotificationService>().Object,
                new Mock <IConfiguration>().Object
                );

            var input = new List <PingDataPoint>()
            {
                new PingDataPoint {
                    Success   = true,
                    Timestamp = DateTime.UtcNow - new TimeSpan(0, 0, 0)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow - new TimeSpan(0, 1, 0)
                },
                new PingDataPoint {
                    Success   = false,
                    Timestamp = DateTime.UtcNow - new TimeSpan(0, 2, 0)
                },
                new PingDataPoint {
                    Success   = true,
                    Timestamp = DateTime.UtcNow - new TimeSpan(0, 3, 0)
                },
                new PingDataPoint {
                    Success   = true,
                    Timestamp = DateTime.UtcNow - new TimeSpan(0, 4, 0)
                },
            };

            var expected = new List <Discrepancy> {
                new Discrepancy
                {
                    DateFirstOffense = input[2].Timestamp,
                    Type             = DiscrepancyType.PingFailedNTimes,
                    MetricType       = Metrics.Ping,
                    MetricSource     = "the-source"
                }
            };

            // Act
            var actual = discrepancyService
                         .FindPingFailuresFromDataPoints(
                input,
                new PingSetting {
                MaxFailures = 1
            },
                new Metric
            {
                Type   = Metrics.Ping.AsInt(),
                Source = "the-source"
            }
                );

            // Assert
            Assert.Equal(expected, actual);
        }