public async Task WriteAsync_VeryLargeData_Written() { // Arrange var ms = new MemoryStream(); var gprcWebStream = new Base64RequestStream(ms); var s = string.Create <object>(16384, null !, (s, o) => { for (var i = 0; i < s.Length; i++) { s[i] = Convert.ToChar(i % 10); } }); var data = Encoding.UTF8.GetBytes(s); // Act await gprcWebStream.WriteAsync(data); await gprcWebStream.FlushAsync(); // Assert var base64 = Encoding.UTF8.GetString(ms.ToArray()); var result = Convert.FromBase64String(base64); CollectionAssert.AreEqual(data, result); }
public async Task WriteAsync_VeryLargeData_Written() { // Arrange var ms = new MemoryStream(); var gprcWebStream = new Base64RequestStream(ms); var chars = new char[16384]; for (var i = 0; i < chars.Length; i++) { chars[i] = Convert.ToChar(i % 10); } var data = Encoding.UTF8.GetBytes(new string(chars)); // Act await WriteAsync(gprcWebStream, data).DefaultTimeout(); await gprcWebStream.FlushAsync().DefaultTimeout(); // Assert var base64 = Encoding.UTF8.GetString(ms.ToArray()); var result = Convert.FromBase64String(base64); CollectionAssert.AreEqual(data, result); }
public async Task FlushAsync_HasRemainder_WriteRemainder() { // Arrange var ms = new MemoryStream(); var gprcWebStream = new Base64RequestStream(ms); var data = Encoding.UTF8.GetBytes("Hello world"); // Act await gprcWebStream.WriteAsync(data); await gprcWebStream.FlushAsync(); // Assert var base64 = Encoding.UTF8.GetString(ms.ToArray()); CollectionAssert.AreEqual(data, Convert.FromBase64String(base64)); }