Improve ValuesJsonConverter test coverage #108
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've gone through the vast majority of branching logic in
ValuesJsonConverterand have written up a number of tests to confirm everything. While a number of these would have been covered by other tests, I have already uncovered a number of strange things inValuesJsonConverter.Values<>serialization supports writing mixed value types (eg.Values<int, string>) however doesn't support reading it.OneOrManyserialization supports reading single value nullable primitives from JSON however has issues when there is an array of them (the type passed to the constructor isList<int>rather thanList<int?>).DateTimereading logic is strange where it can be astring,DateTime,DateTimeOffsetand then any other non-primitive type. What I don't understand is how that branch (any other non-primitive toDateTime) is ever hit. Maybe possible if a type implementsIConvertible<DateTime>however none of the types in the library do as far as I know.DateTimeOffsethas similar strangeness toDateTimethough to a greater extent. I don't actually see howvaluecan ever be aDateTimeOffset. My best guess was the MS date format (eg.{"Property":"\/Date(946730040000)\/"}or{"Property":"\/Date(946730040000-0100)\/"}) however in my testing, that is still typeDateTime.Values<>actually matters in relation to the JSON (eg.Values<string, int>with the JSON["A","B"]throws an exception)Finally there is a block of code that I don't actually understand when it ever would run:
It looks like, after all the other type checks for a value, it is expecting a
structhowever I actually tried with astructwith constructor initialisation but it doesn't work. Was this meant forstructwith settable properties?I have written tests for some of the issues I've found here though I have marked them as "Skip" - I will activate these tests once I have fixed the individual issues in separate PRs.