예제 #1
0
        public async Task ReadMessageStreamAsync_MultipleEmptyMessage_ReturnNoDataMessageThenComplete()
        {
            // Arrange
            var emptyMessage = new byte[]
            {
                0x00,     // compression = 0
                0x00,
                0x00,
                0x00,
                0x00     // length = 0
            };
            var ms = new MemoryStream(emptyMessage.Concat(emptyMessage).ToArray());

            var pipeReader = new StreamPipeReader(ms);

            // Act 1
            var messageData1 = await pipeReader.ReadStreamMessageAsync(TestServerCallContext);

            // Assert 1
            Assert.AreEqual(0, messageData1 !.Length);

            // Act 2
            var messageData2 = await pipeReader.ReadStreamMessageAsync(TestServerCallContext);

            // Assert 2
            Assert.AreEqual(0, messageData2 !.Length);

            // Act 3
            var messageData3 = await pipeReader.ReadStreamMessageAsync(TestServerCallContext);

            // Assert 3
            Assert.IsNull(messageData3);
        }
예제 #2
0
        public async Task ReadMessageStreamAsync_LongMessage_ReturnData()
        {
            // Arrange
            var content = Encoding.UTF8.GetBytes("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam varius nibh a blandit mollis. "
                                                 + "In hac habitasse platea dictumst. Proin non quam nec neque convallis commodo. Orci varius natoque penatibus et magnis dis "
                                                 + "parturient montes, nascetur ridiculus mus. Mauris commodo est vehicula, semper arcu eu, ornare urna. Mauris malesuada nisl "
                                                 + "nisl, vitae tincidunt purus vestibulum sit amet. Interdum et malesuada fames ac ante ipsum primis in faucibus.");

            var ms = new MemoryStream(new byte[]
            {
                0x00,     // compression = 0
                0x00,
                0x00,
                0x01,
                0xC1     // length = 449
            }.Concat(content).ToArray());

            var pipeReader = new StreamPipeReader(ms);

            // Act
            var messageData = await pipeReader.ReadStreamMessageAsync(TestServerCallContext);

            // Assert
            Assert.AreEqual(449, messageData !.Length);
            CollectionAssert.AreEqual(content, messageData);
        }
예제 #3
0
        public static async Task <T> AssertReadMessageStreamAsync <T>(Stream stream) where T : IMessage, new()
        {
            var pipeReader = new StreamPipeReader(stream);

            var messageData = await pipeReader.ReadStreamMessageAsync();

            if (messageData == null)
            {
                return(default);
예제 #4
0
        public void ReadMessageStreamAsync_MessageDataIncomplete_ThrowError()
        {
            // Arrange
            var ms = new MemoryStream(new byte[]
            {
                0x00,     // compression = 0
                0x00,
                0x00,
                0x00,
                0x02,     // length = 2
                0x10
            });

            var pipeReader = new StreamPipeReader(ms);

            // Act
            var ex = Assert.ThrowsAsync <InvalidDataException>(
                () => pipeReader.ReadStreamMessageAsync().AsTask());

            // Assert
            Assert.AreEqual("Incomplete message.", ex.Message);
        }
예제 #5
0
        public void ReadMessageStreamAsync_MessageDataIncomplete_ThrowError()
        {
            // Arrange
            var ms = new MemoryStream(new byte[]
            {
                0x00,     // compression = 0
                0x00,
                0x00,
                0x00,
                0x02,     // length = 2
                0x10
            });

            var pipeReader = new StreamPipeReader(ms);

            // Act
            var ex = Assert.ThrowsAsync <RpcException>(
                () => pipeReader.ReadStreamMessageAsync(TestServerCallContext).AsTask());

            // Assert
            Assert.AreEqual("Incomplete message.", ex.Status.Detail);
            Assert.AreEqual(StatusCode.Internal, ex.StatusCode);
        }