aspnetcore/test/Microsoft.AspNet.Server.Kes.../TestInput.cs

82 lines
2.1 KiB
C#

// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNet.Server.Kestrel.Http;
namespace Microsoft.AspNet.Server.KestrelTests
{
class TestInput : IConnectionControl, IFrameControl
{
public TestInput()
{
var memory = new MemoryPool();
var memory2 = new MemoryPool2();
FrameContext = new FrameContext
{
SocketInput = new SocketInput(memory2),
Memory = memory,
ConnectionControl = this,
FrameControl = this
};
}
public FrameContext FrameContext { get; set; }
public void Add(string text, bool fin = false)
{
var encoding = System.Text.Encoding.ASCII;
var count = encoding.GetByteCount(text);
var buffer = FrameContext.SocketInput.IncomingStart(text.Length);
count = encoding.GetBytes(text, 0, text.Length, buffer.Data.Array, buffer.Data.Offset);
FrameContext.SocketInput.IncomingComplete(count, null);
if (fin)
{
FrameContext.SocketInput.RemoteIntakeFin = true;
}
}
public void ProduceContinue()
{
}
public void Pause()
{
}
public void Resume()
{
}
public void Write(ArraySegment<byte> data, Action<Exception, object> callback, object state)
{
}
public void End(ProduceEndType endType)
{
}
void IFrameControl.ProduceContinue()
{
}
void IFrameControl.Write(ArraySegment<byte> data)
{
}
async Task IFrameControl.WriteAsync(ArraySegment<byte> data, CancellationToken cancellationToken)
{
}
void IFrameControl.Flush()
{
}
async Task IFrameControl.FlushAsync(CancellationToken cancellationToken)
{
}
}
}