Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add tests for serializing and deserializing case sensitive JSON. #2531

Merged
merged 1 commit into from
Sep 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void DefaultInstanceParsesDates()
}

[Fact]
public void CustomInstanceAvoidingDateParsin()
public void CustomInstanceAvoidingDateParsing()
{
string text = "\"2017-05-03T16:38:00Z\"";
var settings = NewtonsoftJsonSerializer.CreateDefaultSettings();
Expand All @@ -63,5 +63,44 @@ public void CustomInstanceAvoidingDateParsin()
// No magic parsing to DateTime...
Assert.IsType<string>(value);
}

[Fact]
public void DefaultInstanceSerializesTwoETags()
{
var data = new DataWithTwoEtags
{
AField = "a value",
ETag = "lowercase",
ETag__ = "no-lowercase"
};
var expectedText = "{\"a_field\":\"a value\",\"etag\":\"lowercase\",\"ETag\":\"no-lowercase\"}";
var text = NewtonsoftJsonSerializer.Instance.Serialize(data);

Assert.Equal(expectedText, text);
}

[Fact]
public void DefaultInstanceDeserializesTwoETags()
{
var text = "{\"a_field\":\"a value\",\"etag\":\"lowercase\",\"ETag\":\"no-lowercase\"}";

var data = NewtonsoftJsonSerializer.Instance.Deserialize<DataWithTwoEtags>(text);

Assert.Equal("a value", data.AField);
Assert.Equal("lowercase", data.ETag);
Assert.Equal("no-lowercase", data.ETag__);
}

public class DataWithTwoEtags
{
[JsonProperty("a_field")]
public string AField { get; set; }

[JsonProperty("etag")]
public string ETag { get; set; }

[JsonProperty("ETag")]
public string ETag__ { get; set; }
}
}
}