本文整理汇总了C#中SocketBufferFake类的典型用法代码示例。如果您正苦于以下问题:C# SocketBufferFake类的具体用法?C# SocketBufferFake怎么用?C# SocketBufferFake使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketBufferFake类属于命名空间,在下文中一共展示了SocketBufferFake类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: decode_two_messages
public void decode_two_messages()
{
var actual = new List<IHttpRequest>();
var buffer = new SocketBufferFake();
buffer.Buffer =
Encoding.ASCII.GetBytes(
@"PUT /?query HTTP/1.0
host: www.onetrueerror.com
content-length:13
hello queue aGET /?query HTTP/1.1
host: www.onetrueerror.com
content-length:14
hello queue aa");
buffer.BytesTransferred = buffer.Buffer.Length;
var decoder = new HttpMessageDecoder();
decoder.MessageReceived = o => actual.Add((IHttpRequest)o);
decoder.ProcessReadBytes(buffer);
actual.Count.Should().Be(2);
actual[1].HttpMethod.Should().Be("GET");
actual[1].HttpVersion.Should().Be("HTTP/1.1");
actual[1].Uri.ToString().Should().Be("http://www.onetrueerror.com/?query");
actual[1].Body.Should().NotBeNull();
actual[1].Body.Length.Should().Be(14);
actual[1].Headers["host"].Should().Be("www.onetrueerror.com");
actual[1].Headers["content-length"].Should().Be("14");
var sw = new StreamReader(actual[1].Body);
sw.ReadToEnd().Should().Be("hello queue aa");
}
示例2: request_with_a_multiline_header
public void request_with_a_multiline_header()
{
IHttpRequest actual = null;
var buffer = new SocketBufferFake();
buffer.Buffer =
Encoding.ASCII.GetBytes(@"GET / HTTP/1.1
host: www.onetrueerror.com
Content-Length: 0
Multi-part: header
which should be merged
");
buffer.BytesTransferred = buffer.Buffer.Length;
var decoder = new HttpMessageDecoder();
decoder.MessageReceived = o => actual = (IHttpRequest)o;
decoder.ProcessReadBytes(buffer);
actual.Should().NotBeNull();
actual.HttpMethod.Should().Be("GET");
actual.HttpVersion.Should().Be("HTTP/1.1");
actual.Uri.ToString().Should().Be("http://www.onetrueerror.com/");
actual.Headers["Multi-part"].Should().Be("header which should be merged");
actual.Headers["content-length"].Should().Be("0");
}
示例3: request_with_body
public void request_with_body()
{
IHttpRequest actual = null;
var buffer = new SocketBufferFake();
buffer.Buffer =
Encoding.ASCII.GetBytes(
@"PUT /?query HTTP/1.0
host: www.onetrueerror.com
content-length:13
hello queue a");
buffer.BytesTransferred = buffer.Buffer.Length;
var decoder = new HttpMessageDecoder();
decoder.MessageReceived = o => actual = (IHttpRequest)o;
decoder.ProcessReadBytes(buffer);
actual.Should().NotBeNull();
actual.HttpMethod.Should().Be("PUT");
actual.HttpVersion.Should().Be("HTTP/1.0");
actual.Uri.ToString().Should().Be("http://www.onetrueerror.com/?query");
actual.Body.Should().NotBeNull();
actual.Body.Length.Should().Be(13);
actual.Headers["host"].Should().Be("www.onetrueerror.com");
actual.Headers["content-length"].Should().Be("13");
var sw = new StreamReader(actual.Body);
sw.ReadToEnd().Should().Be("hello queue a");
}
示例4: complete_header_then_half_typename_then_full_message
public void complete_header_then_half_typename_then_full_message()
{
var args = new SocketBufferFake();
var body = "Hello world";
var type = body.GetType().AssemblyQualifiedName;
var serializer = new StringSerializer();
object actual = null;
BitConverter2.GetBytes(MicroMessageEncoder.FixedHeaderLength + type.Length, args.Buffer, 0); //header length
args.Buffer[2] = MicroMessageDecoder.Version;
BitConverter2.GetBytes(body.Length, args.Buffer, 3); //content lkength
args.Buffer[7] = (byte)(sbyte)type.Length; // type len
Encoding.ASCII.GetBytes(type, 0, type.Length, args.Buffer, HeaderLengthSize + MicroMessageEncoder.FixedHeaderLength); // type name
Encoding.ASCII.GetBytes(body, 0, body.Length, args.Buffer, HeaderLengthSize + type.Length + MicroMessageEncoder.FixedHeaderLength); //body
var sut = new MicroMessageDecoder(serializer);
sut.MessageReceived = o => actual = o;
args.BytesTransferred = sizeof(short) + MicroMessageDecoder.FixedHeaderLength;
sut.ProcessReadBytes(args);
args.Offset += args.BytesTransferred;
args.BytesTransferred = type.Length - 31;
sut.ProcessReadBytes(args);
args.Offset += args.BytesTransferred;
args.BytesTransferred = 31;
sut.ProcessReadBytes(args);
args.Offset += args.BytesTransferred;
args.BytesTransferred = body.Length;
sut.ProcessReadBytes(args);
actual.Should().NotBeNull();
actual.Should().Be("Hello world");
}
示例5: partial_header
public void partial_header()
{
var args = new SocketBufferFake();
var body = "Hello world";
var type = body.GetType().AssemblyQualifiedName;
var serializer = new StringSerializer();
object actual = null;
BitConverter2.GetBytes(MicroMessageEncoder.FixedHeaderLength + type.Length, args.Buffer, 0);
args.Buffer[2] = MicroMessageDecoder.Version;
BitConverter2.GetBytes(body.Length, args.Buffer, 3);
args.Buffer[7] = (byte)(sbyte)type.Length;
Encoding.ASCII.GetBytes(type, 0, type.Length, args.Buffer, HeaderLengthSize+MicroMessageEncoder.FixedHeaderLength);
Encoding.ASCII.GetBytes(body, 0, body.Length, args.Buffer, HeaderLengthSize+type.Length + MicroMessageEncoder.FixedHeaderLength);
var sut = new MicroMessageDecoder(serializer);
sut.MessageReceived = o => actual = o;
args.BytesTransferred = MicroMessageDecoder.FixedHeaderLength - 1;
sut.ProcessReadBytes(args);
args.Offset += args.BytesTransferred;
args.BytesTransferred = body.Length + type.Length + 1 + HeaderLengthSize;
sut.ProcessReadBytes(args);
actual.Should().NotBeNull();
actual.Should().Be("Hello world");
}
示例6: ParseHeader_SkipBody
public void ParseHeader_SkipBody()
{
const string HttpPost = @"POST / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Accept: */*
Referer: http://localhost:8080/ajaxPost.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sv,en;q=0.8,en-US;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF
hello=world";
string actual = "";
var slice = new SocketBufferFake();
var buffer = Encoding.UTF8.GetBytes(HttpPost);
slice.SetBuffer(buffer, 0, buffer.Length);
slice.BytesTransferred = buffer.Length;
var parser = new HeaderParser();
parser.HeaderParsed += (name, value) => actual = value;
slice.Offset = parser.Parse(slice, 0);
Assert.Equal("ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF", actual);
Assert.Equal('h', (char)slice.Buffer[slice.Offset]);
}
示例7: ParsePost
public void ParsePost()
{
const string HttpPost = @"POST / HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 11
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11
Content-Type: application/x-www-form-urlencoded; charset=UTF-32
Accept: */*
Referer: http://localhost:8080/ajaxPost.html
Accept-Encoding: gzip,deflate,sdch
Accept-Language: sv,en;q=0.8,en-US;q=0.6
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: ASP.NET_SessionId=5vkr4tfivb1ybu1sm4u4kahy; GriffinLanguageSwitcher=sv-se; __RequestVerificationToken=LiTSJATsiqh8zlcft_3gZwvY8HpcCUkirm307njxIZLdsJSYyqaV2st1tunH8sMvMwsVrj3W4dDoV8ECZRhU4s6DhTvd2F-WFkgApDBB-CA1; .ASPXAUTH=BF8BE1C246428B10B49AE867BEDF9748DB3842285BC1AF1EC44AD80281C4AE084B75F0AE13EAF1BE7F71DD26D0CE69634E83C4846625DC7E4D976CA1845914E2CC7A7CF2C522EA5586623D9B73B0AE433337FC59CF6AF665DC135491E78978EF
hello=world";
var buffer = new SocketBufferFake();
buffer.SetBuffer(Encoding.ASCII.GetBytes(HttpPost), 0, HttpPost.Length);
IHttpMessage message = null;
var builder = new HttpMessageDecoder();
builder.MessageReceived = o => message = (IHttpMessage) o;
builder.ProcessReadBytes(buffer);
message.Should().NotBeNull();
message.ContentCharset.Should().Be(Encoding.UTF32);
message.ContentLength.Should().Be(11);
message.Body.Should().NotBeNull();
message.Body.Position.Should().Be(0);
message.Body.Length.Should().Be(11);
}
示例8: Parse
public void Parse()
{
var buffer = Encoding.ASCII.GetBytes("GET / HTTP/1.1\r\nSERVER: LOCALHOST\r\n\r\n");
var slice = new SocketBufferFake();
slice.SetBuffer(buffer, 0, buffer.Length);
var parser = new HeaderParser();
parser.HeaderParsed += (name, value) => Console.WriteLine(name + ": " + value);
parser.Parse(slice, 0);
}
示例9: message_in_its_simplest_form
public void message_in_its_simplest_form()
{
var frame = new BasicFrame("STOMP");
var expected = "STOMP\n\n\0";
var buffer = new SocketBufferFake();
var encoder = new StompEncoder();
encoder.Prepare(frame);
encoder.Send(buffer);
var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);
actual.Should().Be(expected);
}
示例10: NoOp_message
public void NoOp_message()
{
var frame = new BasicFrame("NoOp");
var expected = "\n";
var buffer = new SocketBufferFake();
var encoder = new StompEncoder();
encoder.Prepare(frame);
encoder.Send(buffer);
var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);
actual.Should().Be(expected);
}
示例11: request_in_its_simplest_form
public void request_in_its_simplest_form()
{
var frame = new HttpRequest("POST", "/", "HTTP/1.1");
var expected = "POST / HTTP/1.1\r\nContent-Length: 0\r\n\r\n";
var buffer = new SocketBufferFake();
var encoder = new HttpMessageEncoder();
encoder.Prepare(frame);
encoder.Send(buffer);
var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);
actual.Should().Be(expected);
}
示例12: basic_response
public void basic_response()
{
var frame = new HttpResponse(404, "Failed to find it dude", "HTTP/1.1");
var expected = "HTTP/1.1 404 Failed to find it dude\r\n";
var buffer = new SocketBufferFake();
var encoder = new HttpMessageEncoder();
encoder.Prepare(frame);
encoder.Send(buffer);
var actual = Encoding.ASCII.GetString(buffer.Buffer, 0, buffer.Count);
actual.Substring(0,expected.Length).Should().Be(expected);
}
示例13: sendWebSocketUpgradeRequest
/// <summary>
/// Helper method which sends the websocket upgrade request
/// </summary>
/// <param name="decoder"></param>
private static void sendWebSocketUpgradeRequest(IMessageDecoder decoder)
{
var buffer = new SocketBufferFake();
buffer.Buffer = Encoding.ASCII.GetBytes(@"GET / HTTP/1.1
host: localhost
connection: upgrade
upgrade: websocket
");
buffer.BytesTransferred = buffer.Buffer.Length;
decoder.ProcessReadBytes(buffer);
}
示例14: send_simple_message
public void send_simple_message()
{
var buf = new SocketBufferFake();
var expected = "Hello world!";
var sut = new StringEncoder();
sut.Prepare(expected);
sut.Send(buf);
BitConverter.ToInt32(buf.Buffer, 0).Should().Be(expected.Length);
var actual = Encoding.UTF8.GetString(buf.Buffer, buf.BaseOffset + 4, buf.Count - 4);
actual.Should().Be(expected);
}
示例15: can_clear_even_without_shit_being_used
public void can_clear_even_without_shit_being_used()
{
var serializer = new StringSerializer();
var slice = new BufferSlice(new byte[65535], 0, 65535);
var msg = "Hello world";
var buffer = new SocketBufferFake();
var sut = new MicroMessageEncoder(serializer, slice);
sut.Clear();
sut.Prepare(msg);
sut.Send(buffer);
var field = sut.GetType().GetField("_bodyStream", BindingFlags.Instance | BindingFlags.NonPublic);
((Stream)field.GetValue(sut)).CanWrite.Should().BeTrue();
}