Skip to content

Commit

Permalink
Added Multimessage support
Browse files Browse the repository at this point in the history
  • Loading branch information
paul.daniels2 authored and paul.daniels2 committed Dec 19, 2014
1 parent 5b215f2 commit 79b2367
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
8 changes: 6 additions & 2 deletions MiniWamp/MessageWebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,12 @@ void _socket_MessageReceived(MessageWebSocket sender, MessageWebSocketMessageRec
{
args.GetDataStream().AsStreamForRead().CopyTo(ms);
ms.Position = 0;
var parsedMessage = JArray.Load(dataReader);
Message(this, new WampMessageEventArgs(parsedMessage));
dataReader.SupportMultipleContent = true;
while (dataReader.Read())
{
var parsedMessage = JArray.Load(dataReader);
Message(this, new WampMessageEventArgs(parsedMessage));
}
}

}
Expand Down
1 change: 1 addition & 0 deletions MiniWampTests/MiniWampTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<SDKReference Include="TestPlatform, Version=11.0" />
</ItemGroup>
<ItemGroup>
<Compile Include="ParsingTests.cs" />
<Compile Include="WampSessionTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down
40 changes: 40 additions & 0 deletions MiniWampTests/ParsingTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DapperWare
{
[TestClass]
class ParsingTests
{
private JsonSerializer serializer;

[TestInitialize]
public void SetUp()
{
this.serializer = new JsonSerializer();
}

[TestMethod]
public void TestDeserializeMessage()
{
string message = "[]";

using (var reader = new JsonTextReader(new StreamReader(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(message)))))
{
var parsed = JArray.Load(reader);

Assert.AreEqual(0, parsed.Count);
}


}

}
}
39 changes: 39 additions & 0 deletions MiniWampTests/WampSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using DapperWare;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using System.IO;

namespace DapperWare
{
Expand Down Expand Up @@ -147,5 +149,42 @@ public void TestCallWithError()
Assert.ThrowsException<AggregateException>(() => callTask.Wait());

}

[TestMethod]
public void TestDeserializeMultiMessage()
{
string message = "[3][\"test\"]";

using (var reader = new JsonTextReader(new StreamReader(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(message)))))
{

reader.SupportMultipleContent = true;
var parsed = JArray.Load(reader);
reader.Read();
var parsed2 = JArray.Load(reader);

Assert.AreEqual(1, parsed.Count);
Assert.AreEqual(1, parsed2.Count);
}
}

[TestMethod]
public void TestDeserializeMessage()
{
string message = "[3]";

using (var reader = new JsonTextReader(new StreamReader(new System.IO.MemoryStream(Encoding.UTF8.GetBytes(message)))))
{
List<JArray> messages = new List<JArray>();
reader.SupportMultipleContent = true;

while (reader.Read())
{
messages.Add(JArray.Load(reader));
}

Assert.AreEqual(1, messages.Count);
}
}
}
}

0 comments on commit 79b2367

Please sign in to comment.