public void Given_Well_Formed_Alert_Behaviour_Will_Publish_All_Results_Even_Healthy() { // Arrange var ok = false; var httpendpointhealthcheck = new ServiceHealthCheck() { Name = "testhealthcheckalways", HealthCheckConditions = new HealthCheckConditions() { HttpBehaviour = new HttpBehaviour() { HttpExpectedCode = 200, HttpTimeoutMs = 1000, HttpVerb = HttpVerb.Get }, }, AlertBehaviour = new List <AlertBehaviour>() { new AlertBehaviour() { AlertEvery = TimeSpan.FromSeconds(5), AlertOnServiceRecovered = true, TransportName = "Dummy", TransportMethod = AlertTransportMethod.Email, PublishAllResults = true } }, EndpointOrHost = "https://www.google.com", MonitoringInterval = TimeSpan.FromSeconds(1), ServiceType = ServiceType.Http, Alert = true }; var alertPublisher2 = new DictionaryPublisher(healthChecksBuilder, httpendpointhealthcheck, alertTransportSettings); var dic = new Dictionary <string, HealthReportEntry>(); dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Healthy, "", TimeSpan.Zero, null, null)); var healthobserver = new Mock <IObserver <HealthReport> >(); healthobserver.Setup( observer => observer.OnNext(It.IsAny <HealthReport>())).Callback(() => { ok = !ok; }); var healthReportMock = new HealthReport(dic, TimeSpan.Zero); alertPublisher2.Subscribe(healthobserver.Object); //Act alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); //Assert Assert.IsTrue(ok); }
public void Setup() { var healthcheckbuildermock = new Moq.Mock <IHealthChecksBuilder>(); healthcheckbuildermock .Setup(m => m.Services) .Returns(new ServiceCollection()); healthChecksBuilder = healthcheckbuildermock.Object; httpendpointhealthcheck = new ServiceHealthCheck() { Name = "testhealthcheck", HealthCheckConditions = new HealthCheckConditions() { HttpBehaviour = new HttpBehaviour() { HttpExpectedCode = 200, HttpVerb = HttpVerb.Get }, }, AlertBehaviour = new List <AlertBehaviour>() { new AlertBehaviour() { AlertEvery = TimeSpan.FromSeconds(5), AlertOnServiceRecovered = true, TransportName = "Dummy", TransportMethod = AlertTransportMethod.Email } }, EndpointOrHost = "https://www.google.com", MonitoringInterval = TimeSpan.FromSeconds(1), ServiceType = ServiceType.Http, Alert = true }; alertTransportSettings = new DictionaryTransportSettings() { Name = "Dummy", }; alertPublisher = new DictionaryPublisher(healthChecksBuilder, httpendpointhealthcheck, alertTransportSettings); }
public void Unhealthy_Check_Count_Should_Reset_To_0_When_Healthy() { // Arrange var ok = true; var httpendpointhealthcheck = new ServiceHealthCheck() { Name = "testhealthcheckalways", HealthCheckConditions = new HealthCheckConditions() { HttpBehaviour = new HttpBehaviour() { HttpExpectedCode = 200, HttpVerb = HttpVerb.Get }, }, AlertBehaviour = new List <AlertBehaviour>() { new AlertBehaviour() { AlertByFailCount = 5, AlertOnServiceRecovered = true, TransportName = "Dummy", TransportMethod = AlertTransportMethod.Email, PublishAllResults = false } }, EndpointOrHost = "https://www.google.com", MonitoringInterval = TimeSpan.FromSeconds(1), ServiceType = ServiceType.Http, Alert = true }; var alertPublisher2 = new DictionaryPublisher(healthChecksBuilder, httpendpointhealthcheck, alertTransportSettings); var dic = new Dictionary <string, HealthReportEntry>(); dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Unhealthy, "", TimeSpan.Zero, null, null)); var healthobserver = new Mock <IObserver <HealthReport> >(); healthobserver.Setup( observer => observer.OnNext(It.IsAny <HealthReport>())).Callback(() => { ok = !ok; }); var healthReportMock = new HealthReport(dic, TimeSpan.Zero); alertPublisher2.Subscribe(healthobserver.Object); //Act alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); //Assert Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 1); alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 2); alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 3); alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 4); dic.Clear(); dic.Add("testhealthcheckalways", new HealthReportEntry(HealthStatus.Healthy, "", TimeSpan.Zero, null, null)); alertPublisher2.PublishAsync(healthReportMock, new CancellationToken()); Assert.AreEqual(httpendpointhealthcheck.AlertBehaviour.First().FailedCount, 0); }
void OnEnable() { publisher = target as DictionaryPublisher; }