예제 #1
0
        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!
                    }
                }
            }
        }
예제 #2
0
        public void StatusResultsOrganizerPropertiesWorse()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.0"), new StatusProperty("AvailablePercent", "2.1") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                        new StatusResults(null, "/SampleDisk.Temp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.2"), new StatusProperty("AvailableBytes", "1100000000.0") }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromSeconds(3), AmbientClock.UtcNow.AddSeconds(2), new StatusAuditAlert(StatusRating.Okay - .0001f, "ALERT", "Alert", "AlertDetails"))),
                        new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()),
                    }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
예제 #3
0
        public void StatusResultsOrganizerTime()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow.AddSeconds(5), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                AmbientClock.SkipAhead(TimeSpan.FromSeconds(10));
                StatusResults source3Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Target1", AmbientClock.UtcNow.AddSeconds(1), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow.AddSeconds(1), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow.AddSeconds(3), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part2", AmbientClock.UtcNow.AddSeconds(3), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target3", AmbientClock.UtcNow.AddSeconds(2), 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part3", AmbientClock.UtcNow.AddSeconds(2), 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                organizer.Add(organizer, source1Root);
                organizer.Add(organizer, source2Root);
                organizer.Add(organizer, source3Root);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
예제 #4
0
        public void StatusResultsOrganizerPending()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenIrrelevant, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusAuditReport.Pending) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                Assert.IsTrue(organizer.SomeRatingsPending);
                o = organizer.Children.First().ToString();
            }
        }
예제 #5
0
        public void StatusPropertyRange()
        {
            using (AmbientClock.Pause())
            {
                // first test with a single property value
                StatusPropertyRange range = new StatusPropertyRange(new StatusProperty("property", "5"));

                Assert.IsTrue(range.ToString().Contains("5"));

                // now add another property value
                range.Merge("10");

                Assert.IsTrue(range.ToString().Contains("5"));
                Assert.IsTrue(range.ToString().Contains("10"));

                // now add another property value in the middle
                range.Merge("7");

                Assert.IsTrue(range.ToString().Contains("5"));
                Assert.IsTrue(range.ToString().Contains("10"));
                Assert.IsFalse(range.ToString().Contains("7"));

                // now add another property value
                range.Merge("2");

                Assert.IsTrue(range.ToString().Contains("2"));
                Assert.IsTrue(range.ToString().Contains("10"));
                Assert.IsFalse(range.ToString().Contains("7"));
                Assert.IsFalse(range.ToString().Contains("5"));
            }
        }
예제 #6
0
        public void StatusResultsBuilder()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsBuilder test = new StatusResultsBuilder(nameof(StatusResultsBuilder));

                Assert.IsNull(test.AuditDuration);
                test.AuditDuration = TimeSpan.FromSeconds(137);
                Assert.AreEqual(TimeSpan.FromSeconds(137), test.AuditDuration);

                Assert.AreEqual(AmbientClock.UtcNow, test.AuditStartTime);
                test.AuditStartTime = DateTime.MinValue;
                Assert.AreEqual(DateTime.MinValue, test.AuditStartTime);

                test.NatureOfSystem = StatusNatureOfSystem.Leaf;
                Assert.AreEqual(StatusNatureOfSystem.Leaf, test.NatureOfSystem);

                Assert.IsNull(test.NextAuditTime);
                test.NextAuditTime = DateTime.MaxValue;
                Assert.AreEqual(DateTime.MaxValue, test.NextAuditTime);

                test.RelativeDetailLevel = 1;
                Assert.AreEqual(1, test.RelativeDetailLevel);

                test.SourceSystem = nameof(StatusResultsBuilder);
                Assert.AreEqual(nameof(StatusResultsBuilder), test.SourceSystem);

                Assert.AreEqual(nameof(StatusResultsBuilder), test.TargetSystem);
            }
        }
 public void ServiceProfilerNoListener()
 {
     using (ScopedLocalServiceOverride <IAmbientServiceProfiler> o = new ScopedLocalServiceOverride <IAmbientServiceProfiler>(new BasicAmbientServiceProfiler()))
         using (AmbientClock.Pause())
         {
             _ServiceProfiler.Local?.SwitchSystem(nameof(ServiceProfilerNull));
         }
 }
예제 #8
0
 public async Task TestCodeThatCouldTimeoutUnderHeavyLoad()
 {
     using (AmbientClock.Pause())
     {
         AmbientCancellationTokenSource cts = new AmbientCancellationTokenSource(TimeSpan.FromSeconds(1));
         await AsyncFunctionThatCouldTimeoutUnderHeavyLoad(cts.Token);
     }
 }
예제 #9
0
 public void StatusResultsBuilderChildren()
 {
     using (AmbientClock.Pause())
     {
         StatusResultsBuilder test  = new StatusResultsBuilder(nameof(StatusResultsBuilderChildren));
         StatusResultsBuilder child = test.AddChild("Child");
         Assert.AreEqual("Child", child.TargetSystem);
     }
 }
예제 #10
0
 public void StatusResultsBuilderProperties()
 {
     using (AmbientClock.Pause())
     {
         StatusCheckerTest    checker  = new StatusCheckerTest();
         StatusResultsBuilder test     = new StatusResultsBuilder(checker, new StatusProperty[] { new StatusProperty("Property1", "Value1"), new StatusProperty("Property2", "Value2") });
         StatusProperty       property = test.FindProperty("Property1");
         Assert.AreEqual("Value1", property?.Value);
     }
 }
예제 #11
0
        public async Task StatusAuditorHistory()
        {
            BasicAmbientSettingsSet settings = new BasicAmbientSettingsSet(nameof(StatusAuditorHistory));

            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionMinutes", "5");
            settings.ChangeSetting(nameof(StatusChecker) + "-HistoryRetentionEntries", "10");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> localOverrideTest = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settings))

                using (AmbientClock.Pause())
                {
                    using (StatusAuditorTest test = new StatusAuditorTest(nameof(StatusAuditorTest)))
                    {
                        StatusResults results = await test.GetStatus();

                        Assert.AreEqual("StatusAuditorTest", test.TargetSystem);
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // since we're rotating the status rating, the frequency will vary because of that
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one starts kicking out history items due to count (this was determined by simply trying it out, but that part doesn't matter for this test)
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30)); // this one should start kicking history items out due to time
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                        AmbientClock.SkipAhead(TimeSpan.FromSeconds(30));
                        Assert.IsTrue(test.History.Count() <= 10);
                        Assert.IsTrue(test.History.First().Time >= AmbientClock.UtcNow.AddMinutes(-5));
                    }
                }
        }
        public void AmbientServiceProfilerCoordinatorSettingsNonCurrent()
        {
            string system1 = "DynamoDB/Table:My-table/Partition:342644/Result:Success";
            string system2 = "S3/Bucket:My-bucket/Prefix:abcdefg/Result:Retry";
            string system3 = "SQL/Database:My-database/Table:User/Result:Failed";
            BasicAmbientSettingsSet settingsSet = new BasicAmbientSettingsSet(nameof(AmbientServiceProfilerCoordinatorSettingsNonCurrent));

            settingsSet.ChangeSetting(nameof(AmbientServiceProfilerCoordinator) + "-DefaultSystemGroupTransform", "(?:([^:/]+)(?:(/Database:[^:/]*)|(/Bucket:[^:/]*)|(/Result:[^:/]*)|(?:/[^/]*))*)");
            using (ScopedLocalServiceOverride <IAmbientSettingsSet> o = new ScopedLocalServiceOverride <IAmbientSettingsSet>(settingsSet))
                using (ScopedLocalServiceOverride <IAmbientServiceProfiler> p = new ScopedLocalServiceOverride <IAmbientServiceProfiler>(new BasicAmbientServiceProfiler()))
                    using (AmbientClock.Pause())
                        using (AmbientServiceProfilerCoordinator coordinator = new AmbientServiceProfilerCoordinator())
                            using (IAmbientServiceProfile scopeProfile = coordinator.CreateCallContextProfiler(nameof(ServiceProfilerBasic)))
                            {
                                _ServiceProfiler.Local?.SwitchSystem(system1);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(5));

                                _ServiceProfiler.Local?.SwitchSystem(system2);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(200));

                                _ServiceProfiler.Local?.SwitchSystem(system3);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(3000));

                                _ServiceProfiler.Local?.SwitchSystem(system1);
                                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(5));

                                _ServiceProfiler.Local?.SwitchSystem("noreport");

                                if (scopeProfile != null)
                                {
                                    foreach (AmbientServiceProfilerAccumulator stats in scopeProfile.ProfilerStatistics)
                                    {
                                        if (stats.Group.StartsWith("DynamoDB"))
                                        {
                                            Assert.AreEqual("DynamoDB/Result:Success", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(10), stats.TimeUsed);
                                            Assert.AreEqual(2, stats.ExecutionCount);
                                        }
                                        else if (stats.Group.StartsWith("S3"))
                                        {
                                            Assert.AreEqual("S3/Bucket:My-bucket/Result:Retry", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(200), stats.TimeUsed);
                                            Assert.AreEqual(1, stats.ExecutionCount);
                                        }
                                        else if (stats.Group.StartsWith("SQL"))
                                        {
                                            Assert.AreEqual("SQL/Database:My-database/Result:Failed", stats.Group);
                                            Assert.AreEqual(TimeSpan.FromMilliseconds(3000), stats.TimeUsed);
                                            Assert.AreEqual(1, stats.ExecutionCount);
                                        }
                                    }
                                }
                            }
        }
예제 #13
0
 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 ServiceProfilerNull()
 {
     using (ScopedLocalServiceOverride <IAmbientServiceProfiler> o = new ScopedLocalServiceOverride <IAmbientServiceProfiler>(null))
         using (AmbientServiceProfilerCoordinator coordinator = new AmbientServiceProfilerCoordinator())
             using (IAmbientServiceProfile processProfile = coordinator.CreateProcessProfiler(nameof(ServiceProfilerNull)))
                 using (IDisposable timeWindowProfile = coordinator.CreateTimeWindowProfiler(nameof(ServiceProfilerNull), TimeSpan.FromMilliseconds(100), p => Task.CompletedTask))
                     using (IAmbientServiceProfile scopeProfile = coordinator.CreateCallContextProfiler(nameof(ServiceProfilerNull)))
                         using (AmbientClock.Pause())
                         {
                             _ServiceProfiler.Local?.SwitchSystem(nameof(ServiceProfilerNull));
                         }
 }
예제 #15
0
 public async Task StatusAuditorStopAfterDispose()
 {
     using (AmbientClock.Pause())
     {
         StatusAuditorAuditNeverRunTest toStop;
         using (StatusAuditorAuditNeverRunTest test = new StatusAuditorAuditNeverRunTest(nameof(StatusAuditorAuditNeverRunTest)))
         {
             toStop = test;
         }
         await toStop.BeginStop();
     }
 }
예제 #16
0
 public void StatusAuditorAuditException()
 {
     using (AmbientClock.Pause())
     {
         using (StatusAuditorAuditExceptionTest test = new StatusAuditorAuditExceptionTest(nameof(StatusAuditorAuditExceptionTest)))
         {
             Assert.AreEqual("StatusAuditorAuditExceptionTest", test.TargetSystem);
             // run the initial audit manually and synchronously
             test.InitialAuditTimer_Elapsed(null, null);
         }
     }
 }
예제 #17
0
 public void StatusAuditorTriggerAfterDisposed()
 {
     using (AmbientClock.Pause())
     {
         StatusAuditorAuditNeverRunTest testCopy;
         using (StatusAuditorAuditNeverRunTest test = new StatusAuditorAuditNeverRunTest(nameof(StatusAuditorAuditNeverRunTest)))
         {
             testCopy = test;
             Assert.AreEqual("StatusAuditorAuditNeverRunTest", test.TargetSystem);
         }
         testCopy.AuditTimer_Elapsed(null, null);
     }
 }
예제 #18
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 !));
     }
 }
예제 #19
0
        public void StatusResultsOrganizer()
        {
            using (AmbientClock.Pause())
            {
                StatusResultsOrganizer organizer;
                string o;

                organizer = new StatusResultsOrganizer();
                organizer.Add(organizer, new StatusResults(null, "/Target1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/Target1", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1), new StatusAuditAlert(StatusRating.Fail, "Fail", "Terse", "Details"))), "Source2");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.5") }, null), "Source1");
                organizer.Add(organizer, new StatusResults("Source2", "/SampleDisk.SystemTemp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.Temp", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "4.0") }, null), "Source1");
                organizer.Add(organizer, new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "10.0") }, new StatusAuditReport(AmbientClock.UtcNow, TimeSpan.FromMilliseconds(10), DateTime.UtcNow.AddMinutes(1))), "Source2");
                organizer.Add(organizer, new StatusResults("Source1", "Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer, new StatusResults("Source2", "Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer, new StatusResults("Source3", "Pending", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.Leaf, new StatusResults[] { StatusResults.GetPendingResults("Leaf", "PendingTarget") }));
                organizer.Add(organizer.Children.First(), new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.Skip(1).First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.Add(organizer.Children.Skip(2).First(), new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, Array.Empty <StatusResults>()));
                organizer.ComputeOverallRatingAndSort();
                o = organizer.ToString();
                Assert.IsTrue(o.Contains("Overall:"));
                o = organizer.Children.First().ToString();
                Assert.IsTrue(o.Contains("Source1->"));
                Assert.IsTrue(o.Contains("/Target1:"));

                organizer = new StatusResultsOrganizer();
                StatusResults source1Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "1.0") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.0"), new StatusProperty("Att2", "Val2.0") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults source2Root = new StatusResults(null, null, AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] {
                    new StatusResults(null, "/SampleDisk.OperatingSystem", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("AvailablePercent", "2.3") }, StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                    new StatusResults(null, "/Target2", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHeterogenous, new StatusResults[] { new StatusResults(null, "Part1", AmbientClock.UtcNow, 0, new StatusProperty[] { new StatusProperty("Att1", "Val1.1"), new StatusProperty("Att2", "Val2.1") }, StatusNatureOfSystem.Leaf, Array.Empty <StatusResults>()) }),
                });
                StatusResults overallRoot = new StatusResults(null, "/", AmbientClock.UtcNow, 0, Array.Empty <StatusProperty>(), StatusNatureOfSystem.ChildrenHomogenous, new StatusResults[] {
                    source1Root,
                    source2Root,
                });
                organizer.Add(organizer, overallRoot);
                organizer.ComputeOverallRatingAndSort();
                StatusPropertyRange worstRange = organizer.Children.First().WorstPropertyRange;
                o = organizer.Children.First().ToString();
            }
        }
예제 #20
0
        public void StatusResultsGetSummaryAlertsNotificationTime()
        {
            using (AmbientClock.Pause())
            {
                DateTime         now       = AmbientClock.UtcNow;
                string           shortTime = now.ToShortTimeString();
                string           longTime  = now.ToLongTimeString();
                StatusResults    results;
                StatusAuditAlert alert;

                shortTime = now.ToShortTimeString();
                longTime  = now.ToLongTimeString();
                results   = new StatusResults("Source", "StatusTarget", new StatusResults[0]);
                alert     = results.GetSummaryAlerts(true, StatusRating.Okay, false);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Alert, false);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Fail, true);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));

                now       = TimeZoneInfo.ConvertTime(now, TimeZoneInfo.Local);
                shortTime = now.ToShortTimeString();
                longTime  = now.ToLongTimeString();
                alert     = results.GetSummaryAlerts(true, StatusRating.Okay, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Alert, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
                alert = results.GetSummaryAlerts(true, StatusRating.Fail, false, TimeZoneInfo.Local);
                Assert.IsTrue(alert.Details.Contains("Okay"));
                Assert.IsTrue(alert.Details.Contains(longTime));
                Assert.IsTrue(alert.Terse.Contains("OKAY"));
                Assert.IsTrue(alert.Terse.Contains(shortTime));
            }
        }
예제 #21
0
        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);
            }
        }
예제 #22
0
        public void Cancellation()
        {
            IAmbientProgress progress = AmbientProgressService.Progress;

            progress?.ResetCancellation(); // make a new cancellation in case the source was canceled in this execution context during a previous test
            using (AmbientClock.Pause())
            {
                progress?.ResetCancellation(TimeSpan.FromMilliseconds(100));
                AmbientCancellationTokenSource tokenSource = progress?.CancellationTokenSource;
                Assert.IsNotNull(tokenSource);
                Assert.IsFalse(tokenSource?.IsCancellationRequested ?? true);
                AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(100));
                Assert.IsTrue(tokenSource?.IsCancellationRequested ?? false);
                Assert.ThrowsException <OperationCanceledException>(() => AmbientProgressService.Progress?.ThrowIfCancelled());
            }
        }
예제 #23
0
        public async Task StatusChecker()
        {
            using (AmbientClock.Pause())
            {
                using (StatusCheckerTest test = new StatusCheckerTest())
                {
                    StatusResults results = await test.GetStatus();

                    Assert.AreEqual(results, test.LatestResults);
                    Assert.AreEqual(results, test.History.LastOrDefault());   // the most recent history results should be the last one (history is a FIFO queue)
                    Assert.AreEqual("StatusCheckerTest", test.TargetSystem);
                    await test.BeginStop();

                    await test.FinishStop();
                }
            }
        }
        public void ServiceProfilerCloseSampleWithRepeat()
        {
            using (ScopedLocalServiceOverride <IAmbientServiceProfiler> o = new ScopedLocalServiceOverride <IAmbientServiceProfiler>(new BasicAmbientServiceProfiler()))
                using (AmbientClock.Pause())
                    using (AmbientServiceProfilerCoordinator coordinator = new AmbientServiceProfilerCoordinator())
                        using (IDisposable timeWindowProfile = coordinator.CreateTimeWindowProfiler(nameof(ServiceProfilerCloseSampleWithRepeat), TimeSpan.FromMilliseconds(100), p => Task.CompletedTask))
                        {
                            AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(100)); // this should trigger the first window and it should have only the default "" entry

                            _ServiceProfiler.Local?.SwitchSystem(nameof(ServiceProfilerCloseSampleWithRepeat) + "1");
                            AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(10));
                            _ServiceProfiler.Local?.SwitchSystem(null);
                            AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(10));
                            _ServiceProfiler.Local?.SwitchSystem("ServiceProfilerCloseSampleWithRepeat1");
                            AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(80)); // this should trigger the second window, which should close with an augmentation of the first ServiceProfilerCloseSampleWithRepeat1 entry
                            _ServiceProfiler.Local?.SwitchSystem(null);
                        }
        }
예제 #25
0
        public async Task StatusAuditorArgumentException()
        {
            using (AmbientClock.Pause())
            {
                StatusResults auditorTestResults;
                StatusResults auditorAuditExceptionTestResults;
                using (StatusAuditorTest test = new StatusAuditorTest(nameof(StatusAuditorArgumentException)))
                {
                    auditorTestResults = await test.GetStatus();
                }
                using (StatusAuditorAuditExceptionTest test = new StatusAuditorAuditExceptionTest(nameof(StatusAuditorArgumentException) + "2"))
                {
                    auditorAuditExceptionTestResults = await test.GetStatus();

                    Assert.ThrowsException <ArgumentException>(() => test.SetLatestResults(auditorTestResults));
                }
            }
        }
예제 #26
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);
            }
        }
예제 #27
0
    public async Task TestCancellation()
    {
        // this first part *should* get cancelled because we're using the system clock
        AmbientCancellationTokenSource cts = new AmbientCancellationTokenSource(TimeSpan.FromSeconds(1));
        await Assert.ThrowsExceptionAsync <OperationCanceledException>(() => AsyncFunctionThatShouldCancelAfterOneSecond(cts.Token));

        // switch the current call context to the artifically-paused ambient clock and try again
        using (AmbientClock.Pause())
        {
            AmbientCancellationTokenSource cts2 = new AmbientCancellationTokenSource(TimeSpan.FromSeconds(1));
            // this should *not* throw because the clock has been paused
            await AsyncFunctionThatShouldCancelAfterOneSecond(cts2.Token);

            // this skips the artifical paused clock ahead, raising the cancellation
            AmbientClock.SkipAhead(TimeSpan.FromSeconds(1));
            // make sure the cancellation got raised
            Assert.ThrowsException <OperationCanceledException>(() => cts2.Token.ThrowIfCancellationRequested());
        }
    }
예제 #28
0
        public async Task CacheRefresh()
        {
            AmbientSettingsOverride localSettingsSet = new AmbientSettingsOverride(TestCacheSettingsDictionary, nameof(CacheRefresh));

            using (AmbientClock.Pause())
                using (new ScopedLocalServiceOverride <IAmbientSettingsSet>(localSettingsSet))
                {
                    TestCache     ret;
                    IAmbientCache cache = new BasicAmbientCache(localSettingsSet);
                    await cache.Store <TestCache>(true, "CacheRefresh1", this, TimeSpan.FromSeconds(1));

                    AmbientClock.SkipAhead(TimeSpan.FromMilliseconds(1100));

                    ret = await cache.Retrieve <TestCache>("CacheRefresh1", null);

                    Assert.IsNull(ret);
                    await cache.Store <TestCache>(true, "CacheRefresh1", this, TimeSpan.FromMinutes(10));

                    ret = await cache.Retrieve <TestCache>("CacheRefresh1", null);

                    Assert.AreEqual(this, ret);
                    await Eject(cache, 1);

                    await cache.Store <TestCache>(true, "CacheRefresh2", this);

                    ret = await cache.Retrieve <TestCache>("CacheRefresh2", null);

                    Assert.AreEqual(this, ret);
                    await cache.Store <TestCache>(true, "CacheRefresh3", this);

                    ret = await cache.Retrieve <TestCache>("CacheRefresh3", null);

                    Assert.AreEqual(this, ret);
                    await cache.Remove <TestCache>(true, "CacheRefresh3");

                    ret = await cache.Retrieve <TestCache>("CacheRefresh3", null);

                    Assert.IsNull(ret);

                    await Eject(cache, 1);
                }
        }
예제 #29
0
        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));
            }
        }
예제 #30
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);
            }
        }