Skip to content

Commit bb4bebf

Browse files
committed
Updating deprecated test functions
Changed deprecated Assert functions to current versions of those functions. Enabled Skipped Ctor_NullStream_ThrowsArgumentNullException test as it now is passing with correct exception being thrown. Enabled Dispose_BufferContentThenDisposeContent_BufferedStreamGetsDisposed test as it also is passing.
1 parent 20f9cce commit bb4bebf

File tree

2 files changed

+63
-71
lines changed

2 files changed

+63
-71
lines changed

Tests/HttpUnitTests/HttpContentTest.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,22 @@ public class HttpContentTest
1818
[TestMethod]
1919
public void Dispose_BufferContentThenDisposeContent_BufferedStreamGetsDisposed()
2020
{
21-
Assert.SkipTest("Skipping test because of issue in Test Framework");
22-
23-
// TODO
24-
// test is being reported as failing, despite it's successful, issue lyes in the TestFramework
25-
2621
MockContent content = new MockContent();
2722
content.LoadIntoBuffer();
2823

2924
Type type = typeof(HttpContent);
3025

3126
FieldInfo bufferedContentField = type.GetField("_buffer", BindingFlags.Instance | BindingFlags.NonPublic);
3227

33-
Assert.NotNull(bufferedContentField, "_buffer field shouldn't be null");
28+
Assert.IsNotNull(bufferedContentField, "_buffer field shouldn't be null");
3429

3530
MemoryStream bufferedContentStream = bufferedContentField.GetValue(content) as MemoryStream;
36-
Assert.NotNull(bufferedContentStream, "bufferedContentStream field shouldn't be null");
31+
Assert.IsNotNull(bufferedContentStream, "bufferedContentStream field shouldn't be null");
3732

3833
content.Dispose();
3934

4035
// The following line will throw an ObjectDisposedException if the buffered-stream was correctly disposed.
41-
Assert.Throws(typeof(ObjectDisposedException),
36+
Assert.ThrowsException(typeof(ObjectDisposedException),
4237
() =>
4338
{
4439
_ = bufferedContentStream.Length.ToString();
@@ -65,9 +60,9 @@ public void LoadIntoBuffer_ContentLengthSmallerThanActualData_ActualDataLargerTh
6560

6661
foreach (var testConfig in bufferTests)
6762
{
68-
Assert.True((testConfig.MaxSize >= 1 && testConfig.MaxSize <= (testConfig.NumberOfWrites * testConfig.SizeOfEachWrite) - 1), "Config values out of range.");
63+
Assert.IsTrue((testConfig.MaxSize >= 1 && testConfig.MaxSize <= (testConfig.NumberOfWrites * testConfig.SizeOfEachWrite) - 1), "Config values out of range.");
6964

70-
Assert.Throws(typeof(HttpRequestException),
65+
Assert.ThrowsException(typeof(HttpRequestException),
7166
() =>
7267
{
7368
LieAboutLengthContent c = new(

Tests/HttpUnitTests/StreamContentTest.cs

Lines changed: 58 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,24 @@ namespace HttpUnitTests
1414
[TestClass]
1515
public class StreamContentTest
1616
{
17-
// TODO need to fix processing of exception
18-
//[TestMethod]
19-
//public void Ctor_NullStream_ThrowsArgumentNullException()
20-
//{
21-
// Assert.SkipTest("Test disabled because of failure in StreamContent");
22-
//
23-
// Assert.Throws(typeof(ArgumentNullException),
24-
// () => new StreamContent(null));
25-
//}
17+
[TestMethod]
18+
public void Ctor_NullStream_ThrowsArgumentNullException()
19+
{
20+
Assert.ThrowsException(typeof(ArgumentNullException),
21+
() => new StreamContent(null));
22+
}
2623

2724
[TestMethod]
2825
public void Ctor_ZeroBufferSize_ThrowsArgumentOutOfRangeException()
2926
{
30-
Assert.Throws(typeof(ArgumentOutOfRangeException),
27+
Assert.ThrowsException(typeof(ArgumentOutOfRangeException),
3128
() => new StreamContent(new MemoryStream(), 0));
3229
}
3330

3431
[TestMethod]
3532
public void Ctor_NullStreamAndZeroBufferSize_ThrowsArgumentNullException()
3633
{
37-
Assert.Throws(typeof(ArgumentNullException),
34+
Assert.ThrowsException(typeof(ArgumentNullException),
3835
() => new StreamContent(null, 0));
3936
}
4037

@@ -44,7 +41,7 @@ public void ContentLength_SetStreamSupportingSeeking_StreamLengthMatchesHeaderVa
4441
var source = new MockStream(new byte[10], true, true);
4542
var content = new StreamContent(source);
4643

47-
Assert.Equal(source.Length, content.Headers.ContentLength);
44+
Assert.AreEqual(source.Length, content.Headers.ContentLength);
4845
}
4946

5047
[TestMethod]
@@ -55,7 +52,7 @@ public void ContentLength_SetStreamSupportingSeekingPartiallyConsumed_StreamLeng
5552
source.Read(new byte[consumed], 0, consumed);
5653
var content = new StreamContent(source);
5754

58-
Assert.Equal(source.Length - consumed, content.Headers.ContentLength);
55+
Assert.AreEqual(source.Length - consumed, content.Headers.ContentLength);
5956
}
6057

6158
[TestMethod]
@@ -65,15 +62,15 @@ public void Dispose_UseMockStreamSourceAndDisposeContent_MockStreamGotDisposed()
6562
var content = new StreamContent(source);
6663
content.Dispose();
6764

68-
Assert.Equal(1, source.DisposeCount);
65+
Assert.AreEqual(1, source.DisposeCount);
6966
}
7067

7168
[TestMethod]
7269
public void CopyToAsync_NullDestination_ThrowsArgumentnullException()
7370
{
7471
var source = new MockStream(new byte[10]);
7572
var content = new StreamContent(source);
76-
Assert.Throws(typeof(ArgumentNullException),
73+
Assert.ThrowsException(typeof(ArgumentNullException),
7774
() =>
7875
{
7976
content.CopyTo(null);
@@ -89,11 +86,11 @@ public void CopyTo_CallMultipleTimesWithStreamSupportingSeeking_ContentIsSeriali
8986

9087
var destination1 = new MemoryStream();
9188
content.CopyTo(destination1);
92-
Assert.Equal(source.Length, destination1.Length);
89+
Assert.AreEqual(source.Length, destination1.Length);
9390

9491
var destination2 = new MemoryStream();
9592
content.CopyTo(destination2);
96-
Assert.Equal(source.Length, destination2.Length);
93+
Assert.AreEqual(source.Length, destination2.Length);
9794
}
9895

9996
[TestMethod]
@@ -106,11 +103,11 @@ public void CopyTo_CallMultipleTimesWithStreamSupportingSeekingPartiallyConsumed
106103

107104
var destination1 = new MemoryStream();
108105
content.CopyTo(destination1);
109-
Assert.Equal(source.Length - consumed, destination1.Length);
106+
Assert.AreEqual(source.Length - consumed, destination1.Length);
110107

111108
var destination2 = new MemoryStream();
112109
content.CopyTo(destination2);
113-
Assert.Equal(source.Length - consumed, destination2.Length);
110+
Assert.AreEqual(source.Length - consumed, destination2.Length);
114111
}
115112

116113
[TestMethod]
@@ -123,11 +120,11 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeeking_ThrowsInvalid
123120
content.CopyTo(destination1);
124121

125122
// Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable).
126-
Assert.Equal(10, destination1.Length);
123+
Assert.AreEqual(10, destination1.Length);
127124

128125
// Note that the InvalidOperationException is thrown in CopyToAsync(). It is not thrown inside the task.
129126
var destination2 = new MemoryStream();
130-
Assert.Throws(typeof(InvalidOperationException),
127+
Assert.ThrowsException(typeof(InvalidOperationException),
131128
() =>
132129
{
133130
content.CopyTo(destination2);
@@ -147,11 +144,11 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeekingButBufferedStr
147144
var destination1 = new MemoryStream();
148145
content.CopyTo(destination1);
149146
// Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable)
150-
Assert.Equal(10, destination1.Length);
147+
Assert.AreEqual(10, destination1.Length);
151148

152149
var destination2 = new MemoryStream();
153150
content.CopyTo(destination2);
154-
Assert.Equal(10, destination2.Length);
151+
Assert.AreEqual(10, destination2.Length);
155152
}
156153

157154
[TestMethod]
@@ -169,11 +166,11 @@ public void CopyTo_CallMultipleTimesWithStreamNotSupportingSeekingButBufferedStr
169166
var destination1 = new MemoryStream();
170167
content.CopyTo(destination1);
171168
// Use hardcoded expected length, since source.Length would throw (source stream gets disposed if non-seekable).
172-
Assert.Equal(10 - consumed, destination1.Length);
169+
Assert.AreEqual(10 - consumed, destination1.Length);
173170

174171
var destination2 = new MemoryStream();
175172
content.CopyTo(destination2);
176-
Assert.Equal(10 - consumed, destination2.Length);
173+
Assert.AreEqual(10 - consumed, destination2.Length);
177174
}
178175

179176
[TestMethod]
@@ -242,10 +239,10 @@ public void ContentReadStream_GetProperty_ReturnOriginalStream()
242239
var content = new StreamContent(source);
243240

244241
Stream stream = content.ReadAsStream();
245-
Assert.False(stream.CanWrite);
246-
Assert.Equal(source.Length, stream.Length);
247-
Assert.Equal(0, source.ReadCount);
248-
Assert.NotSame(source, stream);
242+
Assert.IsFalse(stream.CanWrite);
243+
Assert.AreEqual(source.Length, stream.Length);
244+
Assert.AreEqual(0, source.ReadCount);
245+
Assert.AreNotSame(source, stream);
249246
}
250247

251248
[TestMethod]
@@ -271,11 +268,11 @@ public void ContentReadStream_GetPropertyPartiallyConsumed_ReturnOriginalStream(
271268
var content = new StreamContent(source);
272269

273270
Stream stream = content.ReadAsStream();
274-
Assert.False(stream.CanWrite);
275-
Assert.Equal(source.Length, stream.Length);
276-
Assert.Equal(1, source.ReadCount);
277-
Assert.Equal(consumed, stream.Position);
278-
Assert.NotSame(source, stream);
271+
Assert.IsFalse(stream.CanWrite);
272+
Assert.AreEqual(source.Length, stream.Length);
273+
Assert.AreEqual(1, source.ReadCount);
274+
Assert.AreEqual(consumed, stream.Position);
275+
Assert.AreNotSame(source, stream);
279276
}
280277

281278
[TestMethod]
@@ -296,56 +293,56 @@ public void ContentReadStream_CheckResultProperties_ValuesRepresentReadOnlyStrea
296293
// The following checks verify that the stream returned passes all read-related properties to the
297294
// underlying MockStream and throws when using write-related members.
298295

299-
Assert.False(contentReadStream.CanWrite);
300-
Assert.True(contentReadStream.CanRead);
301-
Assert.Equal(source.Length, contentReadStream.Length);
296+
Assert.IsFalse(contentReadStream.CanWrite);
297+
Assert.IsTrue(contentReadStream.CanRead);
298+
Assert.AreEqual(source.Length, contentReadStream.Length);
302299

303-
Assert.Equal(1, source.CanSeekCount);
300+
Assert.AreEqual(1, source.CanSeekCount);
304301
OutputHelper.WriteLine(contentReadStream.CanSeek.ToString());
305-
Assert.Equal(2, source.CanSeekCount);
302+
Assert.AreEqual(2, source.CanSeekCount);
306303

307304
contentReadStream.Position = 3; // No exception.
308-
Assert.Equal(3, contentReadStream.Position);
305+
Assert.AreEqual(3, contentReadStream.Position);
309306

310307
byte byteOnIndex3 = (byte)contentReadStream.ReadByte();
311-
Assert.Equal(data[3], byteOnIndex3);
308+
Assert.AreEqual(data[3], byteOnIndex3);
312309

313310
byte[] byteOnIndex4 = new byte[1];
314311
int result = contentReadStream.Read(byteOnIndex4, 0, 1);
315-
Assert.Equal(1, result);
312+
Assert.AreEqual(1, result);
316313

317-
Assert.Equal(data[4], byteOnIndex4[0]);
314+
Assert.AreEqual(data[4], byteOnIndex4[0]);
318315

319316
byte[] byteOnIndex5 = new byte[1];
320-
Assert.Equal(1, contentReadStream.Read(byteOnIndex5, 0, 1));
321-
Assert.Equal(data[5], byteOnIndex5[0]);
317+
Assert.AreEqual(1, contentReadStream.Read(byteOnIndex5, 0, 1));
318+
Assert.AreEqual(data[5], byteOnIndex5[0]);
322319

323320
byte[] byteOnIndex6 = new byte[1];
324-
Assert.Equal(1, contentReadStream.Read(new SpanByte(byteOnIndex6, 0, 1)));
325-
Assert.Equal(data[6], byteOnIndex6[0]);
321+
Assert.AreEqual(1, contentReadStream.Read(new SpanByte(byteOnIndex6, 0, 1)));
322+
Assert.AreEqual(data[6], byteOnIndex6[0]);
326323

327324
contentReadStream.ReadTimeout = 123;
328-
Assert.Equal(123, source.ReadTimeout);
329-
Assert.Equal(123, contentReadStream.ReadTimeout);
325+
Assert.AreEqual(123, source.ReadTimeout);
326+
Assert.AreEqual(123, contentReadStream.ReadTimeout);
330327

331-
Assert.Equal(0, source.CanTimeoutCount);
328+
Assert.AreEqual(0, source.CanTimeoutCount);
332329
OutputHelper.WriteLine(contentReadStream.CanTimeout.ToString());
333-
Assert.Equal(1, source.CanTimeoutCount);
330+
Assert.AreEqual(1, source.CanTimeoutCount);
334331

335-
Assert.Equal(0, source.SeekCount);
332+
Assert.AreEqual(0, source.SeekCount);
336333
contentReadStream.Seek(0, SeekOrigin.Begin);
337-
Assert.Equal(1, source.SeekCount);
334+
Assert.AreEqual(1, source.SeekCount);
338335

339-
Assert.Throws(typeof(NotSupportedException), () => { contentReadStream.WriteTimeout = 5; });
340-
Assert.Throws(typeof(NotSupportedException), () => contentReadStream.WriteTimeout.ToString());
341-
Assert.Throws(typeof(NotSupportedException), () => contentReadStream.Flush());
342-
Assert.Throws(typeof(NotSupportedException), () => contentReadStream.SetLength(1));
343-
Assert.Throws(typeof(NotSupportedException), () => contentReadStream.Write(null, 0, 0));
344-
Assert.Throws(typeof(NotSupportedException), () => contentReadStream.WriteByte(1));
336+
Assert.ThrowsException(typeof(NotSupportedException), () => { contentReadStream.WriteTimeout = 5; });
337+
Assert.ThrowsException(typeof(NotSupportedException), () => contentReadStream.WriteTimeout.ToString());
338+
Assert.ThrowsException(typeof(NotSupportedException), () => contentReadStream.Flush());
339+
Assert.ThrowsException(typeof(NotSupportedException), () => contentReadStream.SetLength(1));
340+
Assert.ThrowsException(typeof(NotSupportedException), () => contentReadStream.Write(null, 0, 0));
341+
Assert.ThrowsException(typeof(NotSupportedException), () => contentReadStream.WriteByte(1));
345342

346-
Assert.Equal(0, source.DisposeCount);
343+
Assert.AreEqual(0, source.DisposeCount);
347344
contentReadStream.Dispose();
348-
Assert.Equal(1, source.DisposeCount);
345+
Assert.AreEqual(1, source.DisposeCount);
349346
}
350347

351348
#region Helper methods

0 commit comments

Comments
 (0)