public void SplitWptsTest() { // Arrange var msg = new NatsMessage( new IndividualNatsMessage( "", "", NatsDirection.West, @"042049 EGGXZOZX A [WPTS] ..."), new IndividualNatsMessage( "", "", NatsDirection.East, @"042049 CZQXZQZX U TUDEP 52/50 53/40 54/30 54/20 DOGAL BEXET ...")); // Act var parser = new NatsParser(msg, null); var result = parser.Parse(); // Assert var trackU = (from trk in result where trk.Ident == "U" select trk).First(); Assert.IsTrue(trackU.MainRoute.SequenceEqual( new[] { "TUDEP", "5250N", "5340N", "5430N", "5420N", "DOGAL", "BEXET" })); }
public async Task ParseMultipleBuffers() { const string message = "some message"; var messageBytes = Encoding.UTF8.GetBytes(message + "\r\n"); var firstPart = new ArraySegment <byte>(messageBytes, 0, messageBytes.Length / 2).ToArray(); var secondPart = new ArraySegment <byte>(messageBytes, firstPart.Length, messageBytes.Length - firstPart.Length).ToArray(); // Arrange var parser = new NatsParser(); var parsedMessageTask = parser.Messages.FirstAsync() .Timeout(_timeout).ToTask(); // Act parser.Parse(firstPart, 0, firstPart.Length); parser.Parse(secondPart, 0, secondPart.Length); var parsedMessage = await parsedMessageTask; // Assert; Assert.Equal(message, parsedMessage.Message); Assert.Null(parsedMessage.Payload); }
public async Task Reset(string partialMessage) { var partialBuffer = Encoding.UTF8.GetBytes(partialMessage); const string message = "some message"; var buffer = Encoding.UTF8.GetBytes(message + "\r\n"); // Arrange var parser = new NatsParser(); var parsedMessageTask = parser.Messages.FirstAsync() .Timeout(_timeout).ToTask(); // Act parser.Parse(partialBuffer, 0, partialBuffer.Length); parser.Reset(); parser.Parse(buffer, 0, buffer.Length); var parsedMessage = await parsedMessageTask; // Assert; Assert.Equal(message, parsedMessage.Message); Assert.Null(parsedMessage.Payload); }
public async Task ParseMsgMessage() { const string message = "MSG subject 12"; const string payload = "Hello\r\nNats!"; var buffer = Encoding.UTF8.GetBytes(message + "\r\n" + payload + "\r\n"); // Arrange var parser = new NatsParser(); var parsedMessageTask = parser.Messages.FirstAsync() .Timeout(_timeout).ToTask(); // Act parser.Parse(buffer, 0, buffer.Length); var parsedMessage = await parsedMessageTask; // Assert; Assert.Equal(message, parsedMessage.Message); Assert.Equal(payload, Encoding.UTF8.GetString(parsedMessage.Payload)); }
public void CategorizeWestEastTest() { // Arrange var west = new IndividualNatsMessage( "", "", NatsDirection.West, @"042049 EGGXZOZX A [WPTS] ... B [WPTS] ... C [WPTS] ..."); var east = new IndividualNatsMessage( "", "", NatsDirection.East, @"042049 CZQXZQZX U [WPTS] ... V [WPTS] ... W [WPTS] ..."); var msg = new NatsMessage(west, east); // Act var parser = new NatsParser(msg, null); var result = parser.Parse(); // Assert Assert.AreEqual(6, result.Count); Assert.IsTrue(ContainTrack(result, "A", NatsDirection.West)); Assert.IsTrue(ContainTrack(result, "B", NatsDirection.West)); Assert.IsTrue(ContainTrack(result, "C", NatsDirection.West)); Assert.IsTrue(ContainTrack(result, "U", NatsDirection.East)); Assert.IsTrue(ContainTrack(result, "V", NatsDirection.East)); Assert.IsTrue(ContainTrack(result, "W", NatsDirection.East)); }
public async Task ParseSelected() { const string message = "some message"; var extraBytes = Encoding.UTF8.GetBytes("garbage"); var messageBytes = Encoding.UTF8.GetBytes(message + "\r\n"); var buffer = extraBytes.Concat(messageBytes).Concat(extraBytes).ToArray(); // Arrange var parser = new NatsParser(); var parsedMessageTask = parser.Messages.FirstAsync() .Timeout(_timeout).ToTask(); // Act parser.Parse(buffer, extraBytes.Length, messageBytes.Length); var parsedMessage = await parsedMessageTask; // Assert; Assert.Equal(message, parsedMessage.Message); Assert.Null(parsedMessage.Payload); }
public async Task EmitMultipleMessages() { const string firstMessage = "some message"; const string secondMessage = "second message"; var buffer = Encoding.UTF8.GetBytes(firstMessage + "\r\n" + secondMessage + "\r\n"); // Arrange var parser = new NatsParser(); var parsedMessagesTask = parser.Messages.Take(2).ToArray() .Timeout(_timeout).ToTask(); // Act parser.Parse(buffer, 0, buffer.Length); var parsedMessages = await parsedMessagesTask; // Assert; Assert.Equal(2, parsedMessages.Length); Assert.Equal(firstMessage, parsedMessages[0].Message); Assert.Equal(secondMessage, parsedMessages[1].Message); }