Skip to content

Commit

Permalink
Add snake case test
Browse files Browse the repository at this point in the history
  • Loading branch information
sguryev committed Oct 11, 2024
1 parent 847bb2a commit df190f9
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Dynamic;
using System.Text.Json;
using SystemTextJsonPatch.Exceptions;
using SystemTextJsonPatch.Operations;
using Xunit;

namespace SystemTextJsonPatch.IntegrationTests;
Expand Down Expand Up @@ -56,6 +57,39 @@ public void ReplaceNestedObjectWithSerialization()
// Assert
Assert.Equal("B", targetObject.NestedObject.StringProperty);
}

#if NET8_0

[Fact]
public void ReplaceNestedObjectWithPlainStrings()
{
// Arrange
var targetObject = new SimpleObjectWithNestedObject()
{
IntegerValue = 1,
NestedObject = null
};
var options = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
};

var newNested = new NestedObject { StringProperty = "B" };
var patchDocument = new JsonPatchDocument<SimpleObjectWithNestedObject>();
patchDocument.Operations.Add(new Operation<SimpleObjectWithNestedObject>("replace", "/nested_object", JsonSerializer.Serialize(newNested, options)));
patchDocument.Options = options;

var serialized = JsonSerializer.Serialize(patchDocument, options);
var deserialized = JsonSerializer.Deserialize<JsonPatchDocument<SimpleObjectWithNestedObject>>(serialized, options);

// Act
deserialized.ApplyTo(targetObject);

// Assert
Assert.Equal("B", targetObject.NestedObject.StringProperty);
}

#endif

[Fact]
public void TestStringPropertyInNestedObject()
Expand Down

0 comments on commit df190f9

Please sign in to comment.