Skip to content

Commit

Permalink
Remove unnecessary null coalescing in settings.MergeArrayHandling (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamco authored Mar 31, 2024
1 parent d1e67cb commit 549ae43
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static bool ContainsValue(this JsonArray? jsonArray, JsonValue? value)

settings ??= new JsonMergeSettings();

switch (settings?.MergeArrayHandling ?? MergeArrayHandling.Concat)
switch (settings.MergeArrayHandling)
{
case MergeArrayHandling.Concat:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<InternalsVisibleTo Include="OrchardCore.Tests" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions test/OrchardCore.Tests/Abstractions/Json/Nodes/JArrayTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Text.Json.Nodes;
using System.Text.Json.Settings;

namespace OrchardCore.Json.Nodes.Test;

public class JArrayTests
{
public static IEnumerable<object[]> MergeArrayEntries => [
["[1, 2, 3, 4]", "[4, 5, 6]", null, "[1,2,3,4,4,5,6]"],
["[1, 2, 3, 4]", "[4, 5, 6]", new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Concat }, "[1,2,3,4,4,5,6]"],
["[1, 2, 3, 4]", "[4, 5, 6]", new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Union }, "[1,2,3,4,5,6]"],
["[1, 2, 3, 4]", "[4, 5, 6]", new JsonMergeSettings() { MergeArrayHandling = MergeArrayHandling.Replace }, "[4,5,6]"]
];

[Theory]
[MemberData(nameof(MergeArrayEntries))]
public void MergeArrayShouldRespectJsonMergeSettings(string jsonArrayContent1, string jsonArrayContent2, JsonMergeSettings mergeSettings, string expectedJsonString)
{
// Arrange
var array = JsonNode.Parse(jsonArrayContent1) as JsonArray;
var content = JsonNode.Parse(jsonArrayContent2);

// Act
var result = array.Merge(content, mergeSettings);

// Assert
Assert.NotNull(result);
Assert.Equal(expectedJsonString, result.ToJsonString());
}
}

0 comments on commit 549ae43

Please sign in to comment.