Skip to content

Commit d41299e

Browse files
authored
Eliminate deprecated asserts in test cases (#32)
***NO_CI***
1 parent 481a9e5 commit d41299e

7 files changed

+136
-136
lines changed

tests/ActivatorTests.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,57 +16,57 @@ public class ActivatorTests
1616
public static void CreateInstance()
1717
{
1818
Choice c = (Choice)(Activator.CreateInstance(typeof(Choice)));
19-
Assert.Equal(1, c.I);
19+
Assert.AreEqual(1, c.I);
2020

2121
c = (Choice)(Activator.CreateInstance(typeof(Choice).FullName));
22-
Assert.Equal(1, c.I);
22+
Assert.AreEqual(1, c.I);
2323

2424
c = (Choice)(Activator.CreateInstance(typeof(Choice), null));
25-
Assert.Equal(1, c.I);
25+
Assert.AreEqual(1, c.I);
2626

2727
c = (Choice)(Activator.CreateInstance(typeof(Choice), null, null));
28-
Assert.Equal(1, c.I);
28+
Assert.AreEqual(1, c.I);
2929

3030
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { }));
31-
Assert.Equal(1, c.I);
31+
Assert.AreEqual(1, c.I);
3232

3333
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { 42 }));
34-
Assert.Equal(2, c.I);
34+
Assert.AreEqual(2, c.I);
3535

3636
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { "Hello" }));
37-
Assert.Equal(3, c.I);
37+
Assert.AreEqual(3, c.I);
3838

3939
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { 5.1, "Hello" }));
40-
Assert.Equal(4, c.I);
40+
Assert.AreEqual(4, c.I);
4141
}
4242

4343
[TestMethod]
4444
public static void CreateInstanceConstructorWithParamsParameter()
4545
{
4646
Choice c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarArgs(), new object[] { } }));
47-
Assert.Equal(5, c.I);
47+
Assert.AreEqual(5, c.I);
4848

4949
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarArgs(), new object[] { "P1" } }));
50-
Assert.Equal(5, c.I);
50+
Assert.AreEqual(5, c.I);
5151

5252
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarArgs(), new object[] { "P1", "P2" } }));
53-
Assert.Equal(5, c.I);
53+
Assert.AreEqual(5, c.I);
5454

5555
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarStringArgs(), new string[] { } }));
56-
Assert.Equal(6, c.I);
56+
Assert.AreEqual(6, c.I);
5757

5858
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarStringArgs(), new string[] { "P1" } }));
59-
Assert.Equal(6, c.I);
59+
Assert.AreEqual(6, c.I);
6060

6161
// TODO:? c = (Choice1)(Activator.CreateInstance(typeof(Choice1), new object[] { new VarStringArgs(), "P1", "P2" }));
6262
c = (Choice)(Activator.CreateInstance(typeof(Choice), new object[] { new VarStringArgs(), new string[] { "P1", "P2" } }));
63-
Assert.Equal(6, c.I);
63+
Assert.AreEqual(6, c.I);
6464
}
6565

6666
[TestMethod]
6767
public void CreateInstanceNullTypeThrowsArgumentNullException()
6868
{
69-
Assert.Throws(typeof(ArgumentNullException), () => Activator.CreateInstance(null, new object[0]));
69+
Assert.ThrowsException(typeof(ArgumentNullException), () => Activator.CreateInstance(null, new object[0]));
7070
}
7171

7272
public class Choice

tests/ActivatorUtilitiesTests.cs

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public void TypeActivatorEnablesYouToCreateAnyTypeWithServicesEvenWhenNotInIocCo
2121

2222
var instance = (AnotherClass)ActivatorUtilities.CreateInstance(serviceProvider, typeof(AnotherClass));
2323

24-
Assert.NotNull(instance.FakeService);
24+
Assert.IsNotNull(instance.FakeService);
2525
}
2626

2727

@@ -38,9 +38,9 @@ public void TypeActivatorAcceptsAnyNumberOfAdditionalConstructorParametersToProv
3838
"1",
3939
"2");
4040

41-
Assert.NotNull(instance.FakeService);
42-
Assert.Equal("1", instance.One);
43-
Assert.Equal("2", instance.Two);
41+
Assert.IsNotNull(instance.FakeService);
42+
Assert.AreEqual("1", instance.One);
43+
Assert.AreEqual("2", instance.Two);
4444
}
4545

4646
[TestMethod]
@@ -52,10 +52,10 @@ public void TypeActivatorCanDisambiguateConstructorsWithUniqueArguments()
5252

5353
var instance = (ClassWithAmbiguousCtors)ActivatorUtilities.CreateInstance(serviceProvider, typeof(ClassWithAmbiguousCtors), "1", 2);
5454

55-
Assert.NotNull(instance);
56-
Assert.NotNull(instance.FakeService);
57-
Assert.Equal("1", instance.Data1);
58-
Assert.Equal(2, instance.Data2);
55+
Assert.IsNotNull(instance);
56+
Assert.IsNotNull(instance.FakeService);
57+
Assert.AreEqual("1", instance.Data1);
58+
Assert.AreEqual(2, instance.Data2);
5959
}
6060

6161
[TestMethod]
@@ -69,13 +69,13 @@ public void TypeActivatorCreateInstanceUsesFirstMathchedConstructor(object value
6969

7070
var instance = (ClassWithAmbiguousCtors)ActivatorUtilities.CreateInstance(serviceProvider, typeof(ClassWithAmbiguousCtors), value);
7171

72-
Assert.Equal(ctor, instance.CtorUsed);
72+
Assert.AreEqual(ctor, instance.CtorUsed);
7373
}
7474

7575
[TestMethod]
7676
public void TypeActivatorRethrowsOriginalExceptionFromConstructor()
7777
{
78-
Assert.Throws(typeof(Exception),
78+
Assert.ThrowsException(typeof(Exception),
7979
() =>
8080
{
8181
try
@@ -96,7 +96,7 @@ public void TypeActivatorRethrowsOriginalExceptionFromConstructor()
9696
}
9797
);
9898

99-
Assert.Throws(typeof(Exception),
99+
Assert.ThrowsException(typeof(Exception),
100100
() =>
101101
{
102102
try
@@ -125,11 +125,11 @@ public void TypeActivatorRequiresAllArgumentsCanBeAccepted()
125125
.AddTransient(typeof(IFakeService), typeof(FakeService))
126126
.BuildServiceProvider();
127127

128-
Assert.Throws(typeof(InvalidOperationException),
128+
Assert.ThrowsException(typeof(InvalidOperationException),
129129
() => ActivatorUtilities.CreateInstance(serviceProvider, typeof(AnotherClassAcceptingData), "1", "2", "3")
130130
);
131131

132-
Assert.Throws(typeof(InvalidOperationException),
132+
Assert.ThrowsException(typeof(InvalidOperationException),
133133
() => ActivatorUtilities.CreateInstance(serviceProvider, typeof(AnotherClassAcceptingData), 1, 2)
134134
);
135135
}
@@ -148,14 +148,14 @@ public void GetServiceOrCreateInstanceRegisteredServiceTransient()
148148
.BuildServiceProvider();
149149

150150
var service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
151-
Assert.NotNull(service);
152-
Assert.Equal(1, service.InstanceId);
153-
Assert.Equal(1, CreationCountFakeService.InstanceCount);
151+
Assert.IsNotNull(service);
152+
Assert.AreEqual(1, service.InstanceId);
153+
Assert.AreEqual(1, CreationCountFakeService.InstanceCount);
154154

155155
service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
156-
Assert.NotNull(service);
157-
Assert.Equal(2, service.InstanceId);
158-
Assert.Equal(2, CreationCountFakeService.InstanceCount);
156+
Assert.IsNotNull(service);
157+
Assert.AreEqual(2, service.InstanceId);
158+
Assert.AreEqual(2, CreationCountFakeService.InstanceCount);
159159
}
160160
}
161161

@@ -173,14 +173,14 @@ public void GetServiceOrCreateInstanceRegisteredServiceSingleton()
173173
.BuildServiceProvider();
174174

175175
var service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
176-
Assert.NotNull(service);
177-
Assert.Equal(1, service.InstanceId);
178-
Assert.Equal(1, CreationCountFakeService.InstanceCount);
176+
Assert.IsNotNull(service);
177+
Assert.AreEqual(1, service.InstanceId);
178+
Assert.AreEqual(1, CreationCountFakeService.InstanceCount);
179179

180180
service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
181-
Assert.NotNull(service);
182-
Assert.Equal(1, service.InstanceId);
183-
Assert.Equal(1, CreationCountFakeService.InstanceCount);
181+
Assert.IsNotNull(service);
182+
Assert.AreEqual(1, service.InstanceId);
183+
Assert.AreEqual(1, CreationCountFakeService.InstanceCount);
184184
}
185185
}
186186

@@ -197,14 +197,14 @@ public void GetServiceOrCreateInstanceUnregisteredService()
197197
.BuildServiceProvider();
198198

199199
var service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
200-
Assert.NotNull(service);
201-
Assert.Equal(1, service.InstanceId);
202-
Assert.Equal(1, CreationCountFakeService.InstanceCount);
200+
Assert.IsNotNull(service);
201+
Assert.AreEqual(1, service.InstanceId);
202+
Assert.AreEqual(1, CreationCountFakeService.InstanceCount);
203203

204204
service = (CreationCountFakeService)ActivatorUtilities.GetServiceOrCreateInstance(serviceProvider, typeof(CreationCountFakeService));
205-
Assert.NotNull(service);
206-
Assert.Equal(2, service.InstanceId);
207-
Assert.Equal(2, CreationCountFakeService.InstanceCount);
205+
Assert.IsNotNull(service);
206+
Assert.AreEqual(2, service.InstanceId);
207+
Assert.AreEqual(2, CreationCountFakeService.InstanceCount);
208208
}
209209
}
210210

@@ -215,7 +215,7 @@ public void UnRegisteredServiceAsConstructorParameterThrowsException()
215215
.AddSingleton(typeof(CreationCountFakeService))
216216
.BuildServiceProvider();
217217

218-
Assert.Throws(typeof(InvalidOperationException),
218+
Assert.ThrowsException(typeof(InvalidOperationException),
219219
() => ActivatorUtilities.CreateInstance(serviceProvider, typeof(CreationCountFakeService))
220220
);
221221
}

tests/AggregateExceptionTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ public class AggregateExceptionTests
1616
public static void ConstructorBasic()
1717
{
1818
AggregateException ex = new AggregateException();
19-
Assert.Equal(0, ex.InnerExceptions.Count);
20-
Assert.True(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor is used, expected a default message");
19+
Assert.AreEqual(0, ex.InnerExceptions.Count);
20+
Assert.IsTrue(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor is used, expected a default message");
2121

2222
ex = new AggregateException("message");
23-
Assert.Equal(0, ex.InnerExceptions.Count);
24-
Assert.True(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor(string) is used");
25-
23+
Assert.AreEqual(0, ex.InnerExceptions.Count);
24+
Assert.IsTrue(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor(string) is used");
25+
2626
ex = new AggregateException("message", new Exception());
27-
Assert.Equal(1, ex.InnerExceptions.Count);
28-
Assert.True(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor(string, Exception) is used");
27+
Assert.AreEqual(1, ex.InnerExceptions.Count);
28+
Assert.IsTrue(ex.Message != null, "RunAggregateException_Constructor: FAILED. Message property is null when the default constructor(string, Exception) is used");
2929
}
3030

3131
[TestMethod]
3232
public static void ConstructorInvalidArguments()
3333
{
34-
Assert.Throws(typeof(ArgumentNullException), () => new AggregateException("message", (Exception)null));
35-
Assert.Throws(typeof(ArgumentNullException), () => new AggregateException("message", new ArrayList() { null }));
34+
Assert.ThrowsException(typeof(ArgumentNullException), () => new AggregateException("message", (Exception)null));
35+
Assert.ThrowsException(typeof(ArgumentNullException), () => new AggregateException("message", new ArrayList() { null }));
3636
}
3737

3838
[TestMethod]
@@ -43,7 +43,7 @@ public static void Message()
4343
Exception exceptionC = new Exception("C");
4444

4545
AggregateException aggExceptionBase = new AggregateException("message", exceptionA, exceptionB, exceptionC);
46-
Assert.Equal("message (A) (B) (C)", aggExceptionBase.Message);
46+
Assert.AreEqual("message (A) (B) (C)", aggExceptionBase.Message);
4747
//Assert.Equal("message (A) (B) (C)\n---> (Inner Exception #0) System.Exception: A <---\n---> (Inner Exception #1) System.Exception: B <---\n---> (Inner Exception #2) System.Exception: C <---\n", aggExceptionBase.ToString());
4848
}
4949
}

0 commit comments

Comments
 (0)