public void ToPagedResultConfiguredReturnsAbsolutePath() { var accessor = GetActionContextAccessorWithLinkProvider(); PageOptionsExtensions.Configure(accessor.Object); var pageOptions = new PageOptions(); var result = pageOptions.ToPagedResult(new List <Object>(), 0, "test", new object[] { }); Assert.Equal("xhs://myhost.be:999/test", result.Links.First.Href); }
public void ToPagedResultFirstPageHasNoPreviousLink() { var accessor = GetActionContextAccessorWithLinkProvider(); PageOptionsExtensions.Configure(accessor.Object); var pageOptions = new PageOptions() { Page = 1, PageSize = 10 }; var result = pageOptions.ToPagedResult(new List <Object>(), 30, "test", new object[] { }); Assert.Null(result.Links.Previous); }
public void ToPagedResultSecondToLastPageHasFirstAndNextAndPreviousAndLastLink() { var accessor = GetActionContextAccessorWithLinkProvider(); PageOptionsExtensions.Configure(accessor.Object); var pageOptions = new PageOptions() { Page = 3, PageSize = 10 }; var result = pageOptions.ToPagedResult(new List <Object>(), 40, "test", new object[] { }); Assert.NotNull(result.Links.First); Assert.NotNull(result.Links.Previous); Assert.NotNull(result.Links.Next); Assert.NotNull(result.Links.Last); }
public static void UseApiExtensions(this IApplicationBuilder app) { var settings = app.ApplicationServices.GetService <IOptions <ApiExtensionOptions> >(); //var linkProvider = app.ApplicationServices.GetService<ILinkProvider>(); var httpContextAccessor = app.ApplicationServices.GetService <IActionContextAccessor>(); if (settings?.Value?.DisableGlobalErrorHandling == false) { app.UseMiddleware <ExceptionResponseMiddleware>(); } PageOptionsExtensions.Configure(httpContextAccessor); app.UseForwardedHeaders(new ForwardedHeadersOptions() { RequireHeaderSymmetry = true, ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedHost | Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto }); //if (httpContextAccessor != null) LinkProvider.Configure(httpContextAccessor,settings?.Value?.BaseUrl); }