Skip to content

Commit a4ad21e

Browse files
committed
Update test code
1 parent ea8b8ce commit a4ad21e

4 files changed

Lines changed: 37 additions & 37 deletions

File tree

Tests/AdditionalTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,13 +203,13 @@ public void ResetOptions()
203203
private class TestObject
204204
{
205205
public int IntField;
206-
public string StringProp { get; set; }
206+
public string StringProp { get; set; } = string.Empty;
207207

208208
[SharpConfig.Ignore]
209209
public int IgnoredField;
210210

211211
[SharpConfig.Ignore]
212-
public string IgnoredProp { get; set; }
212+
public string IgnoredProp { get; set; } = string.Empty;
213213
}
214214
}
215215
}

Tests/InvalidInputTest.cs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,29 +34,29 @@ public void ConfigLoading()
3434
{
3535
var cfg = new Configuration();
3636

37-
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromFile(null));
37+
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromFile(null!));
3838
Assert.Throws<FileNotFoundException>(() => Configuration.LoadFromFile("doesnotexist.ini"));
39-
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromStream(null));
40-
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromString(null));
41-
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromBinaryFile(null));
42-
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromBinaryStream(null));
43-
Assert.Throws<ArgumentNullException>(() => cfg.SaveToFile(null));
44-
Assert.Throws<ArgumentNullException>(() => cfg.SaveToStream(null));
45-
Assert.Throws<ArgumentNullException>(() => cfg.SaveToBinaryFile(null));
46-
Assert.Throws<ArgumentNullException>(() => cfg.SaveToBinaryStream(null));
39+
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromStream(null!));
40+
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromString(null!));
41+
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromBinaryFile(null!));
42+
Assert.Throws<ArgumentNullException>(() => Configuration.LoadFromBinaryStream(null!));
43+
Assert.Throws<ArgumentNullException>(() => cfg.SaveToFile(null!));
44+
Assert.Throws<ArgumentNullException>(() => cfg.SaveToStream(null!));
45+
Assert.Throws<ArgumentNullException>(() => cfg.SaveToBinaryFile(null!));
46+
Assert.Throws<ArgumentNullException>(() => cfg.SaveToBinaryStream(null!));
4747
}
4848

4949
[Test]
5050
public void EmptyObjects()
5151
{
52-
Assert.Throws<ArgumentNullException>(() => new Setting(null));
53-
Assert.Throws<ArgumentNullException>(() => new Section(null));
52+
Assert.Throws<ArgumentNullException>(() => new Setting(null!));
53+
Assert.Throws<ArgumentNullException>(() => new Section(null!));
5454
}
5555

5656
[Test]
5757
public void Options()
5858
{
59-
Assert.Throws<ArgumentNullException>(() => Configuration.CultureInfo = null);
59+
Assert.Throws<ArgumentNullException>(() => Configuration.CultureInfo = null!);
6060
Assert.Throws<ArgumentException>(() => Configuration.PreferredCommentChar = 'a');
6161
Assert.Throws<ArgumentException>(() => Configuration.ArrayElementSeparator = '\0');
6262
}
@@ -65,20 +65,20 @@ public void Options()
6565
public void ConfigSectionOperations()
6666
{
6767
var cfg = new Configuration();
68-
Assert.Throws<ArgumentNullException>(() => cfg.Add((Section)null));
68+
Assert.Throws<ArgumentNullException>(() => cfg.Add((Section)null!));
6969

7070
var section = new Section("SomeSection");
7171
Assert.DoesNotThrow(() => cfg.Add(section));
7272

7373
Assert.Throws<ArgumentException>(() => cfg.Add(section));
7474

75-
Assert.Throws<ArgumentNullException>(() => cfg.Remove((string)null));
75+
Assert.Throws<ArgumentNullException>(() => cfg.Remove((string)null!));
7676
Assert.DoesNotThrow(() => cfg.Remove("SomeSection"));
7777

78-
Assert.Throws<ArgumentNullException>(() => cfg.RemoveAllNamed((string)null));
79-
Assert.Throws<ArgumentNullException>(() => cfg.Contains((string)null));
80-
Assert.Throws<ArgumentNullException>(() => cfg.Contains("A", null));
81-
Assert.Throws<ArgumentNullException>(() => cfg.Contains(null, "B"));
78+
Assert.Throws<ArgumentNullException>(() => cfg.RemoveAllNamed((string)null!));
79+
Assert.Throws<ArgumentNullException>(() => cfg.Contains((string)null!));
80+
Assert.Throws<ArgumentNullException>(() => cfg.Contains("A", null!));
81+
Assert.Throws<ArgumentNullException>(() => cfg.Contains(null!, "B"));
8282
Assert.DoesNotThrow(() => cfg.Contains("A", "B"));
8383

8484
Assert.DoesNotThrow(() => cfg.Add("SomeSection"));
@@ -93,16 +93,16 @@ public void Sections()
9393
var section = new Section("SomeSection");
9494
section.Add("S");
9595

96-
Assert.Throws<ArgumentException>(() => Section.FromObject(null, 1));
97-
Assert.Throws<ArgumentNullException>(() => Section.FromObject("A", null));
98-
Assert.Throws<ArgumentNullException>(() => section.ToObject(null));
99-
Assert.Throws<ArgumentNullException>(() => section.GetValuesFrom(null));
100-
Assert.Throws<ArgumentNullException>(() => section.SetValuesTo(null));
101-
Assert.Throws<ArgumentNullException>(() => section.Remove((string)null));
102-
Assert.Throws<ArgumentNullException>(() => section.Remove((Setting)null));
96+
Assert.Throws<ArgumentException>(() => Section.FromObject(null!, 1));
97+
Assert.Throws<ArgumentNullException>(() => Section.FromObject("A", null!));
98+
Assert.Throws<ArgumentNullException>(() => section.ToObject(null!));
99+
Assert.Throws<ArgumentNullException>(() => section.GetValuesFrom(null!));
100+
Assert.Throws<ArgumentNullException>(() => section.SetValuesTo(null!));
101+
Assert.Throws<ArgumentNullException>(() => section.Remove((string)null!));
102+
Assert.Throws<ArgumentNullException>(() => section.Remove((Setting)null!));
103103
Assert.Throws<ArgumentNullException>(() => section.Remove(""));
104-
Assert.Throws<ArgumentNullException>(() => section.RemoveAllNamed(null));
105-
Assert.Throws<ArgumentNullException>(() => section.Contains((string)null));
104+
Assert.Throws<ArgumentNullException>(() => section.RemoveAllNamed(null!));
105+
Assert.Throws<ArgumentNullException>(() => section.Contains((string)null!));
106106
Assert.DoesNotThrow(() => section[0].ToString());
107107
Assert.Throws<ArgumentOutOfRangeException>(() => section[-1].ToString());
108108
Assert.Throws<ArgumentOutOfRangeException>(() => section[1].ToString());
@@ -111,18 +111,18 @@ public void Sections()
111111
[Test]
112112
public void TypeStringConverterRegistration()
113113
{
114-
Assert.Throws<ArgumentNullException>(() => Configuration.RegisterTypeStringConverter(null));
114+
Assert.Throws<ArgumentNullException>(() => Configuration.RegisterTypeStringConverter(null!));
115115

116116
var converter = new DummyTypeStringConverter();
117117
Assert.DoesNotThrow(() => Configuration.RegisterTypeStringConverter(converter));
118118

119119
Assert.Throws<InvalidOperationException>(() => Configuration.RegisterTypeStringConverter(converter));
120120

121-
Assert.Throws<ArgumentNullException>(() => Configuration.DeregisterTypeStringConverter(null));
121+
Assert.Throws<ArgumentNullException>(() => Configuration.DeregisterTypeStringConverter(null!));
122122
Assert.DoesNotThrow(() => Configuration.DeregisterTypeStringConverter(typeof(DummyClass)));
123123
Assert.Throws<InvalidOperationException>(() => Configuration.DeregisterTypeStringConverter(typeof(DummyClass)));
124124

125-
Assert.Throws<ArgumentNullException>(() => Configuration.FindTypeStringConverter(null));
125+
Assert.Throws<ArgumentNullException>(() => Configuration.FindTypeStringConverter(null!));
126126
}
127127
}
128128
}

Tests/MultilineValuesTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void MultilineAttributeTest()
156156
private class MultilineTestObject
157157
{
158158
[Multiline]
159-
public string MultilineValue { get; set; }
159+
public string MultilineValue { get; set; } = string.Empty;
160160
}
161161

162162
[Test]

Tests/SimpleConfigTest.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public void SetGetValue()
7575
Assert.AreEqual(cfg["TestSection"]["IntSetting2"].GetValue(typeof(int)), 200);
7676
Assert.AreEqual(cfg["TestSection"]["StringSetting1"].GetValue(typeof(string)), "Test");
7777

78-
var intsNonGeneric = cfg["TestSection"]["IntArray"].GetValueArray(typeof(int));
79-
var intsGeneric = cfg["TestSection"]["IntArray"].GetValueArray<int>();
78+
var intsNonGeneric = cfg["TestSection"]["IntArray"].GetValueArray(typeof(int))!;
79+
var intsGeneric = cfg["TestSection"]["IntArray"].GetValueArray<int>()!;
8080

8181
Assert.AreEqual(intsNonGeneric.Length, intsGeneric.Length);
8282
Assert.AreEqual(intsGeneric.Length, ints.Length);
@@ -173,8 +173,8 @@ public void SetValueOverload()
173173
{ setting.GetValue(typeof(int)); });
174174

175175
// Now get the array object and check.
176-
var intsNonGeneric = setting.GetValueArray(typeof(int));
177-
var intsGeneric = setting.GetValueArray<int>();
176+
var intsNonGeneric = setting.GetValueArray(typeof(int))!;
177+
var intsGeneric = setting.GetValueArray<int>()!;
178178

179179
Assert.AreEqual(obj.Length, intsGeneric.Length);
180180
Assert.AreEqual(intsGeneric.Length, intsNonGeneric.Length);

0 commit comments

Comments
 (0)