Ejemplo n.º 1
0
        public HealthServiceFacts()
        {
            _storage = new Mock <ICoreFileStorageService>();
            _config  = new HealthConfiguration
            {
                ContainerName  = "status",
                StatusBlobName = "status.json",
                ComponentPath  = "NuGet/Package Publishing"
            };

            _target = new HealthService(_storage.Object, _config, Mock.Of <ILogger <HealthService> >());
        }
Ejemplo n.º 2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseConsul("Service 1", "api");

            var healthConfiguration = new HealthConfiguration();

            var rnd = new Random();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapHealthChecks(healthConfiguration.HealthEndpoint);
                endpoints.MapGet("/", async context =>
                {
                    Console.WriteLine($"Request {DateTime.Now}");

                    if (rnd.Next(1, 10) < 5)
                    {
                        context.Response.StatusCode = 500;
                    }
                    else
                    {
                        await context.Response.WriteAsJsonAsync(new[]
                        {
                            new
                            {
                                Id   = 1,
                                Name = "John"
                            },
                            new
                            {
                                Id   = 2,
                                Name = "Alice"
                            }
                        });
                    }
                });
            });
        }