本文整理汇总了C#中TestStream类的典型用法代码示例。如果您正苦于以下问题:C# TestStream类的具体用法?C# TestStream怎么用?C# TestStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestStream类属于命名空间,在下文中一共展示了TestStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test_Read1
private void Test_Read1() {
string s;
string crlf = "\r\n";
var stream = new TestStream(false, B(
"ab\r\r\n" +
"e" + (s = "fgh" + crlf + "ijkl" + crlf + "mnop" + crlf + crlf + crlf + crlf + "qrst") +
crlf + "!"
));
int s_crlf_count = 6;
var io = new RubyIO(Context, stream, "r");
Assert(io.PeekByte() == (byte)'a');
var buffer = MutableString.CreateBinary(B("foo:"));
Assert(io.AppendBytes(buffer, 4) == 4);
Assert(buffer.ToString() == "foo:ab\r\n");
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 1) == 1);
Assert(buffer.ToString() == "e");
buffer = MutableString.CreateMutable("x:");
int c = s.Length - s_crlf_count - 2;
Assert(io.AppendBytes(buffer, c) == c);
Assert(buffer.ToString() == "x:" + s.Replace(crlf, "\n").Substring(0, c));
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 10) == 4);
Assert(buffer.ToString() == "st\n!");
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 10) == 0);
Assert(buffer.ToString() == "");
}
示例2: NoHelloMessage
public void NoHelloMessage()
{
var responseStream = new MemoryStream ();
var stream = new TestStream (new MemoryStream (), responseStream);
// Create mock byte server and client
var mockByteServer = new Mock<IServer<byte,byte>> ();
var byteServer = mockByteServer.Object;
var mockByteClient = new Mock<IClient<byte,byte>> ();
mockByteClient.Setup (x => x.Stream).Returns (stream);
var byteClient = mockByteClient.Object;
var server = new StreamServer (byteServer);
server.OnClientRequestingConnection += (sender, e) => e.Request.Allow ();
server.Start ();
// Fire a client connection event
var eventArgs = new ClientRequestingConnectionArgs<byte,byte> (byteClient);
mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs);
Assert.IsFalse (eventArgs.Request.ShouldAllow);
Assert.IsTrue (eventArgs.Request.ShouldDeny);
Assert.AreEqual (0, responseStream.Length);
}
示例3: ReadMultipleRequests
public void ReadMultipleRequests ()
{
var multipleRequestBytes = new byte [requestBytes.Length * 5];
for (int i = 0; i < 5; i++)
Array.Copy (requestBytes, 0, multipleRequestBytes, i * requestBytes.Length, requestBytes.Length);
var byteStream = new TestStream (multipleRequestBytes);
var rpcStream = new RPCStream (byteStream);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (0, rpcStream.BytesRead);
for (int i = 0; i < 5; i++) {
Assert.IsTrue (rpcStream.DataAvailable);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (multipleRequestBytes.Length, rpcStream.BytesRead);
Request request = rpcStream.Read ();
if (i < 4)
Assert.IsTrue (rpcStream.DataAvailable);
else {
Assert.IsFalse (rpcStream.DataAvailable);
Assert.Throws<KRPC.Server.Message.NoRequestException> (() => rpcStream.Read ());
}
Assert.AreEqual (expectedRequest.Service, request.Service);
Assert.AreEqual (expectedRequest.Procedure, request.Procedure);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (multipleRequestBytes.Length, rpcStream.BytesRead);
}
Assert.IsFalse (byteStream.Closed);
}
示例4: Empty
public void Empty()
{
var stream = new TestStream (new MemoryStream (), null);
var rpcStream = new RPCStream (stream);
Assert.IsFalse (rpcStream.DataAvailable);
//rpcStream.Read ();
}
示例5: ValidHelloMessage
public void ValidHelloMessage ()
{
var responseStream = new MemoryStream ();
var stream = new TestStream (new MemoryStream (helloMessage), responseStream);
// Create mock byte server and client
var mockByteServer = new Mock<IServer<byte,byte>> ();
var byteServer = mockByteServer.Object;
var byteClient = new TestClient (stream);
var server = new RPCServer (byteServer);
server.OnClientRequestingConnection += (sender, e) => e.Request.Allow ();
server.Start ();
// Fire a client connection event
var eventArgs = new ClientRequestingConnectionEventArgs<byte,byte> (byteClient);
mockByteServer.Raise (m => m.OnClientRequestingConnection += null, eventArgs);
Assert.IsTrue (eventArgs.Request.ShouldAllow);
Assert.IsFalse (eventArgs.Request.ShouldDeny);
server.Update ();
Assert.AreEqual (1, server.Clients.Count ());
Assert.AreEqual ("Jebediah Kerman!!!", server.Clients.First ().Name);
byte[] bytes = responseStream.ToArray ();
byte[] responseBytes = byteClient.Guid.ToByteArray ();
Assert.IsTrue (responseBytes.SequenceEqual (bytes));
}
示例6: Setup
public void Setup()
{
_testStream = new TestStream();
_dut = new Mavlink(_testStream);
_dut.PacketReceived += (sender, e) => _decodedPackets.Add(e);
_decodedPackets = new List<MavlinkPacket>();
_dut.Start();
}
示例7: Empty
public void Empty()
{
var stream = new TestStream (new MemoryStream (), null);
var rpcStream = new RPCStream (stream);
Assert.IsFalse (rpcStream.DataAvailable);
//rpcStream.Read ();
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (0, rpcStream.BytesRead);
}
示例8: DoesntWrapSeekableStream
public void DoesntWrapSeekableStream()
{
var s = new TestStream(true, "some data");
using (var actual = SeekableStreamWrapper.FromStream(s))
{
Assert.AreSame(s, actual);
Assert.IsTrue(actual.CanSeek);
}
}
示例9: ReadSingleRequest
public void ReadSingleRequest()
{
var stream = new TestStream (new MemoryStream (requestBytes), null);
var rpcStream = new RPCStream (stream);
Assert.IsTrue (rpcStream.DataAvailable);
Request request = rpcStream.Read ();
Assert.IsFalse (rpcStream.DataAvailable);
Assert.AreEqual (expectedRequest.Service, request.Service);
Assert.AreEqual (expectedRequest.Procedure, request.Procedure);
}
示例10: Empty
public void Empty ()
{
var byteStream = new TestStream (new MemoryStream ());
var rpcStream = new RPCStream (byteStream);
Assert.IsFalse (rpcStream.DataAvailable);
Assert.Throws<KRPC.Server.Message.NoRequestException> (() => rpcStream.Read ());
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (0, rpcStream.BytesRead);
Assert.IsFalse (byteStream.Closed);
}
示例11: WrapsNonSeekableStream
public void WrapsNonSeekableStream()
{
var s = new TestStream(false, "some data");
using (var actual = SeekableStreamWrapper.FromStream(s))
{
Assert.AreNotSame(s, actual);
Assert.IsInstanceOfType(typeof(SeekableStreamWrapper), actual);
Assert.IsTrue(actual.CanSeek);
Assert.IsFalse(actual.CanWrite);
}
}
示例12: When_reading_a_non_PDB
public async Task When_reading_a_non_PDB()
{
var sut = new Pdb70SymbolMetadataProvider();
var stream = new TestStream(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
using (var metadata = await sut.TryGetSymbolMetadataAsync(stream))
{
Assert.Null(metadata);
}
}
示例13: When_getting_the_metadata_for_unsupported_data
public async Task When_getting_the_metadata_for_unsupported_data()
{
var sut = new FallbackSymbolsMetadataProvider();
var stream = new TestStream(MZ.Exes.NuGet);
using (var file = await sut.TryGetSymbolMetadataAsync(stream, CancellationToken.None))
{
Assert.Equal("7f71c74f53a9138b31495107e33077d1", file.Identifier);
Assert.False(file.SupportsSourceServerInformation);
}
}
示例14: When_reading_NuGet_exe
public async Task When_reading_NuGet_exe()
{
var sut = new MZSymbolMetadataProvider();
// Authoritative identifiers can be calculated with:
// "C:\Program Files (x86)\Windows Kits\8.1\Debuggers\x64\symstore.exe" add /f NuGet.exe /s "C:\symbols" /t symblr
// Make sure the file is larger than 32k.
var stream = new TestStream(Exes.NuGet);
using (var file = await sut.TryGetSymbolMetadataAsync(stream, CancellationToken.None))
{
Assert.Equal("550953A8c000", file.Identifier);
Assert.False(file.SupportsSourceServerInformation);
}
}
示例15: ReadSingleRequest
public void ReadSingleRequest ()
{
var byteStream = new TestStream (requestBytes);
var rpcStream = new RPCStream (byteStream);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (0, rpcStream.BytesRead);
Assert.IsTrue (rpcStream.DataAvailable);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (requestBytes.Length, rpcStream.BytesRead);
Request request = rpcStream.Read ();
Assert.IsFalse (rpcStream.DataAvailable);
Assert.Throws<KRPC.Server.Message.NoRequestException> (() => rpcStream.Read ());
Assert.AreEqual (expectedRequest.Service, request.Service);
Assert.AreEqual (expectedRequest.Procedure, request.Procedure);
Assert.AreEqual (0, rpcStream.BytesWritten);
Assert.AreEqual (requestBytes.Length, rpcStream.BytesRead);
Assert.IsFalse (byteStream.Closed);
}