public void Base64Stream_EncodeString_WithVeryLongString_ShouldEncodeProperly() { var writeStateInfo = new Base64WriteStateInfo(10, new byte[0], new byte[0], 70, 0); var s = new Base64Stream(writeStateInfo); s.EncodeString(LongString, Encoding.UTF8); string encodedString = s.GetEncodedString(); byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(LongString, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
public void Base64Stream_WithVeryLongString_ShouldEncodeProperly() { var writeStateInfo = new Base64WriteStateInfo(10, new byte[0], new byte[0], 70, 0); var s = new Base64Stream(writeStateInfo); byte[] buffer = Encoding.UTF8.GetBytes(LongString); s.EncodeBytes(buffer, 0, buffer.Length); string encodedString = s.GetEncodedString(); byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(LongString, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
public void Base64Stream_WithBasicAsciiString_ShouldEncodeAndDecode(string testHeader) { var s = new Base64Stream(new Base64WriteStateInfo()); var testHeaderBytes = Encoding.UTF8.GetBytes(testHeader); s.EncodeBytes(testHeaderBytes, 0, testHeaderBytes.Length); string encodedString = s.GetEncodedString(); for (int i = 0; i < encodedString.Length; i++) { Assert.InRange((byte)encodedString[i], 0, 127); } byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(testHeader, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
public void Base64Stream_EncodeString_WithVerySmallBuffer_ShouldTriggerBufferResize_AndShouldEncodeProperly() { var s = new Base64Stream(new Base64WriteStateInfo(10, new byte[0], new byte[0], 70, 0)); const string TestString = "0123456789abcdef"; s.EncodeString(TestString, Encoding.UTF8); string encodedString = s.GetEncodedString(); Assert.Equal("MDEyMzQ1Njc4OWFiY2RlZg==", encodedString); byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(TestString, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
public void Base64Stream_WithVerySmallBuffer_ShouldTriggerBufferResize_AndShouldEncodeProperly() { var s = new Base64Stream(new Base64WriteStateInfo(10, new byte[0], new byte[0], 70, 0)); const string TestString = "0123456789abcdef"; byte[] buffer = Encoding.UTF8.GetBytes(TestString); s.EncodeBytes(buffer, 0, buffer.Length); string encodedString = s.GetEncodedString(); Assert.Equal("MDEyMzQ1Njc4OWFiY2RlZg==", encodedString); byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(TestString, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
public void Base64Stream_EncodeString_WithBasicAsciiString_ShouldEncodeAndDecode(string testHeader) { var s = new Base64Stream(new Base64WriteStateInfo()); s.EncodeString(testHeader, Encoding.UTF8); string encodedString = s.GetEncodedString(); for (int i = 0; i < encodedString.Length; i++) { Assert.InRange((byte)encodedString[i], 0, 127); } byte[] stringToDecode = Encoding.ASCII.GetBytes(encodedString); int result = s.DecodeBytes(stringToDecode, 0, encodedString.Length); Assert.Equal(testHeader, Encoding.UTF8.GetString(stringToDecode, 0, result)); }
private bool CompleteRead(IAsyncResult result) { _read = _parent.BaseStream.EndRead(result); // if the underlying stream returns 0 then there // is no more data - ust return 0. if (_read == 0) { InvokeCallback(); return(true); } // while decoding, we may end up not having // any bytes to return pending additional data // from the underlying stream. _read = _parent.DecodeBytes(_buffer, _offset, _read); if (_read > 0) { InvokeCallback(); return(true); } return(false); }