Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 22e4ab4

Browse files
committed
Use Assert.Same in TaskFactory_FromAsyncTests
When comparing the async state object, use Assert.Same to make sure we are verifying reference equality. This is functionally the same as before, but clearer semantically
1 parent e7b239c commit 22e4ab4

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

src/System.Threading.Tasks/tests/TaskFactory/TaskFactory_FromAsyncTests.cs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public static void RunAPMFactoryTests()
3939
t = Task.Factory.FromAsync(fac.StartWrite, fac.EndWrite, stateObject);
4040
t.Wait();
4141
Assert.Equal(0, check.Length);
42-
Assert.Equal(stateObject, ((IAsyncResult)t).AsyncState);
42+
Assert.Same(stateObject, ((IAsyncResult)t).AsyncState);
4343

4444
// Exercise 1-arg void option
4545
Task.Factory.FromAsync(
@@ -48,7 +48,7 @@ public static void RunAPMFactoryTests()
4848
"1234", stateObject).Wait();
4949
check = fac.ToString();
5050
Assert.Equal("1234", check);
51-
Assert.Equal(stateObject, ((IAsyncResult)t).AsyncState);
51+
Assert.Same(stateObject, ((IAsyncResult)t).AsyncState);
5252

5353
// Exercise 2-arg void option
5454
Task.Factory.FromAsync(
@@ -58,7 +58,7 @@ public static void RunAPMFactoryTests()
5858
4, stateObject).Wait();
5959
check = fac.ToString();
6060
Assert.Equal("1234aaaa", check);
61-
Assert.Equal(stateObject, ((IAsyncResult)t).AsyncState);
61+
Assert.Same(stateObject, ((IAsyncResult)t).AsyncState);
6262

6363
// Exercise 3-arg void option
6464
Task.Factory.FromAsync(
@@ -70,7 +70,7 @@ public static void RunAPMFactoryTests()
7070
stateObject).Wait();
7171
check = fac.ToString();
7272
Assert.Equal("1234aaaazzzz", check);
73-
Assert.Equal(stateObject, ((IAsyncResult)t).AsyncState);
73+
Assert.Same(stateObject, ((IAsyncResult)t).AsyncState);
7474

7575
// Read side, exercises getting return values from EndMethod
7676
char[] carray = new char[100];
@@ -86,7 +86,7 @@ public static void RunAPMFactoryTests()
8686
string s = f.Result;
8787
Assert.Equal("1234", s);
8888
Assert.Equal('1', carray[0]);
89-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
89+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
9090

9191
// Exercise 2-arg value option
9292
f = Task<string>.Factory.FromAsync(
@@ -98,7 +98,7 @@ public static void RunAPMFactoryTests()
9898
s = f.Result;
9999
Assert.Equal("aaaa", s);
100100
Assert.Equal('a', carray[0]);
101-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
101+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
102102

103103
// Exercise 1-arg value option
104104
f = Task<string>.Factory.FromAsync(
@@ -108,7 +108,7 @@ public static void RunAPMFactoryTests()
108108
stateObject);
109109
s = f.Result;
110110
Assert.Equal("z", s);
111-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
111+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
112112

113113
// Exercise 0-arg value option
114114
f = Task<string>.Factory.FromAsync(
@@ -117,7 +117,7 @@ public static void RunAPMFactoryTests()
117117
stateObject);
118118
s = f.Result;
119119
Assert.Equal("zzz", s);
120-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
120+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
121121

122122
//
123123
// Do all of the read tests again, except with Task.Factory.FromAsync<string>(), instead of Task<string>.Factory.FromAsync().
@@ -137,7 +137,7 @@ public static void RunAPMFactoryTests()
137137
s = f.Result;
138138
Assert.Equal("1234", s);
139139
Assert.Equal('1', carray[0]);
140-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
140+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
141141

142142
// one more with the creationOptions overload
143143
f = Task.Factory.FromAsync<int, char[], int, string>(
@@ -153,7 +153,7 @@ public static void RunAPMFactoryTests()
153153
s = f.Result;
154154
Assert.Equal("5678", s);
155155
Assert.Equal('5', carray[0]);
156-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
156+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
157157

158158
// Exercise 2-arg value option
159159
f = Task.Factory.FromAsync<int, char[], string>(
@@ -165,7 +165,7 @@ public static void RunAPMFactoryTests()
165165
s = f.Result;
166166
Assert.Equal("aaaa", s);
167167
Assert.Equal('a', carray[0]);
168-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
168+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
169169

170170
//one more with the creation option overload
171171
f = Task.Factory.FromAsync<int, char[], string>(
@@ -178,7 +178,7 @@ public static void RunAPMFactoryTests()
178178
s = f.Result;
179179
Assert.Equal("AAAA", s);
180180
Assert.Equal('A', carray[0]);
181-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
181+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
182182

183183
// Exercise 1-arg value option
184184
f = Task.Factory.FromAsync<int, string>(
@@ -188,7 +188,7 @@ public static void RunAPMFactoryTests()
188188
stateObject);
189189
s = f.Result;
190190
Assert.Equal("z", s);
191-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
191+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
192192

193193
// one more with creation option overload
194194
f = Task.Factory.FromAsync<int, string>(
@@ -199,7 +199,7 @@ public static void RunAPMFactoryTests()
199199
TaskCreationOptions.None);
200200
s = f.Result;
201201
Assert.Equal("z", s);
202-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
202+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
203203

204204
// Exercise 0-arg value option
205205
f = Task.Factory.FromAsync<string>(
@@ -208,7 +208,7 @@ public static void RunAPMFactoryTests()
208208
stateObject);
209209
s = f.Result;
210210
Assert.Equal("zz", s);
211-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
211+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
212212

213213
//one more with Creation options overload
214214
f = Task.Factory.FromAsync<string>(
@@ -218,7 +218,7 @@ public static void RunAPMFactoryTests()
218218
TaskCreationOptions.None);
219219
s = f.Result;
220220
Assert.Equal(string.Empty, s);
221-
Assert.Equal(stateObject, ((IAsyncResult)f).AsyncState);
221+
Assert.Same(stateObject, ((IAsyncResult)f).AsyncState);
222222

223223
// Inject a few more characters into the buffer
224224
fac.EndWrite(fac.StartWrite("0123456789", null, null));

0 commit comments

Comments
 (0)