public void HateoasRouteUriProvider_Should_GenerateEndpoint_BasedOnRouteNameAndRouteData_OLD() { // Arrange Guid itemId = Guid.NewGuid(); Expression <Func <BookViewModel, object> > expression = x => x.Id; var selfPolicy = new InMemoryPolicyRepository.RoutePolicy( typeof(BookViewModel), expression, "GetById"); var actionDescriptor = new ActionDescriptor { AttributeRouteInfo = new AttributeRouteInfo { Name = "GetById" }, EndpointMetadata = new List <object> { new HttpMethodMetadata(new [] { "Get" }) } }; actionDescriptor.RouteValues = new Dictionary <string, string> { { "action", "Get" }, { "controller", "Books" } }; var helpers = TestHelper.GetHttpContextHelpers("/api/book", actionDescriptor.RouteValues.ToDictionary(x => x.Key, x => (object)x.Value)); helpers.ContextAccessor.HttpContext.Request.RouteValues = new RouteValueDictionary(actionDescriptor.RouteValues); var actionDescriptorCollection = new ReadOnlyCollection <ActionDescriptor>(new[] { actionDescriptor }); var actionDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>(); actionDescriptorProvider .SetupGet(x => x.ActionDescriptors) .Returns(new ActionDescriptorCollection(actionDescriptorCollection, 1)); var uriProvider = new HateoasRouteUriProvider(helpers.ContextAccessor, helpers.LinkGenerator, actionDescriptorProvider.Object); // Act var results = uriProvider.GenerateEndpoint(selfPolicy, itemId); // Assert results.Should().NotBeNull(); results.Method.Should().Be(HttpMethods.Get); results.Uri.Should().EndWith($"/api/book/{itemId}"); }
public void HateoasSelfUriProvider_Should_ReturnDefaultValue_IfControllerIsNotPresent() { // Arrange Guid itemId = Guid.NewGuid(); Expression <Func <BookViewModel, object> > expression = x => x.Id; var selfPolicy = new InMemoryPolicyRepository.RoutePolicy(typeof(BookViewModel), expression, "GetById"); var helpers = TestHelper.GetHttpContextHelpers( "/api/book", new Dictionary <string, object> { { "action", "get" } }); var uriProvider = new HateoasRouteUriProvider(helpers.ContextAccessor, helpers.LinkGenerator, helpers.ActionDescriptor); // Act var results = uriProvider.GenerateEndpoint(selfPolicy, itemId); // Assert results.Should().Be(default);