Пример #1
0
        public void WriteTrailers_InvalidHeaderValue_Error()
        {
            // Arrange
            var trailers = new HeaderDictionary();

            trailers.Add("one", "two:" + (char)127);
            var output = new ArrayBufferWriter <byte>();

            // Act
            var ex = Assert.Throws <InvalidOperationException>(() => GrpcWebProtocolHelpers.WriteTrailers(trailers, output));

            // Assert
            Assert.AreEqual("Invalid non-ASCII or control character in header: 0x007F", ex.Message);
        }
Пример #2
0
        public void WriteTrailers_NoTrailers_WrittenToOutput()
        {
            // Arrange
            var trailers = new HeaderDictionary();
            var output   = new ArrayBufferWriter <byte>();

            // Act
            GrpcWebProtocolHelpers.WriteTrailers(trailers, output);

            // Assert
            Assert.AreEqual(5, output.WrittenSpan.Length);

            Assert.AreEqual(128, output.WrittenSpan[0]);
            Assert.AreEqual(0, output.WrittenSpan[1]);
            Assert.AreEqual(0, output.WrittenSpan[2]);
            Assert.AreEqual(0, output.WrittenSpan[3]);
            Assert.AreEqual(0, output.WrittenSpan[4]);
        }
Пример #3
0
        public void WriteTrailers_OneTrailerMixedCase_WrittenToOutputLowerCase()
        {
            // Arrange
            var trailers = new HeaderDictionary();

            trailers.Add("One", "Two");
            var output = new ArrayBufferWriter <byte>();

            // Act
            GrpcWebProtocolHelpers.WriteTrailers(trailers, output);

            // Assert
            Assert.AreEqual(15, output.WrittenSpan.Length);

            Assert.AreEqual(128, output.WrittenSpan[0]);
            Assert.AreEqual(0, output.WrittenSpan[1]);
            Assert.AreEqual(0, output.WrittenSpan[2]);
            Assert.AreEqual(0, output.WrittenSpan[3]);
            Assert.AreEqual(10, output.WrittenSpan[4]);

            var text = Encoding.ASCII.GetString(output.WrittenSpan.Slice(5));

            Assert.AreEqual("one: Two\r\n", text);
        }
Пример #4
0
        public void WriteTrailers_MultiValueTrailer_WrittenToOutput()
        {
            // Arrange
            var trailers = new HeaderDictionary();

            trailers.Add("one", new StringValues(new[] { "two", "three" }));
            var output = new ArrayBufferWriter <byte>();

            // Act
            GrpcWebProtocolHelpers.WriteTrailers(trailers, output);

            // Assert
            Assert.AreEqual(27, output.WrittenSpan.Length);

            Assert.AreEqual(128, output.WrittenSpan[0]);
            Assert.AreEqual(0, output.WrittenSpan[1]);
            Assert.AreEqual(0, output.WrittenSpan[2]);
            Assert.AreEqual(0, output.WrittenSpan[3]);
            Assert.AreEqual(22, output.WrittenSpan[4]);

            var text = Encoding.ASCII.GetString(output.WrittenSpan.Slice(5));

            Assert.AreEqual("one: two\r\none: three\r\n", text);
        }