88using System ;
99using System . IO ;
1010using System . Net . Http ;
11- using System . Text ;
1211
1312namespace HttpUnitTests
1413{
@@ -18,113 +17,106 @@ public class ByteArrayContentTest
1817 [ TestMethod ]
1918 public void Ctor_NullSourceArray_ThrowsArgumentNullException ( )
2019 {
21- Assert . Throws ( typeof ( ArgumentNullException ) , ( ) => new ByteArrayContent ( null ) ) ;
20+ Assert . ThrowsException ( typeof ( ArgumentNullException ) , ( ) => new ByteArrayContent ( null ) ) ;
2221 }
2322
2423 [ TestMethod ]
2524 public void Ctor_NullSourceArrayWithRange_ThrowsArgumentNullException ( )
2625 {
27- Assert . Throws ( typeof ( ArgumentNullException ) , ( ) => new ByteArrayContent ( null , 0 , 1 ) ) ;
26+ Assert . ThrowsException ( typeof ( ArgumentNullException ) , ( ) => new ByteArrayContent ( null , 0 , 1 ) ) ;
2827 }
2928
3029 [ TestMethod ]
3130 public void Ctor_EmptySourceArrayWithRange_ThrowsArgumentOutOfRangeException ( )
3231 {
33- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 0 ] , 0 , 1 ) ) ;
32+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 0 ] , 0 , 1 ) ) ;
3433 }
3534
3635 [ TestMethod ]
3736 public void Ctor_StartIndexTooBig_ThrowsArgumentOufOfRangeException ( )
3837 {
39- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 5 , 1 ) ) ;
38+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 5 , 1 ) ) ;
4039 }
4140
4241 [ TestMethod ]
4342 public void Ctor_StartIndexNegative_ThrowsArgumentOutOfRangeException ( )
4443 {
45- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , - 1 , 1 ) ) ;
44+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , - 1 , 1 ) ) ;
4645 }
4746
4847 [ TestMethod ]
4948 public void Ctor_LengthTooBig_ThrowsArgumentOutOfRangeException ( )
5049 {
51- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 1 , 5 ) ) ;
50+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 1 , 5 ) ) ;
5251 }
5352
5453 [ TestMethod ]
5554 public void Ctor_LengthPlusOffsetCauseIntOverflow_ThrowsArgumentOutOfRangeException ( )
5655 {
57- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 1 , int . MaxValue ) ) ;
56+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 1 , int . MaxValue ) ) ;
5857 }
5958
6059 [ TestMethod ]
6160 public void Ctor_LengthNegative_ThrowsArgumentOutOfRangeException ( )
6261 {
63- Assert . Throws ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 0 , - 1 ) ) ;
62+ Assert . ThrowsException ( typeof ( ArgumentOutOfRangeException ) , ( ) => new ByteArrayContent ( new byte [ 5 ] , 0 , - 1 ) ) ;
6463 }
6564
66- // TODO need to fix processing of exception
67- //[TestMethod]
68- //public void ContentLength_UseWholeSourceArray_LengthMatchesArrayLength()
69- //{
70- // var contentData = new byte[10];
71- // var content = new ByteArrayContent(contentData);
72-
73- // Assert.Equal(contentData.Length, content.Headers.ContentLength);
74- //}
75-
76- // TODO need to fix processing of exception
77- //[TestMethod]
78- //public void ContentLength_UsePartialSourceArray_LengthMatchesArrayLength()
79- //{
80- // Assert.SkipTest("Test disabled on API failure");
65+ [ TestMethod ]
66+ public void ContentLength_UseWholeSourceArray_LengthMatchesArrayLength ( )
67+ {
68+ var contentData = new byte [ 10 ] ;
69+ var content = new ByteArrayContent ( contentData ) ;
8170
82- // // TODO need to fix edge case in ByteArrayContent
71+ Assert . AreEqual ( contentData . Length , content . Headers . ContentLength ) ;
72+ }
8373
84- // var contentData = new byte[10];
85- // var content = new ByteArrayContent(contentData, 5, 3);
74+ [ TestMethod ]
75+ public void ContentLength_UsePartialSourceArray_LengthMatchesArrayLength ( )
76+ {
77+ var contentData = new byte [ 10 ] ;
78+ var content = new ByteArrayContent ( contentData , 5 , 3 ) ;
8679
87- // Assert.Equal (3, content.Headers.ContentLength);
88- // }
80+ Assert . AreEqual ( 3 , content . Headers . ContentLength ) ;
81+ }
8982
9083 [ TestMethod ]
9184 public void ReadAsStreamAsync_EmptySourceArray_Succeed ( )
9285 {
9386 var content = new ByteArrayContent ( new byte [ 0 ] ) ;
9487 Stream stream = content . ReadAsStream ( ) ;
95- Assert . Equal ( 0 , stream . Length ) ;
88+ Assert . AreEqual ( 0 , stream . Length ) ;
9689 }
9790
98- // TODO need to fix processing of exception
99- //[TestMethod]
100- //public void ReadAsStream_Call_MemoryStreamWrappingByteArrayReturned()
101- //{
102- // Assert.SkipTest("Test disabled on API failure");
91+ [ TestMethod ]
92+ public void ReadAsStream_Call_MemoryStreamWrappingByteArrayReturned ( )
93+ {
94+ Assert . SkipTest ( "Read only MemoryStream not implemented yet" ) ;
10395
104- // // TODO need to fix edge case in stream reader
96+ // TODO need to fix edge case in stream reader
97+ // (stream reader does not have read only stream properly implemented)
10598
106- // var contentData = new byte[10];
107- // var content = new MockByteArrayContent(contentData, 5, 3);
99+ var contentData = new byte [ 10 ] ;
100+ var content = new MockByteArrayContent ( contentData , 5 , 3 ) ;
108101
109- // Stream stream = content.ReadAsStream();
110- // Assert.False (stream.CanWrite);
111- // Assert.Equal (3, stream.Length);
112- // Assert.Equal (0, content.CopyToCount);
113- // }
102+ Stream stream = content . ReadAsStream ( ) ;
103+ Assert . IsFalse ( stream . CanWrite ) ;
104+ Assert . AreEqual ( 3 , stream . Length ) ;
105+ Assert . AreEqual ( 0 , content . CopyToCount ) ;
106+ }
114107
115- // TODO need to fix processing of exception
116- //[TestMethod]
117- //public void CopyTo_NullDestination_ThrowsArgumentNullException()
118- //{
119- // byte[] contentData = CreateSourceArray();
120- // var content = new ByteArrayContent(contentData);
108+ [ TestMethod ]
109+ public void CopyTo_NullDestination_ThrowsArgumentNullException ( )
110+ {
111+ byte [ ] contentData = CreateSourceArray ( ) ;
112+ var content = new ByteArrayContent ( contentData ) ;
121113
122- // Assert.Throws (typeof(ArgumentNullException),
123- // () =>
124- // {
125- // content.CopyTo(null);
126- // });
127- // }
114+ Assert . ThrowsException ( typeof ( ArgumentNullException ) ,
115+ ( ) =>
116+ {
117+ content . CopyTo ( null ) ;
118+ } ) ;
119+ }
128120
129121 [ TestMethod ]
130122 public void CopyTo_UseWholeSourceArray_WholeContentCopied ( )
@@ -135,7 +127,7 @@ public void CopyTo_UseWholeSourceArray_WholeContentCopied()
135127 var destination = new MemoryStream ( ) ;
136128 content . CopyTo ( destination ) ;
137129
138- Assert . Equal ( contentData . Length , destination . Length ) ;
130+ Assert . AreEqual ( contentData . Length , destination . Length ) ;
139131 CheckResult ( destination , 0 ) ;
140132 }
141133
@@ -148,22 +140,21 @@ public void CopyTo_UsePartialSourceArray_PartialContentCopied()
148140 var destination = new MemoryStream ( ) ;
149141 content . CopyTo ( destination ) ;
150142
151- Assert . Equal ( 5 , destination . Length ) ;
143+ Assert . AreEqual ( 5 , destination . Length ) ;
152144 CheckResult ( destination , 3 ) ;
153145 }
154146
155- // TODO need to fix processing of exception
156- //[TestMethod]
157- //public void CopyTo_UseEmptySourceArray_NothingCopied()
158- //{
159- // var contentData = new byte[0];
160- // var content = new ByteArrayContent(contentData, 0, 0);
147+ [ TestMethod ]
148+ public void CopyTo_UseEmptySourceArray_NothingCopied ( )
149+ {
150+ var contentData = new byte [ 0 ] ;
151+ var content = new ByteArrayContent ( contentData , 0 , 0 ) ;
161152
162- // var destination = new MemoryStream();
163- // content.CopyTo(destination);
153+ var destination = new MemoryStream ( ) ;
154+ content . CopyTo ( destination ) ;
164155
165- // Assert.Equal (0, destination.Length);
166- // }
156+ Assert . AreEqual ( 0 , destination . Length ) ;
157+ }
167158
168159 #region Helper methods
169160
@@ -183,12 +174,12 @@ private static void CheckResult(Stream destination, byte firstValue)
183174 var destinationData = new byte [ destination . Length ] ;
184175 int read = destination . Read ( destinationData , 0 , destinationData . Length ) ;
185176
186- Assert . Equal ( destinationData . Length , read ) ;
187- Assert . Equal ( firstValue , destinationData [ 0 ] ) ;
177+ Assert . AreEqual ( destinationData . Length , read ) ;
178+ Assert . AreEqual ( firstValue , destinationData [ 0 ] ) ;
188179
189180 for ( int i = 1 ; i < read ; i ++ )
190181 {
191- Assert . True ( ( destinationData [ i ] == ( destinationData [ i - 1 ] + 1 ) ) ||
182+ Assert . IsTrue ( ( destinationData [ i ] == ( destinationData [ i - 1 ] + 1 ) ) ||
192183 ( ( destinationData [ i ] == 0 ) && ( destinationData [ i - 1 ] != 0 ) ) ) ;
193184 }
194185 }
0 commit comments