public void CanReadThrowsIfContextIsNull() { // Arrange & Act ODataInputFormatter formatter = new ODataInputFormatter(new[] { ODataPayloadKind.Resource }); // Assert Assert.Throws <ArgumentNullException>("context", () => formatter.CanRead(context: null)); }
private static bool CanReadType(ODataInputFormatter formatter, Type type, HttpRequest request) { InputFormatterContext context = new InputFormatterContext( request.HttpContext, "modelName", new ModelStateDictionary(), new EmptyModelMetadataProvider().GetMetadataForType(type), (stream, encoding) => new StreamReader(stream, encoding)); return(formatter.CanRead(context)); }
public void CanReadReturnsFalseIfNoODataPathSet() { // Arrange & Act InputFormatterContext context = new InputFormatterContext( new DefaultHttpContext(), "modelName", new ModelStateDictionary(), new EmptyModelMetadataProvider().GetMetadataForType(typeof(int)), (stream, encoding) => new StreamReader(stream, encoding)); ODataInputFormatter formatter = new ODataInputFormatter(new[] { ODataPayloadKind.Resource }); // Assert Assert.False(formatter.CanRead(context)); }
public void CanReadReturnsBooleanValueAsExpected(Type type, ODataPayloadKind payloadKind, bool expected) { // Arrange & Act IEdmEntitySet entitySet = _edmModel.EntityContainer.FindEntitySet("Customers"); EntitySetSegment entitySetSeg = new EntitySetSegment(entitySet); HttpRequest request = RequestFactory.Create(opt => opt.AddModel("odata", _edmModel)); request.ODataFeature().PrefixName = "odata"; request.ODataFeature().Model = _edmModel; request.ODataFeature().Path = new ODataPath(entitySetSeg); InputFormatterContext context = CreateInputContext(type, request); ODataInputFormatter formatter = new ODataInputFormatter(new[] { payloadKind }); // Assert Assert.Equal(expected, formatter.CanRead(context)); }
public void CanReadResultODataOutputFormatter_Throws_IfRequestIsNull() { // Arrange & Act ODataInputFormatter formatter = new ODataInputFormatter(new[] { ODataPayloadKind.Resource }); Mock <HttpContext> httpContext = new Mock <HttpContext>(); httpContext.Setup(c => c.Request).Returns((HttpRequest)null); InputFormatterContext context = new InputFormatterContext(httpContext.Object, "any", new ModelStateDictionary(), new EmptyModelMetadataProvider().GetMetadataForType(typeof(int)), (stream, encoding) => null); // Assert ExceptionAssert.Throws <InvalidOperationException>( () => formatter.CanRead(context), "The OData formatter requires an attached request in order to deserialize."); }