public async void ContentTooLong() { var command = StompParser.Command.MESSAGE; var eol = "\n"; var header = "content-length:5"; await Assert.ThrowsAsync <ContentLengthException>(async() => { using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { streamWriter.Write(command); streamWriter.Write(eol); streamWriter.Write(header); streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write("0123456789"); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parsedCommand = await StompParser.ReadStompCommand(memStream.AsPrependableStream()); var parsedHeaders = await StompParser.ReadStompHeaders(parsedCommand.Item1, parsedCommand.Item2); var parsedBody = await StompParser .ReadStompBody(parsedHeaders.Item1, parsedHeaders.Item2, CancellationToken.None); } }); }
public async void StompHeadersFail(string header) { var command = StompParser.Command.MESSAGE; var eol = "\r\n"; await Assert.ThrowsAsync <HeaderParseException>(async() => { using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { streamWriter.Write(command); streamWriter.Write(eol); streamWriter.Write(header); streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parsedCommand = await StompParser.ReadStompCommand(memStream.AsPrependableStream()); var parsedHeaders = await StompParser.ReadStompHeaders(parsedCommand.Item1, parsedCommand.Item2); } }); }
public async void StompParseHeaders() { var command = StompParser.Command.MESSAGE; var header = new KeyValuePair <string, string>("content-length", "126"); var headerArray = new KeyValuePair <string, string> [1]; headerArray[0] = header; var expectation = new StompFrame(command, headerArray); using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { var eol = "\r\n"; streamWriter.Write(command); streamWriter.Write(eol); foreach (var headerPair in headerArray) { streamWriter.Write($"{headerPair.Key}:{headerPair.Value}"); } streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parsedCommand = await StompParser.ReadStompCommand(memStream.AsPrependableStream()); var parsedHeaders = await StompParser.ReadStompHeaders(parsedCommand.Item1, parsedCommand.Item2); Assert.StrictEqual(expectation.Command, parsedCommand.Item2.Command); Assert.Equal(expectation.Headers[0], parsedHeaders.Item2.Headers[0]); } }
public static void Main(string[] args) { var endPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 5467); var parser = new StompParser(); using (var reStompService = new StompService(endPoint, parser)) { reStompService.Start((middlewareStack) => { middlewareStack.Push(new TerminationMiddleware().Invoke); middlewareStack.Push(new ProtocolVersionMiddleware().Invoke); middlewareStack.Push(new SessionMiddleware().Invoke); middlewareStack.Push(new SendMiddleware().Invoke); }); Console.WriteLine("Service started."); var client = new StompClient(); var session = client.Connect("127.0.0.1", 5467).Result; if (session != null) { client.Send(new Dictionary <string, string> { ["receipt-id"] = "111" }, "WOO!").Wait(); } Console.ReadLine(); } }
public async void ContentLengthMatchesValue() { var bodyString = "0123456789abcdefghijk1234567890abcd"; var command = StompParser.Command.MESSAGE; var header = new KeyValuePair <string, string> ("content-length", bodyString.Length.ToString()); var headerArray = new KeyValuePair <string, string> [1]; headerArray[0] = header; var body = Encoding.UTF8.GetBytes(bodyString); var expectation = new StompFrame(command, headerArray, body); using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { var eol = "\r\n"; streamWriter.Write(command); streamWriter.Write(eol); foreach (var headerPair in headerArray) { streamWriter.Write($"{headerPair.Key}:{headerPair.Value}"); } streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write(bodyString); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parsedCommand = await StompParser.ReadStompCommand(memStream.AsPrependableStream()); var parsedHeaders = await StompParser.ReadStompHeaders(parsedCommand.Item1, parsedCommand.Item2); var parsedBody = await StompParser .ReadStompBody(parsedHeaders.Item1, parsedHeaders.Item2, CancellationToken.None); Assert.StrictEqual(expectation.Command, parsedCommand.Item2.Command); Assert.Equal(expectation.Headers[0], parsedHeaders.Item2.Headers[0]); Assert.True(Encoding.UTF8.GetString(expectation.Body.ToArray()) == Encoding.UTF8.GetString(parsedBody.Item2.Body.ToArray())); Assert.Equal(parsedBody.Item2.Body.Length, bodyString.Length); } }
public async void CommandParser(string command, string eol) { using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { streamWriter.Write(command); streamWriter.Write(eol); streamWriter.Write("version:1.2"); streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parsedCommand = await StompParser.ReadStompCommand(memStream.AsPrependableStream()); Assert.StrictEqual(command, parsedCommand.Item2.Command); } }
public async void CommandParserIsCaseSensitive(string command, string eol) { await Assert.ThrowsAsync <CommandParseException>(async() => { using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { streamWriter.Write(command); streamWriter.Write(eol); streamWriter.Write("version:1.2"); streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; await StompParser.ReadStompCommand(memStream.AsPrependableStream()); } }); }
public async void FrameParses() { var bodyString = "0123456789abcdefghijk1234567890abcd"; var command = StompParser.Command.MESSAGE; var header = new KeyValuePair <string, string>("key", "value"); var headerArray = new KeyValuePair <string, string> [1]; headerArray[0] = header; var body = Encoding.UTF8.GetBytes(bodyString); var expectation = new StompFrame(command, headerArray, body); using (var memStream = new MemoryStream()) using (var streamWriter = new StreamWriter(memStream)) { var eol = "\r\n"; streamWriter.Write(command); streamWriter.Write(eol); foreach (var headerPair in headerArray) { streamWriter.Write($"{headerPair.Key}:{headerPair.Value}"); } streamWriter.Write(eol); streamWriter.Write(eol); streamWriter.Write(bodyString); streamWriter.Write((char)0x00); streamWriter.Flush(); memStream.Position = 0; var parser = new StompParser(); var frame = await parser.ReadStompFrame(memStream).UnWrapFrame(); Assert.StrictEqual(expectation.Command, frame.Command); Assert.Equal(expectation.Headers[0], frame.Headers[0]); Assert.True(Encoding.UTF8.GetString(expectation.Body.ToArray()) == Encoding.UTF8.GetString(frame.Body.ToArray())); Assert.Equal(frame.Body.Length, bodyString.Length); } }