public async Task Status() { using (AmbientClock.Pause()) { Status s = new Status(false); LocalDiskAuditor lda = null; try { //System.Text.StringBuilder str = new System.Text.StringBuilder(); //str.AppendLine(); //str.AppendLine(Environment.GetFolderPath(Environment.SpecialFolder.System)); //str.AppendLine(System.IO.Path.GetTempPath()); //str.AppendLine(Path.GetPathRoot(System.IO.Path.GetTempPath())); //Assert.Fail(str.ToString()); lda = new LocalDiskAuditor(); s.AddCheckerOrAuditor(lda); await s.Start(); // run all the tests (just the one here) right now await s.RefreshAsync(); StatusAuditAlert a = s.Summary; Assert.AreEqual(StatusRatingRange.Okay, StatusRating.FindRange(a.Rating)); } finally { await s.Stop(); if (lda != null) { s.RemoveCheckerOrAuditor(lda); // note that lda could be null if the constructor throws! } } } }
public void AggregatedAlertProperties() { using (AmbientClock.Pause()) { StatusAuditAlert commonAlert = new StatusAuditAlert(.7f, "TestCode", "TerseTest", "Detailed Test Message"); StatusAuditReport report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), commonAlert); AggregatedAlert first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); Assert.IsNotNull(first.PropertyRanges); Assert.AreEqual(first.Report, report1); } }
public void StatusAuditReportMisc() { StatusAuditAlert sa = new StatusAuditAlert(StatusRating.Okay, "Okay", "terse", "detailed"); StatusAuditReport sr = new StatusAuditReport(AmbientClock.UtcNow.AddMinutes(1), TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(2), sa); Assert.AreNotEqual(StatusAuditReport.Pending, sr); Assert.AreNotEqual(StatusAuditReport.Pending.GetHashCode(), sr.GetHashCode()); Assert.AreNotEqual(sr.GetHashCode(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(5)).GetHashCode()); Assert.IsFalse(StatusAuditReport.Pending.Equals((StatusAuditReport)null)); Assert.IsFalse(StatusAuditReport.Pending !.Equals("test")); // this is a false positive in the analyzer's null detector Assert.AreNotEqual(StatusAuditReport.Pending.ToString(), sr.ToString()); }
public void StatusAuditAlertMisc() { Assert.AreNotEqual(StatusAuditAlert.Empty, StatusAuditAlert.None); Assert.AreNotEqual(StatusAuditAlert.Empty.GetHashCode(), StatusAuditAlert.None.GetHashCode()); Assert.IsFalse(StatusAuditAlert.Empty.Equals((StatusAuditAlert)null)); Assert.IsFalse(StatusAuditAlert.Empty !.Equals("test")); // the analyzer obviously gets confused when you test whether something is equal to null, even if you assert that it returns false Assert.AreNotEqual(StatusAuditAlert.Empty.ToString(), StatusAuditAlert.None.ToString()); StatusAuditAlert sa = StatusAuditAlert.Empty; Assert.ThrowsException <ArgumentNullException>(() => new StatusAuditAlert(1.0f, null !, "", "")); Assert.ThrowsException <ArgumentNullException>(() => new StatusAuditAlert(1.0f, "", null !, "")); Assert.ThrowsException <ArgumentNullException>(() => new StatusAuditAlert(1.0f, "", "", null !)); }
public void AggregatedDefaultRating() { using (AmbientClock.Pause()) { StatusAuditAlert commonAlert = new StatusAuditAlert(.7f, "TestCode", "TerseTest", "Detailed Test Message"); StatusResults results = new StatusResults("TestSource", "TestTarget", ImmutableArray <StatusResults> .Empty); AggregatedAlert alert = new AggregatedAlert(results); Assert.AreEqual(StatusRating.Okay, alert.RatingSum); StatusAuditReport report = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10)); results = new StatusResults("TestSource", "TestTarget", AmbientClock.UtcNow, 0, ImmutableArray <StatusProperty> .Empty, report); alert = new AggregatedAlert(results); Assert.AreEqual(StatusRating.Okay, alert.RatingSum); } }
public void AggregatedAlertExceptions() { using (AmbientClock.Pause()) { StatusAuditAlert alert1 = new StatusAuditAlert(.7f, "TestCode1", "TerseTest", "Detailed Test Message"); StatusAuditAlert alert2 = new StatusAuditAlert(.7f, "TestCode2", "TerseTest", "Detailed Test Message"); StatusAuditReport report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), alert1); StatusAuditReport report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), alert2); AggregatedAlert first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); AggregatedAlert second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); StatusResults secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2); Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate(secondResults)); Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2)); report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), alert1); secondResults = new StatusResults("TestSource2", "MismatchedTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2); Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate(secondResults)); Assert.ThrowsException <InvalidOperationException>(() => first.Aggregate("TestSource2", "MismatchedTarget", AmbientClock.UtcNow.AddSeconds(-10), report2)); } }
public void AggregatedAlertCanBeAggregated() { using (AmbientClock.Pause()) { StatusAuditAlert alert1 = new StatusAuditAlert(.7f, "TestCode1", "TerseTest", "Detailed Test Message"); StatusAuditAlert alert2 = new StatusAuditAlert(.7f, "TestCode2", "TerseTest", "Detailed Test Message"); StatusAuditReport report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), alert1); StatusAuditReport report1NoAlert = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), null); StatusAuditReport report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), alert2); StatusAuditReport report2NoAlert = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), null); AggregatedAlert first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); AggregatedAlert second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); Assert.IsFalse(first.CanBeAggregated("/", report2)); Assert.IsFalse(first.CanBeAggregated("/", report2NoAlert)); Assert.IsFalse(first.CanBeAggregated("/", null)); Assert.IsTrue(first.CanBeAggregated("TestTarget", report1)); Assert.IsFalse(first.CanBeAggregated("TestTarget", report1NoAlert)); Assert.IsFalse(first.CanBeAggregated("TestTarget", null)); } }
public async Task StatusClass() { await Status.DefaultInstance.Start(); Assert.IsFalse(Status.DefaultInstance.ShuttingDown); try { DateTime start = AmbientClock.UtcNow; await Status.DefaultInstance.RefreshAsync(); StatusResults overallStatus = Status.DefaultInstance.Results; Assert.AreEqual("/", overallStatus.TargetSystem); Assert.AreEqual(0, overallStatus.RelativeDetailLevel); Assert.AreEqual(StatusNatureOfSystem.ChildrenHeterogenous, overallStatus.NatureOfSystem); Assert.AreEqual(0, overallStatus.Properties.Count()); Assert.IsTrue(overallStatus.Children.Count() > 0); Assert.IsFalse(string.IsNullOrEmpty(overallStatus.ToString())); StatusResults sampleDisk = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == "SampleDisk" && c.Children.Any()) as StatusResults; Assert.IsNotNull(sampleDisk); StatusResults disk = sampleDisk !.Children.FirstOrDefault() as StatusResults; Assert.IsNotNull(disk); Assert.IsTrue(disk !.Properties.Count() > 0); // the properties in the node itself are the constant properties, ie. the path for a disk test Assert.IsFalse(string.IsNullOrEmpty(sampleDisk !.ToString())); StatusProperty att = disk.Properties.FirstOrDefault(a => a.Name == "TotalBytes"); Assert.IsNotNull(att); Assert.IsFalse(string.IsNullOrEmpty(att !.ToString())); Assert.IsFalse(String.IsNullOrEmpty(att !.Name)); Assert.IsFalse(String.IsNullOrEmpty(att !.Value)); HashSet <StatusResults> test = new HashSet <StatusResults>(); StatusResults c1 = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestHeterogenousExplicitRating)); Assert.IsNotNull(c1); Assert.IsNotNull(c1 !.Report); Assert.IsNotNull(c1 !.Report?.Alert?.Rating); Assert.IsFalse(string.IsNullOrEmpty(c1 !.ToString())); test.Add(c1); StatusResults c2 = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestHomogeneousExplicitFailure)); Assert.IsNotNull(c2); Assert.IsNotNull(c2 !.Report); Assert.IsNotNull(c2 !.Report?.Alert?.Rating); Assert.AreNotEqual(c1 !.Report?.Alert, c2 !.Report?.Alert); Assert.IsFalse(string.IsNullOrEmpty(c2 !.ToString())); test.Add(c2); StatusResults c3 = overallStatus.Children.FirstOrDefault(c => c.TargetSystem == nameof(TestMachineConstantStatus)); Assert.IsNotNull(c3); Assert.IsNull(c3 !.Report); Assert.IsFalse(string.IsNullOrEmpty(c3 !.ToString())); test.Add(c3); StatusAuditAlert auditResult = overallStatus.GetSummaryAlerts(true, StatusRating.Alert, false); Assert.AreEqual(0, overallStatus.Properties.Count()); HashSet <StatusAuditReport> test3 = new HashSet <StatusAuditReport>(); Assert.IsTrue(auditResult.Rating >= -1.0f && auditResult.Rating <= 4.0f); Assert.IsFalse(string.IsNullOrEmpty(auditResult.Terse)); Assert.IsFalse(string.IsNullOrEmpty(auditResult.Details)); Assert.IsTrue(overallStatus.SourceSystem == null); Assert.IsTrue(auditResult.Rating <= StatusRating.Fail); Assert.IsFalse(string.IsNullOrEmpty(auditResult.ToString())); AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(100)); await Status.DefaultInstance.RefreshAsync(); overallStatus = Status.DefaultInstance.Results; StatusAuditAlert notOkayResult = overallStatus.GetSummaryAlerts(true, StatusRating.Okay, false); StatusAuditAlert fullResult = overallStatus.GetSummaryAlerts(true, float.MaxValue, false); StatusAuditAlert overallSummaryAlerts = Status.DefaultInstance.Summary; Assert.IsTrue(overallSummaryAlerts.Rating <StatusRating.Fail && overallSummaryAlerts.Rating> StatusRating.Catastrophic); StatusAuditAlert overallSummaryAlertsAndFailures = Status.DefaultInstance.SummaryAlertsAndFailures; Assert.IsTrue(overallSummaryAlertsAndFailures.Rating <StatusRating.Fail && overallSummaryAlertsAndFailures.Rating> StatusRating.Catastrophic); StatusAuditAlert overallSummaryFailures = Status.DefaultInstance.SummaryFailures; Assert.IsTrue(overallSummaryFailures.Rating <StatusRating.Fail && overallSummaryFailures.Rating> StatusRating.Catastrophic); } finally { await Status.DefaultInstance.Stop(); } }
public void AggregatedAlertAggregate() { using (AmbientClock.Pause()) { StatusAuditAlert commonAlert = new StatusAuditAlert(.7f, "TestCode", "TerseTest", "Detailed Test Message"); StatusAuditReport report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10), commonAlert); StatusAuditReport report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10), commonAlert); AggregatedAlert first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); AggregatedAlert second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); StatusResults secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2); first.Aggregate(secondResults); report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10)); report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10)); first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, report2); first.Aggregate(secondResults); Assert.AreEqual(StatusRating.Okay, first.AverageRating); first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2); Assert.AreEqual(StatusRating.Okay, first.AverageRating); //report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1)); //report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2)); //first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); //second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); //secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray<StatusProperty>.Empty, report2); //first.Aggregate(secondResults); //Assert.AreEqual(StatusRating.Okay, first.AverageRating); //first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), report2); //Assert.AreEqual(StatusRating.Okay, first.AverageRating); report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1)); report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2)); first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, report1); second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, report2); secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(50), AmbientClock.UtcNow.AddSeconds(5))); first.Aggregate(secondResults); Assert.AreEqual(StatusRating.Okay, first.AverageRating); first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(50), AmbientClock.UtcNow.AddSeconds(5))); Assert.AreEqual(StatusRating.Okay, first.AverageRating); first = new AggregatedAlert("TestSource1", "TestTarget", DateTime.MinValue, null); second = new AggregatedAlert("TestSource2", "TestTarget", DateTime.MinValue, null); secondResults = new StatusResults("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, null); first.Aggregate(secondResults); Assert.AreEqual(StatusRating.Okay, first.AverageRating); first.Aggregate("TestSource2", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), null); Assert.AreEqual(StatusRating.Okay, first.AverageRating); report1 = new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(1), AmbientClock.UtcNow.AddMinutes(10)); report2 = new StatusAuditReport(AmbientClock.UtcNow.AddSeconds(-10), TimeSpan.FromSeconds(2), AmbientClock.UtcNow.AddSeconds(-10).AddMinutes(10)); first = new AggregatedAlert("TestSource", "TestTarget", DateTime.MinValue, report1); second = new AggregatedAlert("TestSource", "TestTarget", DateTime.MinValue, report2); secondResults = new StatusResults("TestSource", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), 0, ImmutableArray <StatusProperty> .Empty, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(13))); first.Aggregate(secondResults); Assert.AreEqual(StatusRating.Okay, first.AverageRating); first.Aggregate("TestSource", "TestTarget", AmbientClock.UtcNow.AddSeconds(-10), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(13))); Assert.AreEqual(StatusRating.Okay, first.AverageRating); } }