Open augerhandle opened 9 years ago
In a test I am writing, I have some assertions on the deserialized JSON that I get back from my API. The deserialization and assert looks like this:
var output = result.Body.Deserialize<MyOutput>(new JsonNetBodyDeserializer()); Assert.That( output... );
Unfortunately, I never get to the assert. Instead, I get an ArgumentNullException from System.Linq.Enumerable.
Here's how that happens. When result.Body.Deserialize() executes, it has the following code in it:
var bindingContext = new BindingContext { DestinationType = typeof(TModel) }; return (TModel)bodyDeserializer.Deserialize(bodyWrapper.ContentType, bodyWrapper.AsStream(), bindingContext);
Notice in particular the only property defined in bindingContext is DestinationType. In particular the ValidModelBindingMembers property is null.
Now, when the JsonNetBodyDeserializer Deserialize() method is executed, there is code in there that looks like this:
if (properties.Concat(fields).Except(context.ValidModelBindingMembers).Any()){...}
In other words, the argument to Except() is null, which immediately causes Except() to throw an exception.
My conclusion is that JsonNetBodyDeserializer is guarenteed never to work in this scenario.
Is this a bug, or am I somehow misusing the class in the first place?
In a test I am writing, I have some assertions on the deserialized JSON that I get back from my API. The deserialization and assert looks like this:
Unfortunately, I never get to the assert. Instead, I get an ArgumentNullException from System.Linq.Enumerable.
Here's how that happens. When result.Body.Deserialize() executes, it has the following code in it:
Notice in particular the only property defined in bindingContext is DestinationType. In particular the ValidModelBindingMembers property is null.
Now, when the JsonNetBodyDeserializer Deserialize() method is executed, there is code in there that looks like this:
In other words, the argument to Except() is null, which immediately causes Except() to throw an exception.
My conclusion is that JsonNetBodyDeserializer is guarenteed never to work in this scenario.
Is this a bug, or am I somehow misusing the class in the first place?