-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Source/ZoomNet.UnitTests/Json/TrackingFieldsConverterTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Shouldly; | ||
using System; | ||
using System.Text; | ||
using System.Text.Json; | ||
using Xunit; | ||
using ZoomNet.Json; | ||
|
||
namespace ZoomNet.UnitTests.Json | ||
{ | ||
public class TrackingFieldsConverterTests | ||
{ | ||
[Fact] | ||
public void Read() | ||
{ | ||
// Arrange | ||
var json = @"[ | ||
{ ""field"": ""some_field"", ""value"": ""ABC_123"" }, | ||
{ ""field"": ""another_field"", ""value"": ""FooBar"" } | ||
]"; | ||
var jsonUtf8 = (ReadOnlySpan<byte>)Encoding.UTF8.GetBytes(json); | ||
var jsonReader = new Utf8JsonReader(jsonUtf8); | ||
var objectType = (Type)null; | ||
var options = new JsonSerializerOptions(); | ||
|
||
var converter = new TrackingFieldsConverter(); | ||
|
||
// Act | ||
jsonReader.Read(); | ||
var result = converter.Read(ref jsonReader, objectType, options); | ||
|
||
// Assert | ||
result.ShouldNotBeNull(); | ||
result.Length.ShouldBe(2); | ||
result[0].Key.ShouldBe("some_field"); | ||
result[0].Value.ShouldBe("ABC_123"); | ||
result[1].Key.ShouldBe("another_field"); | ||
result[1].Value.ShouldBe("FooBar"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text.Json; | ||
|
||
namespace ZoomNet.Json | ||
{ | ||
/// <summary> | ||
/// Converts an array of <see cref="KeyValuePair{TKey, TValue}"/> to or from JSON. | ||
/// Converts an array of <see cref="KeyValuePair{String, String}"/> to or from JSON. | ||
/// </summary> | ||
/// <seealso cref="ZoomNetJsonConverter{T}"/> | ||
internal class TrackingFieldsConverter : ZoomNetJsonConverter<KeyValuePair<string, string>[]> | ||
/// <seealso cref="KeyValuePairConverter"/> | ||
internal class TrackingFieldsConverter : KeyValuePairConverter | ||
{ | ||
private readonly KeyValuePairConverter _converter = new KeyValuePairConverter("field", "value"); | ||
|
||
public override KeyValuePair<string, string>[] Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
return _converter.Read(ref reader, typeToConvert, options); | ||
} | ||
|
||
public override void Write(Utf8JsonWriter writer, KeyValuePair<string, string>[] value, JsonSerializerOptions options) | ||
public TrackingFieldsConverter() | ||
: base("field", "value") | ||
{ | ||
_converter.Write(writer, value, options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"sdk": { | ||
"version": "7.0.203", | ||
"rollForward": "latestFeature" | ||
"version": "7.0.302", | ||
"rollForward": "patch", | ||
"allowPrerelease": false | ||
} | ||
} |