Esempio n. 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IUrlRepository urlRepository)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints => {
                endpoints.MapHealthChecks("/hc", new HealthCheckOptions {
                    Predicate      = check => !check.Tags.Contains("ready"),
                    ResponseWriter = this.ResponseWriter
                });
                endpoints.MapHealthChecks("/rd", new HealthCheckOptions {
                    Predicate      = check => check.Tags.Contains("ready"),
                    ResponseWriter = this.ResponseWriter
                });
                endpoints.MapGet("/{token}", async context => {
                    var token = context.Request.RouteValues["token"];
                    var Id    = Base62Convertor.Decode(token.ToString());
                    var url   = await urlRepository.GetUrl(Id);
                    context.Response.Redirect(new Uri(url).AbsoluteUri, true);
                    return;
                });
                endpoints.MapDefaultControllerRoute();
            });
        }
        public void GenerateUniqueKeyTests()
        {
            var token = Base62Convertor.Convert(1000000);

            Assert.Equal(1000000, Base62Convertor.Decode(token));
        }