public void SelectAction_ReturnsTheActionName_DollarCount() { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); ODataPath odataPath = new DefaultODataPathHandler().Parse( model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp/$count"); ILookup <string, HttpActionDescriptor> actionMap = new HttpActionDescriptor[1].ToLookup(desc => "GetEnumCollectionPropFromDollarCountEntity"); HttpRequestContext requestContext = new HttpRequestContext(); HttpControllerContext controllerContext = new HttpControllerContext { Request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/"), RequestContext = requestContext, RouteData = new HttpRouteData(new HttpRoute()) }; controllerContext.Request.SetRequestContext(requestContext); // Act string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, actionMap); // Assert Assert.NotNull(selectedAction); Assert.Equal("GetEnumCollectionPropFromDollarCountEntity", selectedAction); Assert.Equal(1, controllerContext.Request.GetRouteData().Values.Count); Assert.Equal("7", controllerContext.Request.GetRouteData().Values["key"]); }
public void SelectAction_ReturnsNull_IfPatchToCollectionProperty() { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp"); var request = RequestFactory.Create(HttpMethod.Get, "http://localhost/"); var actionMap = SelectActionHelper.CreateActionMap("PatchToEnumCollectionProp"); // Act string selectedAction = SelectActionHelper.SelectAction(new PropertyRoutingConvention(), odataPath, request, actionMap); // Assert Assert.Null(selectedAction); Assert.Empty(SelectActionHelper.GetRouteData(request).Values); }
public void SelectAction_OnEnumCollection_ReturnsTheActionName(string httpMethod, string prefix) { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp"); var request = RequestFactory.Create(new HttpMethod(httpMethod), "http://localhost/"); var actionMap = SelectActionHelper.CreateActionMap(prefix + "EnumCollectionProp"); // Act string selectedAction = SelectActionHelper.SelectAction(new PropertyRoutingConvention(), odataPath, request, actionMap); // Assert Assert.NotNull(selectedAction); Assert.Equal(prefix + "EnumCollectionProp", selectedAction); Assert.Single(SelectActionHelper.GetRouteData(request).Values); Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]); }
public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForDollarCountRequests(string uri, Type elementType) { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); Type type = typeof(ICollection <>).MakeGenericType(elementType); var pathHandler = new DefaultODataPathHandler(); var path = pathHandler.Parse(model, "http://localhost/", uri); var request = RequestFactory.CreateFromModel(model); request.ODataContext().Path = path; // Act var serializer = _serializerProvider.GetODataPayloadSerializer(type, request); // Assert Assert.NotNull(serializer); var rawValueSerializer = Assert.IsType <ODataRawValueSerializer>(serializer); Assert.Equal(ODataPayloadKind.Value, rawValueSerializer.ODataPayloadKind); }
public void SelectAction_ReturnsTheActionName_DollarCount() { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); ODataPath odataPath = new DefaultODataPathHandler().Parse( model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp/$count"); var request = RequestFactory.Create(HttpMethod.Get, "http://localhost/"); var actionMap = SelectActionHelper.CreateActionMap("GetEnumCollectionPropFromDollarCountEntity"); // Act string selectedAction = SelectActionHelper.SelectAction(new PropertyRoutingConvention(), odataPath, request, actionMap); // Assert Assert.NotNull(selectedAction); Assert.Equal("GetEnumCollectionPropFromDollarCountEntity", selectedAction); Assert.Equal(2, SelectActionHelper.GetRouteData(request).Values.Count); Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["key"]); Assert.Equal(7, SelectActionHelper.GetRouteData(request).Values["keyID"]); }
public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForDollarCountRequests(string uri, Type elementType) { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); Type type = typeof(ICollection <>).MakeGenericType(elementType); ODataUriParser parser = new ODataUriParser(model, new Uri(uri, UriKind.Relative)); var path = parser.ParsePath(); var request = RequestFactory.Create(model); request.ODataFeature().Path = path; // Act var serializer = _serializerProvider.GetODataPayloadSerializer(type, request); // Assert Assert.NotNull(serializer); var rawValueSerializer = Assert.IsType <ODataRawValueSerializer>(serializer); Assert.Equal(ODataPayloadKind.Value, rawValueSerializer.ODataPayloadKind); }
public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForDollarCountRequests(string uri, Type elementType) { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); Type type = typeof(ICollection <>).MakeGenericType(elementType); var request = new HttpRequestMessage(); var pathHandler = new DefaultODataPathHandler(); var path = pathHandler.Parse(model, "http://localhost/", uri); request.ODataProperties().Path = path; request.EnableHttpDependencyInjectionSupport(model); // Act var serializer = _serializerProvider.GetODataPayloadSerializer(type, request); // Assert Assert.NotNull(serializer); var rawValueSerializer = Assert.IsType <ODataRawValueSerializer>(serializer); Assert.Equal(ODataPayloadKind.Value, rawValueSerializer.ODataPayloadKind); }
public void SelectAction_ReturnsNull_IfPatchToCollectionProperty() { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); ODataPath odataPath = new DefaultODataPathHandler().Parse(model, _serviceRoot, "DollarCountEntities(7)/EnumCollectionProp"); ILookup <string, HttpActionDescriptor> emptyActionMap = new HttpActionDescriptor[0].ToLookup(desc => "PatchToEnumCollectionProp"); HttpRequestContext requestContext = new HttpRequestContext(); HttpControllerContext controllerContext = new HttpControllerContext { Request = new HttpRequestMessage(new HttpMethod("Patch"), "http://localhost/"), RequestContext = requestContext, RouteData = new HttpRouteData(new HttpRoute()) }; controllerContext.Request.SetRequestContext(requestContext); // Act string selectedAction = new PropertyRoutingConvention().SelectAction(odataPath, controllerContext, emptyActionMap); // Assert Assert.Null(selectedAction); Assert.Empty(controllerContext.Request.GetRouteData().Values); }
public void GetODataPayloadSerializer_ReturnsRawValueSerializer_ForDollarCountRequests(string uri, Type elementType) { // Arrange IEdmModel model = ODataCountTest.GetEdmModel(); Type type = typeof(ICollection <>).MakeGenericType(elementType); DefaultODataSerializerProvider serialierProvider = new DefaultODataSerializerProvider(); HttpContext context = CreateHttpContext(serialierProvider); var pathHandler = new DefaultODataPathHandler(context.RequestServices); var path = pathHandler.Parse(model, "http://localhost/", uri); context.ODataFeature().Path = path; context.ODataFeature().Model = model; // Act var serializer = serialierProvider.GetODataPayloadSerializer(context, type); // Assert Assert.NotNull(serializer); var rawValueSerializer = Assert.IsType <ODataRawValueSerializer>(serializer); Assert.Equal(ODataPayloadKind.Value, rawValueSerializer.ODataPayloadKind); }