Пример #1
0
        public void TryInjectLiveReloadScript_NoBodyTag()
        {
            // Arrange
            var expected = "<p>Hello world</p>";
            var stream   = new MemoryStream();
            var input    = Encoding.UTF8.GetBytes(expected).AsSpan();

            // Act
            var result = ScriptInjection.TryInjectLiveReloadScript(stream, input);

            // Assert
            Assert.False(result);
            var output = Encoding.UTF8.GetString(stream.ToArray());

            Assert.Equal(expected, output);
        }
Пример #2
0
 public override void Write(ReadOnlySpan <byte> buffer)
 {
     OnWrite();
     if (IsHtmlResponse && !ScriptInjectionPerformed)
     {
         ScriptInjectionPerformed = WebSocketScriptInjection.TryInjectLiveReloadScript(_baseStream, buffer);
     }
     else
     {
         _baseStream.Write(buffer);
     }
 }
Пример #3
0
        public override void Write(byte[] buffer, int offset, int count)
        {
            OnWrite();

            if (IsHtmlResponse && !ScriptInjectionPerformed)
            {
                ScriptInjectionPerformed = WebSocketScriptInjection.TryInjectLiveReloadScript(_baseStream, buffer.AsSpan(offset, count));
            }
            else
            {
                _baseStream.Write(buffer, offset, count);
            }
        }
        public void TryInjectLiveReloadScript_WithOffset()
        {
            // Arrange
            var expected = $"</table>{WebSocketScriptInjection.InjectedScript}</body>";
            var stream   = new MemoryStream();
            var input    = Encoding.UTF8.GetBytes("unused</table></body>").AsSpan(6);

            // Act
            var result = WebSocketScriptInjection.TryInjectLiveReloadScript(stream, input);

            // Assert
            Assert.True(result);
            var output = Encoding.UTF8.GetString(stream.ToArray());

            Assert.Equal(expected, output);
        }