Skip to content
Merged
Show file tree
Hide file tree
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 @@ -384,6 +384,44 @@ public Task DictionaryInterfaceFallback_Formatted_MatchesSnapshot()
[Fact]
public Task ReadOnlyDictionaryInterfaceFallback_Formatted_MatchesSnapshot()
=> VerifyFallbackBitStream<IReadOnlyDictionary<string, int>>(new UnknownDictionary<string, int>(new Dictionary<string, int> { ["a"] = 1, ["b"] = 2 }), ReadOnlyDictionaryCodecAlias);

[Fact]
public Task EnumerableInterfaceConcreteList_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IEnumerable<int>>(new List<int> { 2, 4, 6 }, EnumerableCodecAlias);

[Fact]
public Task ReadOnlyCollectionInterfaceConcreteList_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IReadOnlyCollection<int>>(new List<int> { 2, 4, 6 }, ReadOnlyCollectionCodecAlias);

[Fact]
public Task ReadOnlyListInterfaceConcreteList_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IReadOnlyList<int>>(new List<int> { 2, 4, 6 }, ReadOnlyListCodecAlias);

[Fact]
public Task CollectionInterfaceConcreteList_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<ICollection<int>>(new List<int> { 2, 4, 6 }, CollectionCodecAlias);

[Fact]
public Task ListInterfaceConcreteList_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IList<int>>(new List<int> { 2, 4, 6 }, ListCodecAlias);

[Fact]
public Task SetInterfaceConcreteHashSet_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<ISet<string>>(new HashSet<string> { "a", "b" }, SetCodecAlias);

#if NET5_0_OR_GREATER
[Fact]
public Task ReadOnlySetInterfaceConcreteHashSet_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IReadOnlySet<string>>(new HashSet<string> { "a", "b" }, ReadOnlySetCodecAlias);
#endif

[Fact]
public Task DictionaryInterfaceConcreteDictionary_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IDictionary<string, int>>(new Dictionary<string, int> { ["a"] = 1, ["b"] = 2 }, DictionaryCodecAlias);

[Fact]
public Task ReadOnlyDictionaryInterfaceConcreteDictionary_Formatted_MatchesSnapshot()
=> VerifyConcreteRuntimeBitStream<IReadOnlyDictionary<string, int>>(new Dictionary<string, int> { ["a"] = 1, ["b"] = 2 }, ReadOnlyDictionaryCodecAlias);
#endif

private static T RoundTrip<T>(T value)
Expand All @@ -407,6 +445,17 @@ private static Task VerifyFallbackBitStream<T>(T value, string codecAlias)
return Verify(formatted, extension: "txt").UseDirectory("snapshots");
}

private static Task VerifyConcreteRuntimeBitStream<T>(T value, params string[] fallbackCodecAliases)
{
var formatted = FormatSerializedPayload(value);
foreach (var codecAlias in fallbackCodecAliases)
{
Assert.DoesNotContain($"TypeName \"{codecAlias}", formatted);
}

return Verify(formatted, extension: "txt").UseDirectory("snapshots");
}

private static string FormatSerializedPayload<T>(T value)
{
using var serviceProvider = new ServiceCollection().AddSerializer().BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0x002F [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.List`1[System.Int32] (name: Encoded "TypeName "System.Collections.Generic.List`1[[int]]" (hash 77903B0D)" (System.Collections.Generic.List`1[[System.Int32]]))] Value: {
0x0030 [#2 VarInt Id: 0 SchemaType: Expected] Value: 3 (0x3)
0x0032 [#3 VarInt Id: 1 SchemaType: Expected] Value: 4 (0x4)
0x0034 [#4 VarInt Id: 1 SchemaType: Expected] Value: 8 (0x8)
0x0036 [#5 VarInt Id: 1 SchemaType: Expected] Value: 12 (0xC)
0x0038 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0x003E [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.Dictionary`2[System.String,System.Int32] (name: Encoded "TypeName "System.Collections.Generic.Dictionary`2[[string],[int]]" (hash ABFDFCFE)" (System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]]))] Value: {
0x003F [#2 VarInt Id: 1 SchemaType: Expected] Value: 2 (0x2)
0x0041 [#3 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["a"]
0x0044 [#4 VarInt Id: 2 SchemaType: Expected] Value: 2 (0x2)
0x0046 [#5 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["b"]
0x0049 [#6 VarInt Id: 2 SchemaType: Expected] Value: 4 (0x4)
0x004B }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0x002F [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.List`1[System.Int32] (name: Encoded "TypeName "System.Collections.Generic.List`1[[int]]" (hash 77903B0D)" (System.Collections.Generic.List`1[[System.Int32]]))] Value: {
0x0030 [#2 VarInt Id: 0 SchemaType: Expected] Value: 3 (0x3)
0x0032 [#3 VarInt Id: 1 SchemaType: Expected] Value: 4 (0x4)
0x0034 [#4 VarInt Id: 1 SchemaType: Expected] Value: 8 (0x8)
0x0036 [#5 VarInt Id: 1 SchemaType: Expected] Value: 12 (0xC)
0x0038 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0x002F [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.List`1[System.Int32] (name: Encoded "TypeName "System.Collections.Generic.List`1[[int]]" (hash 77903B0D)" (System.Collections.Generic.List`1[[System.Int32]]))] Value: {
0x0030 [#2 VarInt Id: 0 SchemaType: Expected] Value: 3 (0x3)
0x0032 [#3 VarInt Id: 1 SchemaType: Expected] Value: 4 (0x4)
0x0034 [#4 VarInt Id: 1 SchemaType: Expected] Value: 8 (0x8)
0x0036 [#5 VarInt Id: 1 SchemaType: Expected] Value: 12 (0xC)
0x0038 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0x002F [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.List`1[System.Int32] (name: Encoded "TypeName "System.Collections.Generic.List`1[[int]]" (hash 77903B0D)" (System.Collections.Generic.List`1[[System.Int32]]))] Value: {
0x0030 [#2 VarInt Id: 0 SchemaType: Expected] Value: 3 (0x3)
0x0032 [#3 VarInt Id: 1 SchemaType: Expected] Value: 4 (0x4)
0x0034 [#4 VarInt Id: 1 SchemaType: Expected] Value: 8 (0x8)
0x0036 [#5 VarInt Id: 1 SchemaType: Expected] Value: 12 (0xC)
0x0038 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
0x003E [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.Dictionary`2[System.String,System.Int32] (name: Encoded "TypeName "System.Collections.Generic.Dictionary`2[[string],[int]]" (hash ABFDFCFE)" (System.Collections.Generic.Dictionary`2[[System.String],[System.Int32]]))] Value: {
0x003F [#2 VarInt Id: 1 SchemaType: Expected] Value: 2 (0x2)
0x0041 [#3 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["a"]
0x0044 [#4 VarInt Id: 2 SchemaType: Expected] Value: 2 (0x2)
0x0046 [#5 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["b"]
0x0049 [#6 VarInt Id: 2 SchemaType: Expected] Value: 4 (0x4)
0x004B }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
0x002F [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.List`1[System.Int32] (name: Encoded "TypeName "System.Collections.Generic.List`1[[int]]" (hash 77903B0D)" (System.Collections.Generic.List`1[[System.Int32]]))] Value: {
0x0030 [#2 VarInt Id: 0 SchemaType: Expected] Value: 3 (0x3)
0x0032 [#3 VarInt Id: 1 SchemaType: Expected] Value: 4 (0x4)
0x0034 [#4 VarInt Id: 1 SchemaType: Expected] Value: 8 (0x8)
0x0036 [#5 VarInt Id: 1 SchemaType: Expected] Value: 12 (0xC)
0x0038 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0x0035 [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.HashSet`1[System.String] (name: Encoded "TypeName "System.Collections.Generic.HashSet`1[[string]]" (hash DCA1FD98)" (System.Collections.Generic.HashSet`1[[System.String]]))] Value: {
0x0036 [#2 VarInt Id: 1 SchemaType: Expected] Value: 2 (0x2)
0x0038 [#3 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["a"]
0x003B [#4 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["b"]
0x003E }
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
0x0035 [#1 TagDelimited Id: 0 SchemaType: Encoded RuntimeType: System.Collections.Generic.HashSet`1[System.String] (name: Encoded "TypeName "System.Collections.Generic.HashSet`1[[string]]" (hash DCA1FD98)" (System.Collections.Generic.HashSet`1[[System.String]]))] Value: {
0x0036 [#2 VarInt Id: 1 SchemaType: Expected] Value: 2 (0x2)
0x0038 [#3 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["a"]
0x003B [#4 LengthPrefixed Id: 2 SchemaType: Expected] Value: (length: 1b) ["b"]
0x003E }
Loading