public void AutoHealthCheckContext_should_ignore_repeated_probes()
        {
            // arrange
            var context = new AutoHealthCheckContext();

            // act
            context.AddProbe <FakeProbe>();
            context.AddProbe <FakeProbe>();

            // assert
            Assert.Single(context.Probes);
        }
        public async Task ProbesProcessor_should_not_fail_with_unhandled_probe()
        {
            // arrange
            var contextAccessor = new Mock <IAutoHealthCheckContextAccessor>();
            var serviceProvider = new Mock <IServiceProvider>();

            // service provider will not resolve the type
            serviceProvider.Setup(c => c.GetService(It.Is <Type>(x => x == typeof(UnImplementedProbe))))
            .Returns(new UnImplementedProbe());

            var context = new AutoHealthCheckContext();

            context.AddProbe <UnImplementedProbe>(); // first well delay

            contextAccessor.Setup(c => c.Context)
            .Returns(context);

            var processor = new ProbesProcessor(serviceProvider.Object, contextAccessor.Object);

            // act
            var result = await processor.ExecuteCustomProbes();

            // assert
            Assert.NotNull(result);
            Assert.Single(result);

            Assert.False(result.First().Succeed);
            Assert.Equal("foo", result.First().ErrorMessage);
        }
        public async Task ProbesProcessor_should_execute_single_well_probe()
        {
            // arrange
            var contextAccessor = new Mock <IAutoHealthCheckContextAccessor>();
            var serviceProvider = new Mock <IServiceProvider>();

            // service provider will not resolve the type
            serviceProvider.Setup(c => c.GetService(It.IsAny <Type>()))
            .Returns(new WellProbe());

            var context = new AutoHealthCheckContext();

            context.AddProbe <WellProbe>();
            contextAccessor.Setup(c => c.Context)
            .Returns(context);

            var processor = new ProbesProcessor(serviceProvider.Object, contextAccessor.Object);

            // act
            var result = await processor.ExecuteCustomProbes();

            // assert
            Assert.NotNull(result);
            Assert.Single(result);
            Assert.True(result.First().Succeed);
            Assert.Equal("WellProbe", result.First().Name);
        }
        public async Task ProbesProcessor_should_ignore_if_probes_can_not_be_resolved()
        {
            // arrange
            var contextAccessor = new Mock <IAutoHealthCheckContextAccessor>();
            var serviceProvider = new Mock <IServiceProvider>();

            // service provider will not resolve the type
            serviceProvider.Setup(c => c.GetService(It.IsAny <Type>()))
            .Returns(null);

            var context = new AutoHealthCheckContext();

            context.AddProbe <UnImplementedProbe>();
            contextAccessor.Setup(c => c.Context)
            .Returns(context);

            var processor = new ProbesProcessor(serviceProvider.Object, contextAccessor.Object);

            // act
            var result = await processor.ExecuteCustomProbes();

            // assert
            Assert.NotNull(result);
            Assert.Empty(result);
        }
        public void AutoHealthCheckContext_add_probe_should_fail_with_abstract_types()
        {
            // arrange
            var context = new AutoHealthCheckContext();

            // act
            // assert
            Assert.Throws <InvalidOperationException>(() => context.AddProbe <AbstractProbe>());
        }
        public void AutoHealthCheckContext_should_add_single_probe()
        {
            // arrange
            var context = new AutoHealthCheckContext();

            // act
            context.AddProbe <FakeProbe>();

            // assert
            Assert.Single(context.Probes);
        }
예제 #7
0
        public async Task ProbesProcessor_should_execute_probes_simultaneously()
        {
            // arrange
            var contextAccessor = new Mock <IAutoHealthCheckContextAccessor>();
            var serviceProvider = new Mock <IServiceProvider>();

            // service provider will not resolve the type
            serviceProvider.Setup(c => c.GetService(It.Is <Type>(x => x == typeof(BadProbe))))
            .Returns(new BadProbe());

            serviceProvider.Setup(c => c.GetService(It.Is <Type>(x => x == typeof(WellDelayProbe))))
            .Returns(new WellDelayProbe());

            var context = new AutoHealthCheckContext(new AutoHealthCheckConfigurations
            {
                RunCustomProbesAsync = true // run async
            });

            context.AddProbe <WellDelayProbe>(); // first well delay
            context.AddProbe <BadProbe>();

            contextAccessor.Setup(c => c.Context)
            .Returns(context);

            var processor = new ProbesProcessor(serviceProvider.Object, contextAccessor.Object);

            // act
            var result = await processor.ExecuteCustomProbes();

            // assert
            Assert.NotNull(result);
            Assert.Equal(2, result.Count());

            // bad probe
            Assert.False(result.First(s => s.Name == "BadProbe").Succeed);
            Assert.Equal("custom error 0", result.First(s => s.Name == "BadProbe").ErrorMessage);

            // well probe
            Assert.True(result.First(s => s.Name == "WellDelayProbe").Succeed);
            Assert.Null(result.First(s => s.Name == "WellDelayProbe").ErrorMessage);
        }