本文整理汇总了C#中TestStream类的典型用法代码示例。如果您正苦于以下问题:C# TestStream类的具体用法?C# TestStream怎么用?C# TestStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TestStream类属于命名空间,在下文中一共展示了TestStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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() == "");
}
开发者ID:xerxesb,项目名称:ironruby,代码行数:35,代码来源:IoTests.cs
示例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);
}
开发者ID:artwhaley,项目名称:krpc,代码行数:25,代码来源:StreamServerTest.cs
示例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);
}
开发者ID:paperclip,项目名称:krpc,代码行数:27,代码来源:RPCStreamTest.cs
示例4: Empty
public void Empty()
{
var stream = new TestStream (new MemoryStream (), null);
var rpcStream = new RPCStream (stream);
Assert.IsFalse (rpcStream.DataAvailable);
//rpcStream.Read ();
}
开发者ID:602p,项目名称:krpc,代码行数:7,代码来源:RPCStreamTest.cs
示例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));
}
开发者ID:paperclip,项目名称:krpc,代码行数:29,代码来源:RPCServerTest.cs
示例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();
}
开发者ID:mandrolic,项目名称:pymavlink,代码行数:8,代码来源:DataLinkSendTests.cs
示例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);
}
开发者ID:artwhaley,项目名称:krpc,代码行数:9,代码来源:RPCStreamTest.cs
示例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);
}
}
开发者ID:stukalin,项目名称:ImageResizer,代码行数:9,代码来源:SeekableStreamWrapperTests.cs
示例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);
}
开发者ID:602p,项目名称:krpc,代码行数:10,代码来源:RPCStreamTest.cs
示例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);
}
开发者ID:paperclip,项目名称:krpc,代码行数:10,代码来源:RPCStreamTest.cs
示例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);
}
}
开发者ID:stukalin,项目名称:ImageResizer,代码行数:11,代码来源:SeekableStreamWrapperTests.cs
示例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);
}
}
开发者ID:tmr232,项目名称:symblr,代码行数:11,代码来源:Pdb70SymbolMetadataProviderFixtures.cs
示例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);
}
}
开发者ID:tmr232,项目名称:symblr,代码行数:11,代码来源:FallbackSymbolsMetadataProviderFixtures.cs
示例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);
}
}
开发者ID:tmr232,项目名称:symblr,代码行数:14,代码来源:MZMetadataFixtures.cs
示例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);
}
开发者ID:paperclip,项目名称:krpc,代码行数:18,代码来源:RPCStreamTest.cs
示例16: File_AppendBytes1
public void File_AppendBytes1()
{
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 RubyBufferedStream(stream);
Assert(io.PeekByte() == (byte)'a');
var buffer = MutableString.CreateBinary(B("foo:"));
Assert(io.AppendBytes(buffer, 4, false) == 4);
Assert(buffer.ToString() == "foo:ab\r\n");
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 1, false) == 1);
Assert(buffer.ToString() == "e");
buffer = MutableString.CreateMutable("x:", RubyEncoding.Binary);
int c = s.Length - s_crlf_count - 2;
Assert(io.AppendBytes(buffer, c, false) == c);
Assert(buffer.ToString() == "x:" + s.Replace(crlf, "\n").Substring(0, c));
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 10, false) == 4);
Assert(buffer.ToString() == "st\n!");
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, 10, false) == 0);
Assert(buffer.ToString() == "");
stream = new TestStream(false, B(s = "abcd" + crlf + "xyz" + crlf + "qqq;"));
io = new RubyBufferedStream(stream);
buffer = MutableString.CreateBinary();
Assert(io.AppendBytes(buffer, Int32.MaxValue, true) == s.Length);
io.BaseStream.Seek(0, SeekOrigin.Begin);
Assert(io.AppendBytes(buffer, Int32.MaxValue, false) == s.Length - 2);
Assert(buffer.ToString() == s + s.Replace(crlf, "\n"));
}
开发者ID:TerabyteX,项目名称:main,代码行数:43,代码来源:IoTests.cs
示例17: When_reading_a_file_with_source_server_information
public async Task When_reading_a_file_with_source_server_information()
{
var sut = new Pdb70SymbolMetadataProvider();
var ms = new MemoryStream();
var stream = new TestStream(ms);
await stream.WriteAsync(Pdbs.RealSrcSrv, 0, Pdbs.RealSrcSrv.Length);
stream.Position = 0;
using (var metadata = await sut.TryGetSymbolMetadataAsync(stream))
{
Assert.NotNull(metadata);
Assert.True(metadata.SupportsSourceServerInformation);
Assert.Equal("63ba9bb5992dfc429f6bcc52135dbb092", metadata.Identifier);
Assert.True(metadata.HasSourceServerInformation);
Assert.Equal(581, metadata.SourceInformation.Count);
Assert.False(metadata.SourceInformation.Any(x => string.IsNullOrEmpty(x.TargetPath)));
}
}
开发者ID:tmr232,项目名称:symblr,代码行数:19,代码来源:Pdb70SymbolMetadataProviderFixtures.cs
示例18: When_reading_a_PDB_with_no_source_server_stream
public async Task When_reading_a_PDB_with_no_source_server_stream()
{
var stream = new TestStream(Pdbs.NoSrcSrv);
using (var file = await Pdb70File.TryOpenAsync(stream))
{
Assert.Equal(1, file.Age);
Assert.Equal(0x555CE245, file.Signature);
Assert.Equal(20000404, file.Version);
Assert.Equal(Guid.Parse("{b59bba63-2d99-42fc-9f6b-cc52135dbb09}"), file.Guid);
Assert.False(file.StreamExists("SRCSRV"));
Assert.True(file.StreamExists(1));
Assert.True(file.StreamNames.Any(x => x.StartsWith("/src/files/")));
Assert.True(file.StreamNames.Any(x => x.StartsWith("/LinkInfo")));
}
Assert.True(stream.IsDisposed);
Assert.True(stream.DidRead);
Assert.False(stream.DidWrite);
}
开发者ID:tmr232,项目名称:symblr,代码行数:19,代码来源:Pdb70FileFixtures.cs
示例19: InvalidHelloMessageIdentifier
public void InvalidHelloMessageIdentifier()
{
helloMessage [15] = 0x00;
var stream = new TestStream (new MemoryStream (helloMessage));
// 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 RPCServer (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);
}
开发者ID:BasConijn,项目名称:krpc,代码行数:23,代码来源:RPCServerTest.cs
示例20: When_writing_to_a_PDB_with_no_source_server_stream
public async Task When_writing_to_a_PDB_with_no_source_server_stream()
{
var longString = new StringBuilder();
for (var i = 0; i < 1000; i++)
longString.AppendFormat("Line {0}", i).AppendLine();
var ms = new MemoryStream();
var stream = new TestStream(ms);
await stream.WriteAsync(Pdbs.NoSrcSrv, 0, Pdbs.NoSrcSrv.Length);
stream.Position = 0;
using (var file = await Pdb70File.TryOpenAsync(stream))
{
using (var srcsrv = file.GetStream("SRCSRV"))
using (var writer = new StreamWriter(srcsrv))
{
await writer.WriteAsync(longString.ToString());
await writer.FlushAsync();
}
await file.SaveAsync();
stream = new TestStream(ms.ToArray());
stream.Position = 0;
}
using (var file = await Pdb70File.TryOpenAsync(stream))
{
using (var srcsrv = file.GetStream("SRCSRV"))
using (var reader = new StreamReader(srcsrv))
{
var data = await reader.ReadToEndAsync();
Assert.Equal(longString.ToString(), data);
}
}
}
开发者ID:tmr232,项目名称:symblr,代码行数:36,代码来源:Pdb70FileFixtures.cs
注:本文中的TestStream类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论