/// <exception cref="InvalidOperationException">Cannot add a Uri mapping once the configuration has been done.</exception> /// <exception cref="ArgumentException">Cannot use a Type as the resourceKey. NotifyAsync an <see cref="IType"/> instead or assign the <see cref="TypeSystem"/> property.</exception> public void Add(UriRegistration registration) { if (_templates.IsReadOnly) { throw new InvalidOperationException("Cannot add a Uri mapping once the configuration has been done."); } var resourceKey = EnsureIsNotType(registration.ResourceKey); var descriptor = new UrlDescriptor { Uri = new UriTemplate(registration.UriTemplate), Culture = registration.UriCulture, ResourceKey = resourceKey, UriName = registration.UriName, Registration = registration }; _templates.KeyValuePairs.Add(new KeyValuePair <UriTemplate, object>(descriptor.Uri, descriptor)); _templates.BaseAddress = new Uri("http://localhost/").IgnoreAuthority(); var keys = UriNamesForKey(resourceKey); if (registration.UriName != null) { keys.Add(registration.UriName); } }
public void ConfigureMustConfigureSwaggerUIMiddlewareWhenCalled() { IConfiguration configuration = new ConfigurationFactory().Create(); IServiceCollection services = new ServiceCollection(); IWebHostEnvironment environment = new FakeHostingEnvironment(); StubStartup startup = new StubStartup(configuration, environment); startup.ConfigureServices(services); DiagnosticListener listener = new DiagnosticListener("Test"); services.AddSingleton(listener); services.AddSingleton <DiagnosticSource>(listener); services.AddSingleton(environment); IApplicationBuilder app = new ApplicationBuilder(services.BuildServiceProvider()); startup.Configure(app, environment); List <Func <RequestDelegate, RequestDelegate> > delegates = ReflectionHelper.GetFieldOrDefault(app, "_components") as List <Func <RequestDelegate, RequestDelegate> >; Assert.NotNull(delegates); Func <RequestDelegate, RequestDelegate> requestDelegate = delegates.FirstOrDefault(x => ReflectionHelper.GetFieldOrDefault(x.Target, "middleware") as Type == typeof(SwaggerUIMiddleware)); Assert.NotNull(requestDelegate); object[] args = ReflectionHelper.GetFieldOrDefault(requestDelegate.Target, "args") as object[]; Assert.NotNull(args); SwaggerUIOptions options = args.FirstOrDefault(x => x is SwaggerUIOptions) as SwaggerUIOptions; Assert.NotNull(options); UrlDescriptor descriptor = options.ConfigObject.Urls.FirstOrDefault(y => y.Url == "/swagger/v1/swagger.json"); Assert.NotNull(descriptor); Assert.Equal("testhost API V1", descriptor.Name); }
public UrlDescriptor ParseUrl() { var res = new UrlDescriptor(); res.Parameters = new Dictionary <string, object>(); var hash = Window.Location.Hash; hash = hash.Replace("#", ""); if (string.IsNullOrEmpty(hash)) { return(res); } var equalIndex = hash.IndexOf('?'); if (equalIndex == -1) { res.PageId = hash; return(res); } res.PageId = hash.Substring(0, equalIndex); var doublePointsIndx = equalIndex + 1; var parameters = hash.Substring(doublePointsIndx, hash.Length - doublePointsIndx); if (string.IsNullOrEmpty(parameters)) { return(res); // no parameters } var splittedByDoubleAnd = parameters.Split("&").ToList(); splittedByDoubleAnd.ForEach(f => { var splitted = f.Split("="); res.Parameters.Add(splitted[0], Global.DecodeURIComponent(splitted[1])); }); return(res); }
public void Add(UriRegistration registration) { if (this.templates.IsReadOnly) { throw new InvalidOperationException("Cannot add a Uri mapping once the configuration has been done."); } var resourceKey = this.EnsureIsNotType(registration.ResourceKey); var descriptor = new UrlDescriptor { Uri = new UriTemplate(registration.UriTemplate), Culture = registration.UriCulture, ResourceKey = resourceKey, UriName = registration.UriName, Registration = registration }; this.templates.KeyValuePairs.Add(new KeyValuePair<UriTemplate, object>(descriptor.Uri, descriptor)); this.templates.BaseAddress = new Uri("http://localhost/").IgnoreAuthority(); }
public UrlDescriptor ParseUrl() { var res = new UrlDescriptor(); var hash = Window.Location.Hash; hash = hash.Replace("#", ""); if (string.IsNullOrEmpty(hash)) { return(res); } var equalIndex = hash.IndexOf('='); if (equalIndex == -1) { res.PageId = hash; return(res); } res.PageId = hash.Substring(0, equalIndex); var doublePointsIndx = equalIndex + 1; var parameters = hash.Substring(doublePointsIndx, hash.Length - doublePointsIndx); if (string.IsNullOrEmpty(parameters)) { return(res); // no parameters } var decoded = Global.Atob(parameters); var deserialized = JSON.Parse <Dictionary <string, object> >(decoded); res.Parameters = deserialized; return(res); }
public static string MapToAction(this IUrlHelper helper, UrlDescriptor url) { return(url != null?helper.Action(url.Action, url.Controller, url.Params) : null); }