Exemple #1
0
    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);
    }
Exemple #2
0
    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);
    }
Exemple #3
0
    public void NoThresholds()
    {
        var alerter = new ThresholdAlerterV2(Enumerable.Empty <int>());

        // No exceptions
        alerter.Check(0);
    }
Exemple #4
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);
    }
Exemple #5
0
    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);
    }
Exemple #6
0
    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);
    }
Exemple #7
0
    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);
    }
Exemple #8
0
    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);
    }
Exemple #9
0
    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);
    }
Exemple #10
0
    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);
    }