public void Default_Values() { // arrange // act var options = new VoyagerOptions(); // act Assert.Equal("/voyager", options.Path); Assert.Equal("/", options.QueryPath); }
public void Path_Set_To_Empty_ArgumentException() { // arrange var options = new VoyagerOptions(); // act Action action = () => options.Path = default; // act Assert.Throws <ArgumentException>(action); }
public void SetGraphQLEndpoint() { // arrange var options = new VoyagerOptions(); // act options.GraphQLEndpoint = new Uri("https://localhost:8081/graphql"); // act Assert.Equal("https://localhost:8081/graphql", options.GraphQLEndpoint.AbsoluteUri); }
public void SetQueryPath() { // arrange var options = new VoyagerOptions(); // act options.QueryPath = new PathString("/foo"); // act Assert.Equal("/foo/voyager", options.Path.ToString()); Assert.Equal("/foo", options.QueryPath.ToString()); }
public void SetQueryPath() { // arrange var options = new VoyagerOptions(); // act options.QueryPath = "/foo"; // act Assert.Equal("/foo/voyager", options.Path); Assert.Equal("/foo", options.QueryPath); }
private static IApplicationBuilder UseVoyagerSettingsMiddleware( this IApplicationBuilder applicationBuilder, VoyagerOptions options) { return(applicationBuilder.Map( options.Path.Add(new PathString("/settings.js")), #if ASPNETCLASSIC app => app.Use <SettingsMiddleware>(options))); #else app => app.UseMiddleware <SettingsMiddleware>(options)); #endif }
public void GraphQLEndpoint_Set_To_Null_Or_Invalid_Exceptions() { // arrange var options = new VoyagerOptions(); // act Action invalidAction = () => options.GraphQLEndpoint = new Uri("not valid"); Action nullAction = () => options.GraphQLEndpoint = new Uri(null); // act Assert.Throws <UriFormatException>(invalidAction); Assert.Throws <ArgumentNullException>(nullAction); }
public static IApplicationBuilder UseVoyager( this IApplicationBuilder applicationBuilder, VoyagerOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } return(applicationBuilder .UseVoyagerSettingsMiddleware(options) .UseVoyagerFileServer(options.Path)); }
public async Task Default_Values() { // arrange var options = new VoyagerOptions(); TestServer server = CreateServer(options); string settingsUri = "/voyager/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task SetQueryPath() { // arrange var options = new VoyagerOptions(); options.QueryPath = new PathString("/foo"); TestServer server = CreateServer(options); string settingsUri = "/foo/voyager/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public async Task SetGraphQLEndpoint() { // arrange var options = new VoyagerOptions(); options.Path = "/foo-bar"; options.GraphQLEndpoint = new Uri("https://github.com/graphql"); TestServer server = CreateServer(options); string settingsUri = "/foo-bar/settings.js"; // act string settings_js = await GetSettingsAsync(server, settingsUri); // act settings_js.MatchSnapshot(); }
public SettingsMiddleware( RequestDelegate next, VoyagerOptions options) #if ASPNETCLASSIC : base(next) #endif { #if !ASPNETCLASSIC Next = next; #endif _options = options ?? throw new ArgumentNullException(nameof(options)); Uri uiPath = UriFromPath(options.Path); Uri queryPath = UriFromPath(options.QueryPath); _queryPath = uiPath.MakeRelativeUri(queryPath).ToString(); }
public VoyagerMiddleware(RequestDelegate next, VoyagerOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); }
/// <summary> /// Add the Voyager middleware to the HTTP request pipeline /// </summary> /// <param name="endpoints">Defines a contract for a route builder in an application. A route builder specifies the routes for an application.</param> /// <param name="options">Options to customize <see cref="VoyagerMiddleware"/>. If not set, then the default values will be used.</param> /// <param name="pattern">The route pattern.</param> /// <returns>The <see cref="IApplicationBuilder"/> received as parameter</returns> public static VoyagerEndpointConventionBuilder MapGraphQLVoyager(this IEndpointRouteBuilder endpoints, VoyagerOptions options, string pattern = "ui/voyager") { if (endpoints == null) { throw new ArgumentNullException(nameof(endpoints)); } var requestDelegate = endpoints.CreateApplicationBuilder().UseMiddleware <VoyagerMiddleware>(options ?? new VoyagerOptions()).Build(); return(new VoyagerEndpointConventionBuilder(endpoints.Map(pattern, requestDelegate).WithDisplayName("GraphQL Voyager"))); }
private TestServer CreateServer(VoyagerOptions options) { return(ServerFactory.Create( services => services.AddStarWars(), (app, sp) => app.UseGraphQL(sp).UseVoyager(options))); }
public VoyagerPageModel(VoyagerOptions options) { _options = options; }
/// <summary> Adds middleware for Voyager using the specified options. </summary> /// <param name="app"> <see cref="IApplicationBuilder"/> to configure an application's request pipeline. </param> /// <param name="options"> Options to customize <see cref="VoyagerMiddleware"/>. If not set, then the default values will be used. </param> /// <param name="path">The path to the Voyager endpoint which defaults to '/ui/voyager'</param> /// <returns> The reference to provided <paramref name="app"/> instance. </returns> public static IApplicationBuilder UseGraphQLVoyager(this IApplicationBuilder app, VoyagerOptions options, string path = "/ui/voyager") { return(app.UseWhen( context => HttpMethods.IsGet(context.Request.Method) && !context.WebSockets.IsWebSocketRequest && context.Request.Path.StartsWithSegments(path, out var remaining) && string.IsNullOrEmpty(remaining), b => b.UseMiddleware <VoyagerMiddleware>(options ?? new VoyagerOptions()))); }