public void Emitting_Should_invoke_logger_for_error_When_exception_is_thrown()
        {
            var thrown = new Exception("I FAILED!");

            UnitUnderTest.Subscribe(msg => throw thrown);

            UnitUnderTest.Emit(Mock.Of <Data>());

            FakeLogger.Verify(f => f.Error(It.Is <string>(m => m.Contains("Error in observer while emitting value.")), thrown), Times.Once);
        }
Beispiel #2
0
        public void TestAlerting()
        {
            var fakeLogger      = new FakeLogger();
            var reportGenerator = new TenSecondTwoMinuteReportGenerator(fakeLogger);
            var now             = DateTime.UtcNow;

            // Add 1 event at T-3 minutes and N-2 events in the past 5 seconds.
            reportGenerator.twoMinQueue.Enqueue(now.Subtract(TimeSpan.FromMinutes(3)));
            for (int i = 0; i < TenSecondTwoMinuteReportGenerator.ALERT_NUMBER - 2; i++)
            {
                reportGenerator.twoMinQueue.Enqueue(now.Subtract(TimeSpan.FromSeconds(5)));
            }
            // Generate the report for [T-5,T] minutes, should not trigger an alert as there are
            // N-1 elements in the queue.
            reportGenerator.GenerateAlertReport(
                now.Subtract(TimeSpan.FromMinutes(5)),
                now
                );

            Assert.IsTrue(!fakeLogger.Logs.Any(x => x.Contains("alert")));

            // Then add the N-th event
            reportGenerator.twoMinQueue.Enqueue(now.Subtract(TimeSpan.FromSeconds(5)));

            // Generate the report, should trigger an alert.
            reportGenerator.GenerateAlertReport(
                now.Subtract(TimeSpan.FromMinutes(5)),
                now
                );

            Assert.IsTrue(fakeLogger.Logs.Any(x => x.Contains("alert")));

            // Clear the queue and run the report again for [T-2,T] minutes,
            // should display "...recovered" as the T-3 minutes element was removed.
            fakeLogger.Logs.Clear();
            // Generate the report, should not trigger an alert.
            reportGenerator.GenerateAlertReport(
                now.Subtract(TimeSpan.FromMinutes(2)),
                now
                );

            Assert.IsTrue(fakeLogger.Logs.Any(x => x.Contains("recovered")));
        }
 public FakeLoggerFactory()
 {
     Logger = new FakeLogger();
 }