public void TryMatchMediaTypeWithBinaryRawValueMatchesRequest()
        {
            IEdmModel model = GetBinaryModel();
            PropertyAccessPathSegment propertySegment = new PropertyAccessPathSegment((model.GetEdmType(typeof(RawValueEntity)) as IEdmEntityType).FindProperty("BinaryProperty"));
            ODataPath path = new ODataPath(new EntitySetPathSegment("RawValue"), new KeyValuePathSegment("1"), propertySegment, new ValuePathSegment());
            ODataBinaryValueMediaTypeMapping mapping = new ODataBinaryValueMediaTypeMapping();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/RawValue(1)/BinaryProperty/$value");
            request.ODataProperties().Model = model;
            request.ODataProperties().Path = path;

            double mapResult = mapping.TryMatchMediaType(request);

            Assert.Equal(1.0, mapResult);
        }
        public void TryMatchMediaTypeWithNonRawvalueRequestDoesntMatchRequest()
        {
            IEdmModel model = ODataTestUtil.GetEdmModel();
            PropertyAccessPathSegment propertySegment = new PropertyAccessPathSegment((model.GetEdmType(typeof(FormatterPerson)) as IEdmEntityType).FindProperty("Age"));
            ODataPath path = new ODataPath(new EntitySetPathSegment("People"), new KeyValuePathSegment("1"), propertySegment);
            ODataPrimitiveValueMediaTypeMapping mapping = new ODataPrimitiveValueMediaTypeMapping();
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/People(1)/Age/");
            request.ODataProperties().Model = model;
            request.ODataProperties().Path = path;

            double mapResult = mapping.TryMatchMediaType(request);

            Assert.Equal(0, mapResult);
        }
Exemple #3
0
        public void CanParsePropertySegment()
        {
            // Arrange
            string       odataPath          = "RoutingCustomers(112)/Name";
            string       expectedText       = "Name";
            IEdmProperty expectedEdmElement = _model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(e => e.Name == "RoutingCustomer").Properties().SingleOrDefault(p => p.Name == "Name");
            IEdmType     expectedType       = expectedEdmElement.Type.Definition;

            // Act
            ODataPath        path    = _parser.Parse(_model, odataPath);
            ODataPathSegment segment = path.Segments.Last();

            // Assert
            Assert.NotNull(segment);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Null(path.EntitySet);
            PropertyAccessPathSegment propertyAccess = Assert.IsType <PropertyAccessPathSegment>(segment);

            Assert.Same(expectedEdmElement, propertyAccess.Property);
        }
        public void CanParsePropertySegment()
        {
            // Arrange
            string       testUrl            = "http://myservice/Customers(112)/Name";
            string       expectedText       = "Name";
            IEdmProperty expectedEdmElement = _parser.Model.SchemaElements.OfType <IEdmEntityType>().SingleOrDefault(e => e.Name == "Customer").Properties().SingleOrDefault(p => p.Name == "Name");
            IEdmType     expectedType       = expectedEdmElement.Type.Definition;
            Uri          uri     = new Uri(testUrl);
            Uri          baseUri = new Uri("http://myservice/");

            // Act
            ODataPath        path    = _parser.Parse(uri, baseUri);
            ODataPathSegment segment = path.Segments.Last.Value;

            // Assert
            Assert.NotNull(segment);
            Assert.NotNull(segment.Previous);
            Assert.Equal(expectedText, segment.ToString());
            Assert.Null(segment.EntitySet);
            PropertyAccessPathSegment propertyAccess = Assert.IsType <PropertyAccessPathSegment>(segment);

            Assert.Same(expectedEdmElement, propertyAccess.Property);
        }
 /// <inheritdoc/>
 protected override bool IsMatch(PropertyAccessPathSegment propertySegment)
 {
     return propertySegment != null && propertySegment.Property.Type.IsBinary();
 }
 /// <summary>
 /// This method determines if the <see cref="System.Net.Http.HttpRequestMessage"/> is an OData Raw value request.
 /// </summary>
 /// <param name="propertySegment">The <see cref="System.Web.Http.OData.Routing.PropertyAccessPathSegment"/> of the path.</param>
 /// <returns>True if the request is an OData raw value request.</returns>
 protected abstract bool IsMatch(PropertyAccessPathSegment propertySegment);