Beispiel #1
0
 public void StatusResultsBuilderExceptions()
 {
     using (AmbientClock.Pause())
     {
         StatusResultsBuilder test = new StatusResultsBuilder(nameof(StatusResultsBuilder));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddException(new ApplicationException(), -1.0f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddFailure("Fail", "Terse", "Details", -0.1f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddAlert("Alert", "Terse", "Details", -0.001f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddAlert("Alert", "Terse", "Details", 1.001f));
         Assert.ThrowsException <ArgumentOutOfRangeException>(() => test.AddOkay("Okay", "Terse", "Details", 1.1f));
         Assert.ThrowsException <ArgumentNullException>(() => new StatusResultsBuilder((StatusResults)null !));
         Assert.ThrowsException <ArgumentNullException>(() => new StatusResultsBuilder((StatusChecker)null !));
     }
 }
Beispiel #2
0
 private void Recurse(StatusResultsBuilder statusBuilder, int level, int sourceNumber)
 {
     if (level == 0)
     {
         statusBuilder.NatureOfSystem = StatusNatureOfSystem.Leaf;
         if (sourceNumber < 3)
         {
             statusBuilder.AddOkay(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Okay", "This is the multiple source okay", 0.5f);
         }
         else if (sourceNumber < 6)
         {
             statusBuilder.AddAlert(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Alert", "This is the multiple source alert", 0.5f);
         }
         else
         {
             statusBuilder.AddFailure(nameof(TestDeepMultipleSource), "test-" + nameof(TestMultipleSource) + "Fail", "This is the multiple source failure", 0.5f);
         }
     }
     else
     {
         if (level % 2 == 0)
         {
             statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
         }
         StatusResultsBuilder child = new StatusResultsBuilder("Level" + level.ToString());
         child.AddProperty("Level", level);
         child.AddProperty("SourceNumber", sourceNumber);
         Recurse(child, level - 1, sourceNumber);
         statusBuilder.AddChild(child.FinalResults);
     }
 }
Beispiel #3
0
        public void StatusResultsBuilderWorstAlert()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsBuilder test;

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddException(new ExpectedException(), 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.5f, test.WorstAlert?.Rating);
                test.AddException(new ExpectedException(), 0.6f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);
                test.AddException(new ExpectedException(), 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddFailure("Fail", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.5f, test.WorstAlert?.Rating);
                test.AddFailure("Fail", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);
                test.AddFailure("Fail", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Fail - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Alert - 0.5f, test.WorstAlert?.Rating);
                test.AddAlert("Alert", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Alert - 0.6f, test.WorstAlert?.Rating);
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Alert - 0.6f, test.WorstAlert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderWorstAlert));
                Assert.IsNull(test.WorstAlert);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Okay - 0.5f, test.WorstAlert?.Rating);
                test.AddOkay("Okay", "Terse", "Details", 0.6f);
                Assert.AreEqual(StatusRating.Okay - 0.6f, test.WorstAlert?.Rating);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                Assert.AreEqual(StatusRating.Okay - 0.6f, test.WorstAlert?.Rating);
            }
        }
Beispiel #4
0
 private void AddSource(StatusResultsBuilder statusBuilder, int sourceNumber)
 {
     if (sourceNumber < 3)
     {
         statusBuilder.AddOkay(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Okay", "This is the multiple source okay", 0.5f);
     }
     else if (sourceNumber < 6)
     {
         statusBuilder.AddAlert(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Alert", "This is the multiple source alert", 0.5f);
     }
     else
     {
         statusBuilder.AddFailure(nameof(TestMultipleSource), "test-" + nameof(TestMultipleSource) + "Fail", "This is the multiple source failure", 0.5f);
     }
     statusBuilder.SourceSystem = "Source " + sourceNumber.ToString();
 }
Beispiel #5
0
 public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
 {
     statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
     if (_rating <= StatusRating.Fail)
     {
         statusBuilder.AddFailure(_auditCode, _terse, _details, _rating);
     }
     else if (_rating <= StatusRating.Alert)
     {
         statusBuilder.AddAlert(_auditCode, _terse, _details, StatusRating.Alert - _rating);
     }
     else
     {
         statusBuilder.AddOkay(_auditCode, _terse, _details, StatusRating.Okay - _rating);
     }
     return(Task.CompletedTask);
 }
Beispiel #6
0
        public void StatusResultsBuilderFinalResults()
        {
            using (AmbientClock.Pause())
            {
                StatusResults        results;
                StatusResultsBuilder test;

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderFinalResults));
                test.AuditDuration = null;
                test.AddAlert("Alert", "Terse", "Details", 0.5f);
                results = test.FinalResults;
                Assert.AreEqual(StatusRating.Alert - 0.5f, results.Report?.Alert?.Rating);

                test = new StatusResultsBuilder(nameof(StatusResultsBuilderFinalResults));
                test.AuditDuration = TimeSpan.FromMilliseconds(100);
                test.AddOkay("Okay", "Terse", "Details", 0.5f);
                results = test.FinalResults;
                Assert.AreEqual(StatusRating.Okay - 0.5f, results.Report?.Alert?.Rating);
            }
        }
Beispiel #7
0
        public override async Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenHeterogenous;
            foreach (SampleVolumeAuditor da in _diskAuditors)
            {
                try
                {
                    StatusResultsBuilder childResults = await da.GetStatus(cancel);

                    statusBuilder.AddChild(childResults);
                }
                catch (Exception ex)
                {
                    statusBuilder.AddException(ex);
                }
            }
            statusBuilder.AddProperty("wc1", "a");
            statusBuilder.AddProperty("wc2", "b");
            statusBuilder.AddProperty("wc2", AmbientClock.UtcNow.AddMinutes(-10));
            statusBuilder.AddAlert("TestAlertCode", "test-terseAlert", "This is the detailed alert message", 0.1f);
        }
        public override Task Audit(StatusResultsBuilder statusBuilder, CancellationToken cancel = default(CancellationToken))
        {
            statusBuilder.NatureOfSystem = StatusNatureOfSystem.ChildrenIrrelevant;
            StatusRatingRange currentAuditRating = (StatusRatingRange)(_auditNumber++ % (int)EnumExtensions.MaxEnumValue <StatusRatingRange>());
            float             rating             = (StatusRating.GetRangeUpperBound(currentAuditRating) + StatusRating.GetRangeLowerBound(currentAuditRating)) / 2;

            if (rating <= StatusRating.Fail)
            {
                statusBuilder.AddFailure("FailCode", "Fail", "The system has failed!", StatusRating.Fail - rating);
            }
            else if (rating <= StatusRating.Alert)
            {
                statusBuilder.AddAlert("AlertCode", "Alert", "The system has alerted!", StatusRating.Alert - rating);
            }
            else if (rating <= StatusRating.Okay)
            {
                statusBuilder.AddOkay("OkayCode", "Okay", "The system is okay", StatusRating.Okay - rating);
            }
            else
            {
                statusBuilder.AddOkay("SuperCode", "Superlative", "The system is superlative", StatusRating.Superlative - rating);
            }
            return(Task.CompletedTask);
        }