-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCollectionsTests.cs
More file actions
88 lines (75 loc) · 2.82 KB
/
CollectionsTests.cs
File metadata and controls
88 lines (75 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Text.Json;
using com.IvanMurzak.ReflectorNet.Model;
using com.IvanMurzak.ReflectorNet.Utils;
using Xunit.Abstractions;
namespace com.IvanMurzak.ReflectorNet.Tests.SchemaTests
{
public class CollectionsTests : BaseTest
{
public CollectionsTests(ITestOutputHelper output) : base(output) { }
static readonly List<Type> _collectionTypes = new List<Type>
{
typeof(int[]),
typeof(string[]),
typeof(List<int>),
typeof(IList<int>),
typeof(IReadOnlyList<int>),
typeof(Dictionary<string, int>),
typeof(IEnumerable<int>),
typeof(IList<string>),
typeof(ICollection<double>),
typeof(SerializedMemberList),
typeof(ListType),
typeof(ListTypeGeneric<int>),
typeof(ListTypeGeneric<string>),
typeof(ListTypeGeneric<int[]>),
typeof(ListTypeGeneric<ListType>),
typeof(ListTypeGeneric<ListTypeGeneric<int>>),
typeof(ListTypeGeneric<ListTypeGeneric<int[]>>)
};
class ListType : List<int>
{
public int? shouldBeIgnored;
public int ShouldBeIgnored { get; set; }
public ListType() { shouldBeIgnored = default; }
}
class ListTypeGeneric<T> : List<T>
{
public T? shouldBeIgnored = default;
public T? ShouldBeIgnored { get; set; }
public ListTypeGeneric() { shouldBeIgnored = default; }
}
[Fact]
public void GetTypeId_SimpleArray_ShouldAppendArray()
{
// Arrange
var reflector = new Reflector();
// Act
foreach (var type in _collectionTypes)
{
var result = reflector.GetSchema(type);
_output.WriteLine($"Type: {type.GetTypeShortName()}\n{result.ToJsonString(new JsonSerializerOptions { WriteIndented = true })}\n");
// Assert
Assert.NotNull(result);
Assert.NotNull(result[JsonSchema.Type]);
Assert.Equal(JsonSchema.Array, result[JsonSchema.Type]!.ToString());
Assert.NotNull(result[JsonSchema.Items]);
Assert.Null(result[nameof(ListType.shouldBeIgnored)]);
Assert.Null(result[nameof(ListType.ShouldBeIgnored)]);
}
}
[Fact]
public void CheckIfCollectionTypesAreEnumerable()
{
// Act
foreach (var type in _collectionTypes)
{
var isEnumerable = TypeUtils.IsIEnumerable(type);
_output.WriteLine($"Checking type: {type.GetTypeShortName()}, IsEnumerable: {isEnumerable}");
Assert.True(isEnumerable);
}
}
}
}