public void NoAlertWhenNoReachedThreshold() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { 100 }); alerter.ThresholdReached += handler.AlertHandler; alerter.Check(0); alerter.Check(50); alerter.Check(99); Assert.Equal(0, handler.CallCount); }
public void AlertOnceOnReachedThreshold() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { 10 }); alerter.ThresholdReached += handler.AlertHandler; // Alert alerter.Check(10); Assert.Equal(1, handler.CallCount); // No alert, already reached 10 alerter.Check(11); Assert.Equal(1, handler.CallCount); }
public void NoThresholds() { var alerter = new ThresholdAlerterV2(Enumerable.Empty <int>()); // No exceptions alerter.Check(0); }
public void AlertWhenValueGoesDownAndUpThreshold() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { 10, 20 }); alerter.ThresholdReached += handler.AlertHandler; // Alert alerter.Check(20); Assert.Equal(1, handler.CallCount); Assert.Equal(20, handler.ReachedThreshold); // No alert alerter.Check(0); Assert.Equal(1, handler.CallCount); // Alert again alerter.Check(17); Assert.Equal(2, handler.CallCount); Assert.Equal(10, handler.ReachedThreshold); }
public void UnsortedThresholds(int value, int expectedThreshold) { int actualThreshold = 0; var alerter = new ThresholdAlerterV2(new[] { 10, 30, 20, 40 }); alerter.ThresholdReached += t => actualThreshold = t; alerter.Check(value); Assert.Equal(expectedThreshold, actualThreshold); }
public void BoundValues(int value, int threshold, int callCount) { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { threshold }); alerter.ThresholdReached += handler.AlertHandler; alerter.Check(value); Assert.Equal(callCount, handler.CallCount); }
public void AlertOnceWhenPassedSeveralThresholds() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { 10, 20 }); alerter.ThresholdReached += handler.AlertHandler; alerter.Check(30); Assert.Equal(1, handler.CallCount); Assert.Equal(20, handler.ReachedThreshold); }
public void AlertWhenReachedThreshold() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(new[] { 10 }); alerter.ThresholdReached += handler.AlertHandler; alerter.Check(10); Assert.Equal(1, handler.CallCount); Assert.Equal(10, handler.ReachedThreshold); }
public void Smoke() { bool alerted = false; var alerter = new ThresholdAlerterV2(new[] { 10 }); alerter.ThresholdReached += x => { alerted = true; Assert.Equal(10, x); }; alerter.Check(10); Assert.True(alerted); }
public void ManyChecks() { var handler = new HandlerMock(); var alerter = new ThresholdAlerterV2(Enumerable.Range(0, 100).Select(i => i * 10)); alerter.ThresholdReached += handler.AlertHandler; for (int i = 0; i < 10000; i++) { alerter.Check(i); } Assert.Equal(100, handler.CallCount); Assert.Equal(990, handler.ReachedThreshold); }