-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathPropertyAndFieldTest.cs
65 lines (58 loc) · 1.53 KB
/
PropertyAndFieldTest.cs
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
using System.Linq;
using Xunit;
// Note: this test file is for API troubleshooting only
// Please do not reference the code here, it should not be used in production
namespace RingCentral.Tests;
internal class A
{
public string b = "bb";
public string c { get; set; } = "cc";
}
[Collection("Sequential")]
public class PropertyAndFieldTest
{
[Fact]
public void StaticClass()
{
var a = new A();
var fields = a.GetType().GetFields().Select(f => f.Name);
Assert.Equal(new[] { "b" }, fields);
var properties = a.GetType().GetProperties().Select(f => f.Name);
Assert.Equal(new[] { "c" }, properties);
}
[Fact]
public void DynamicClass()
{
var a = new
{
b = "b",
c = "c"
};
var fields = a.GetType().GetFields().Select(f => f.Name);
Assert.Empty(fields);
var properties = a.GetType().GetProperties().Select(f => f.Name);
Assert.Equal(new[] { "b", "c" }, properties);
}
[Fact]
private void GetPairs()
{
var a = new
{
b = "b",
c = "c"
};
var pairs = Utils.GetPairs(a);
Assert.Equal(new[]
{
(name: "b", value: "b"),
(name: "c", value: "c" as object)
}, pairs.ToArray());
var a2 = new A();
var pairs2 = Utils.GetPairs(a2);
Assert.Equal(new[]
{
(name: "b", value: "bb"),
(name: "c", value: "cc" as object)
}, pairs2.ToArray());
}
}