Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }