public void GetPathByAddressReturnsCorrectODataPathWithPathBase(string pathBase) { // Arrange int address = 1; IPerRouteContainer container = new PerRouteContainer(); container.AddRoute("odata", "ms/{data}"); IServiceProvider serviceProvider = new ServiceCollection() .AddSingleton <IPerRouteContainer>(container) .BuildServiceProvider(); HttpContext httpContext = new DefaultHttpContext { RequestServices = serviceProvider }; httpContext.Request.PathBase = pathBase; httpContext.ODataFeature().RouteName = "odata"; RouteValueDictionary values = new RouteValueDictionary(); values["odataPath"] = ""; RouteValueDictionary ambientValues = new RouteValueDictionary(); ambientValues["data"] = 2; // Act Mock <LinkGenerator> mock = new Mock <LinkGenerator>(); ODataEndpointLinkGenerator linkGenerator = new ODataEndpointLinkGenerator(mock.Object); string path = linkGenerator.GetPathByAddress(httpContext, address, values, ambientValues); // Assert Assert.Equal(pathBase + "/ms/2", path); }
public void GetPathByAddressCallInnerLinkGeneratorGetPathByAddress() { // Arrange int address = 1; RouteValueDictionary values = new RouteValueDictionary(); PathString pathBase = new PathString(); FragmentString fragment = new FragmentString(); LinkOptions options = null; Mock <LinkGenerator> mock = new Mock <LinkGenerator>(); mock.Setup(g => g.GetPathByAddress(address, values, pathBase, fragment, options)).Verifiable(); // Act ODataEndpointLinkGenerator linkGenerator = new ODataEndpointLinkGenerator(mock.Object); linkGenerator.GetPathByAddress(address, values, pathBase, fragment, options); // Assert mock.Verify(); }