dotnet / dotnet/aspnetcore

JsonPatch test operation error message has values not used in the actual test

Open
#38,872 1 comment 0 reactions 1 assignee Claimed by @bradygaster View on GitHub
area-minimal area-mvc area-networking feature-json-patch
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

Take the example below where the patch test value doesn't have a "Z" or offset etc., so by default Newtonsoft deserializes as DateTime with DateTimeKind.Unspecified and roundtrips that when serializing.

I believe the patch test compares serialized versions of the values, so the test does not pass because the existing UTC value will be serialized with a "Z" while the patch test value won't - this is fair enough, the test value should probably have the Z in order to pass.

However, the error message is:
`The current value '01/01/2000 01:01:01' at path 'utcDateTime' is not equal to the test value '01/01/2000 01:01:01'.`

It appears that while the test uses the JSON serialized values, the message uses ToString() values, which leads to an incorrect, or at least confusing, message.

3.1
```C#
{
var incomingOperations = new[]
{
new Operation
{
op = "test",
path = "/utcDateTime",
value = "2000-01-01T01:01:01"
}
};

var incomingJson = JsonConvert.SerializeObject(incomingOperations);

var document = JsonConvert.DeserializeObject>(incomingJson);

var existingEntity = new Test { UtcDateTime = new DateTime(2000, 1, 1, 1, 1, 1, DateTimeKind.Utc) };

document.ApplyTo(existingEntity, x => Debug.WriteLine(x.ErrorMessage));
}

public class Test
{
public DateTime UtcDateTime { get; set; }
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.