HCV–adding test application–part 5

Now it is time to see a test application. For this I create a new .NET Core 3.1 ASP.NET application, add Xabaril ( to see the end result ) and add reference to my project. The Startup is:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using HCVersion;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

namespace NetCore31HC
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            string name = Assembly.GetExecutingAssembly().GetName().Name;
            services.AddControllers();
            services.AddHealthChecks()
                .AddCheck<HealthCheckVersion>(name);
            services
                .AddHealthChecksUI(setup =>
                 {
                     setup.AddHealthCheckEndpoint("All", $"/hc");
                 })
                .AddInMemoryStorage()
                ;
        }

        // 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.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
                endpoints.MapHealthChecks("/hc",new HealthCheckOptions()
                {
                    Predicate= _=> true,
                    ResponseWriter = UIResponseWriter.WriteHealthCheckUIResponse
                });
                endpoints.MapHealthChecksUI();
            });
        }
    }
}

 

 

And so I figure out the fact that I should not hardcode the name of the HealthCheck , but to put dinamically.  So I change also the readme file to acknowledge that.

Code at https://github.com/ignatandrei/HealthCheckVersion/releases/tag/testApp

HealthCheckVersion

Health Check for Version
 NameLink
1Idea and Githubhttp://msprogrammer.serviciipeweb.ro/2020/07/20/healthcheckversion-idea-part-1/
2Documentationhttp://msprogrammer.serviciipeweb.ro/2020/07/21/healthcheckversiondocumentation-part-2/
3Testshttp://msprogrammer.serviciipeweb.ro/2020/07/22/hcv-adding-testspart-3/
4Codehttp://msprogrammer.serviciipeweb.ro/2020/07/23/hcv-adding-codepart-4/
5Test Applicationhttp://msprogrammer.serviciipeweb.ro/2020/07/27/hcvadding-test-applicationpart-5/
6CIhttp://msprogrammer.serviciipeweb.ro/2020/07/28/hcvautomatic-cipart-6/
7NuGethttp://msprogrammer.serviciipeweb.ro/2020/07/29/hcvpreparing-for-nugetpart-7/
8PostMortemhttp://msprogrammer.serviciipeweb.ro/2020/07/30/hcv-postmortempart-8/