public void Build_MergedSequences_Ok()
        {
            var scheduler   = new TestScheduler();
            var firstEntry  = new HealthCheckEntry("FIRST", HealthStatus.Healthy, "FIRST OK", TimeSpan.FromTicks(1));
            var secondEntry = new HealthCheckEntry("SECOND", HealthStatus.Healthy, "SECOND OK", TimeSpan.FromTicks(1));
            var first       = Substitute.For <IHealthPolicy>();

            first.CheckAsync(Arg.Any <CancellationToken>()).Returns(new HealthCheck(firstEntry.Status, firstEntry.Message));
            var second = Substitute.For <IHealthPolicy>();

            second.CheckAsync(Arg.Any <CancellationToken>()).Returns(new HealthCheck(secondEntry.Status, secondEntry.Message));
            var collection = new HealthPolicyCollection();

            collection.Add(firstEntry.Policy, first);
            collection.Add(secondEntry.Policy, second);

            var observer = scheduler.Start(() => collection.Build(scheduler, Substitute.For <ICollection <IDisposable> >()));

            long scheduledTicks = Subscribed + 1;

            observer.Messages.AssertEqual(
                OnNext <HealthCheckEntry>(
                    scheduledTicks += firstEntry.Duration.Ticks,
                    x => x.Duration == firstEntry.Duration &&
                    x.Policy == firstEntry.Policy &&
                    x.Status == firstEntry.Status &&
                    x.Message == firstEntry.Message),
                OnNext <HealthCheckEntry>(
                    scheduledTicks += secondEntry.Duration.Ticks,
                    x => x.Duration == secondEntry.Duration &&
                    x.Policy == secondEntry.Policy &&
                    x.Status == secondEntry.Status &&
                    x.Message == secondEntry.Message),
                OnCompleted <HealthCheckEntry>(scheduledTicks));
        }
示例#2
0
        public static HealthCheckSection CheckDatabasesEx()
        {
            var chkMsg = CheckDatabases();

            var entry1 = new HealthCheckEntry
            {
                ItemName          = "Database connectivity",
                Result            = chkMsg != "OK",
                ResultDescription = chkMsg,
                OddRow            = false
            };

            var section = new HealthCheckSection
            {
                Title   = "Database",
                Entries = new List <HealthCheckEntry>()
            };

            section.Entries.Add(entry1);

            if (!entry1.Result)
            {
                // Can't get to db to make more checks
                return(section);
            }

            var entry2 = CheckDbStoredProc("DB1", "GetSubjectBedTime", "@uid", true);
            var entry3 = CheckDbStoredProc("DB2", "uspWorkoutCategory", "@workoutCategoryId", false);
            var entry4 = CheckDbSrchInstalled("DB2", true);
            var entry5 = CheckDbDateTime("DB1", false);
            var entry6 = new HealthCheckEntry()
            {
                ItemName          = "Windows Server DateTime.Now",
                Result            = true,
                ResultDescription = DateTime.Now.ToString(),
                OddRow            = true
            };

            section.Entries.Add(entry2);
            section.Entries.Add(entry3);
            section.Entries.Add(entry4);
            section.Entries.Add(entry5);
            section.Entries.Add(entry6);

            return(section);
        }
        public void Build_PolicyException_Equivalent()
        {
            var expected     = new HealthCheckEntry("TEST", HealthStatus.Unhealthy, "SHOULD MATCH", TimeSpan.FromTicks(1));
            var scheduler    = new TestScheduler();
            var healthPolicy = Substitute.For <IHealthPolicy>();

            healthPolicy.CheckAsync(Arg.Any <CancellationToken>()).Throws(new NullReferenceException(expected.Message));

            var sut      = new HealthPolicyConfiguration(expected.Policy, healthPolicy);
            var observer = scheduler.Start(() => sut.Build(scheduler, Substitute.For <ICollection <IDisposable> >()));

            observer.Messages.AssertEqual(
                OnNext <HealthCheckEntry>(
                    Subscribed + 1,
                    x => x.Policy == expected.Policy &&
                    x.Status == expected.Status &&
                    x.Message == expected.Message &&
                    x.Duration == expected.Duration),
                OnCompleted <HealthCheckEntry>(Subscribed + 1));
        }