public void RecurringAlerts_ShouldBeTriggeredEveryXSeconds() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .WithIntervalSeconds(1); WaitForTrigger(testChannel, 3); Assert.AreEqual(3, testChannel.AlertCount); }
public void NonMatchingFilter_ShouldNotTriggerAlert() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object) .ForLogs("testlogid") .When(m => m.Count(p => p.StatusCode == 500) > 4) .ToChannels(testChannel) .WithIntervalSeconds(10); WaitForTrigger(testChannel); Assert.AreEqual(0, testChannel.AlertCount); }
public void FrequentErrors_ShouldSordDescending() { var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .WithIntervalSeconds(10); WaitForTrigger(testChannel); Assert.AreEqual(1, testChannel.AlertCount); }
public void ScheduledAlert_ShouldBeTriggeredAtSpecificTime() { var nextMinute = DateTime.Now.AddMinutes(1); var testChannel = new TestChannel(); AlertPolicy.Create("Test", MockApi.Object, 0) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .RunDailyAt(nextMinute.Hour, nextMinute.Minute); while (DateTime.Now.Minute != nextMinute.Minute) { //This test can take up to a monute to run due to that I can't schedule down to the second. } WaitForTrigger(testChannel); Assert.AreEqual(1, testChannel.AlertCount); }
public void OpenAlerts_ShouldBeClosedWhenFilterDoesNotMatch() { var mockApi = MockApi; var testChannel = new TestChannel(); AlertPolicy.Create("Test", mockApi.Object) .ForLogs("testlogid") .When(m => m.Any()) .ToChannels(testChannel) .WithIntervalSeconds(1); WaitForTrigger(testChannel); mockApi.Setup(m => m.GetMessages(It.IsAny <string>(), It.IsAny <FilterQuery>())) .Returns(new ElmahIoResponse { Messages = new List <Message>() }); while (testChannel.AlertCount > 0) { Thread.Sleep(100); } Assert.AreEqual(0, testChannel.AlertCount); }