public void TryMatchMediaTypeWithBinaryRawValueMatchesRequest() { IEdmModel model = GetBinaryModel(); IEdmEntitySet rawValues = model.EntityContainer.FindEntitySet("RawValue"); IEdmEntityType rawValueEntity = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "RawValueEntity"); IEdmStructuralProperty property = rawValueEntity.FindProperty("BinaryProperty") as IEdmStructuralProperty; Assert.NotNull(property); // Guard PropertySegment propertySegment = new PropertySegment(property); var keys = new[] { new KeyValuePair <string, object>("Id", 1) }; KeySegment keySegment = new KeySegment(keys, rawValueEntity, rawValues); ODataPath path = new ODataPath(new EntitySetSegment(rawValues), keySegment, propertySegment, new ValueSegment(propertySegment.EdmType)); ODataBinaryValueMediaTypeMapping mapping = new ODataBinaryValueMediaTypeMapping(); var request = RequestFactory.Create(HttpMethod.Get, "http://localhost/RawValue(1)/BinaryProperty/$value"); request.ODataContext().Path = path; double mapResult = mapping.TryMatchMediaType(request); Assert.Equal(1.0, mapResult); }
public void TryMatchMediaTypeWithBinaryRawValueMatchesRequest_OnODataSingleton() { // Arrange IEdmModel model = GetBinaryModel(); IEdmSingleton rawSingletonValue = model.EntityContainer.FindSingleton("RawSingletonValue"); IEdmEntityType rawValueEntity = model.SchemaElements.OfType <IEdmEntityType>().First(e => e.Name == "RawValueEntity"); IEdmStructuralProperty property = rawValueEntity.FindProperty("BinaryProperty") as IEdmStructuralProperty; Assert.NotNull(property); // Guard PropertySegment propertySegment = new PropertySegment(property); ODataPath path = new ODataPath(new SingletonSegment(rawSingletonValue), propertySegment, new ValueSegment(propertySegment.EdmType)); ODataBinaryValueMediaTypeMapping mapping = new ODataBinaryValueMediaTypeMapping(); var request = RequestFactory.Create(HttpMethod.Get, "http://localhost/RawSingletonValue/BinaryProperty/$value"); request.ODataContext().Path = path; // Act double mapResult = mapping.TryMatchMediaType(request); // Assert Assert.Equal(1.0, mapResult); }
public void TryMatchMediaType_ThrowsArgumentNull_WhenRequestIsNull() { // Arrange & Act & Assert ExceptionAssert.ThrowsArgumentNull(() => Mapping.TryMatchMediaType(null), "request"); }