public async Task WriteMessageAsync_MultipleMessagesWithFlush_WriteMessagesAsSegments() { // Arrange var ms = new MemoryStream(); var pipeWriter = new Base64PipeWriter(PipeWriter.Create(ms)); // Act await pipeWriter.WriteMessageAsync(new EchoRequest { Message = "test" }, HttpContextServerCallContextHelper.CreateServerCallContext(), MarshallerEchoRequest.ContextualSerializer, canFlush : true); await pipeWriter.WriteMessageAsync(new EchoRequest { Message = "test" }, HttpContextServerCallContextHelper.CreateServerCallContext(), MarshallerEchoRequest.ContextualSerializer, canFlush : true); await pipeWriter.WriteMessageAsync(new EchoRequest { Message = "test" }, HttpContextServerCallContextHelper.CreateServerCallContext(), MarshallerEchoRequest.ContextualSerializer, canFlush : true); // Assert var base64 = Encoding.UTF8.GetString(ms.ToArray()); Assert.AreEqual("AAAAAAYKBHRlc3Q=AAAAAAYKBHRlc3Q=AAAAAAYKBHRlc3Q=", base64); }
public async Task WriteMessageAsync_NoFlush_WriteNoData() { // Arrange var ms = new MemoryStream(); var pipeWriter = new Base64PipeWriter(PipeWriter.Create(ms)); // Act await pipeWriter.WriteMessageAsync(new EchoRequest { Message = "test" }, HttpContextServerCallContextHelper.CreateServerCallContext(), MarshallerEchoRequest.ContextualSerializer, canFlush : false); // Assert var messageData = ms.ToArray(); Assert.AreEqual(0, messageData.Length); }
public async Task WriteMessageAsync_EmptyMessage_WriteMessageWithNoData() { // Arrange var ms = new MemoryStream(); var pipeWriter = new Base64PipeWriter(PipeWriter.Create(ms)); // Act await pipeWriter.WriteMessageAsync(new EchoRequest(), HttpContextServerCallContextHelper.CreateServerCallContext(), MarshallerEchoRequest.ContextualSerializer, canFlush : true); // Assert var base64 = Encoding.UTF8.GetString(ms.ToArray()); var messageData = Convert.FromBase64String(base64); CollectionAssert.AreEqual( new byte[] { 0x00, // compression = 0 0x00, 0x00, 0x00, 0x00, // length = 0 }, messageData); }