-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertiesTests.cs
134 lines (107 loc) · 2.81 KB
/
PropertiesTests.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
namespace CSharpInteractive.Tests;
public class PropertiesTests
{
private readonly Mock<ILog<Properties>> _log;
private readonly Mock<ISettings> _settings;
private readonly Dictionary<string, string> _scriptProperties = new();
public PropertiesTests()
{
_log = new Mock<ILog<Properties>>();
_settings = new Mock<ISettings>();
_settings.SetupGet(i => i.ScriptProperties).Returns(_scriptProperties);
}
[Fact]
public void ShouldInit()
{
// Given
_scriptProperties["Abc"] = "Xyz";
_scriptProperties["11"] = " ";
_scriptProperties["Xyz"] = string.Empty;
var props = CreateInstance();
// When
// Then
props.Count.ShouldBe(2);
}
[Fact]
public void ShouldSupportIndexedGetter()
{
// Given
_scriptProperties["Abc"] = "Xyz";
var props = CreateInstance();
// When
var val = props["Abc"];
// Then
val.ShouldBe("Xyz");
}
[Fact]
public void ShouldSupportTryGetValue()
{
// Given
_scriptProperties["Abc"] = "Xyz";
var props = CreateInstance();
// When
props.TryGetValue("Abc", out var val).ShouldBeTrue();
// Then
val.ShouldBe("Xyz");
}
[Fact]
public void ShouldSupportIndexedSetter()
{
// Given
var props = CreateInstance();
// When
props["Abc"] = "Xyz";
var val = props["Abc"];
// Then
val.ShouldBe("Xyz");
props.Count.ShouldBe(1);
}
[Fact]
public void ShouldGetEmptyStringWhenNoValue()
{
// Given
var props = CreateInstance();
// When
var val = props["Abc"];
// Then
val.ShouldBe(string.Empty);
}
[Fact]
public void ShouldSupportTryGetValueWhenNoValue()
{
// Given
var props = CreateInstance();
// When
var result = props.TryGetValue("Abc", out _);
// Then
result.ShouldBeFalse();
}
[Fact]
public void ShouldEnumeratePairs()
{
// Given
_scriptProperties["Abc"] = "Xyz";
_scriptProperties["1"] = "2";
var props = CreateInstance();
// When
// Then
props.ToArray().ShouldBe([
new KeyValuePair<string, string>("Abc", "Xyz"),
new KeyValuePair<string, string>("1", "2")
]);
}
[Fact]
public void ShouldRemoveStringWhenSetEmptyValue()
{
// Given
_scriptProperties["Abc"] = "Xyz";
var props = CreateInstance();
// When
props["Abc"] = string.Empty;
// Then
props["Abc"].ShouldBe(string.Empty);
props.Count.ShouldBe(0);
}
private Properties CreateInstance() =>
new(_log.Object, _settings.Object);
}