Added NightAlert project for travel kit
This commit is contained in:
@@ -0,0 +1,186 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class BinaryPollingTest : Connection
|
||||
{
|
||||
//[Fact]
|
||||
//public void PingTest()
|
||||
//{
|
||||
// var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
// log.Info("Start");
|
||||
|
||||
// var binaryData = new byte[5];
|
||||
// for (int i = 0; i < binaryData.Length; i++)
|
||||
// {
|
||||
// binaryData[i] = (byte)i;
|
||||
// }
|
||||
|
||||
// var events = new Queue<object>();
|
||||
|
||||
// var options = CreateOptions();
|
||||
// options.Transports = new List<string>(){"polling"};
|
||||
|
||||
// var socket = new Socket(options);
|
||||
|
||||
// socket.On(Socket.EVENT_OPEN, () =>
|
||||
// {
|
||||
// log.Info("EVENT_OPEN");
|
||||
|
||||
// socket.Send(binaryData);
|
||||
// socket.Send("cash money €€€");
|
||||
// });
|
||||
|
||||
// socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
// {
|
||||
// var data = d as string;
|
||||
// log.Info(string.Format("EVENT_MESSAGE data ={0} d = {1} ", data, d));
|
||||
|
||||
// if (data == "hi")
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// events.Enqueue(d);
|
||||
// //socket.Close();
|
||||
// });
|
||||
|
||||
// socket.Open();
|
||||
// Task.Delay(20000).Wait();
|
||||
// socket.Close();
|
||||
// log.Info("ReceiveBinaryData end");
|
||||
|
||||
// var binaryData2 = new byte[5];
|
||||
// for (int i = 0; i < binaryData2.Length; i++)
|
||||
// {
|
||||
// binaryData2[i] = (byte)(i + 1);
|
||||
// }
|
||||
|
||||
// object result;
|
||||
// events.TryDequeue(out result);
|
||||
// Assert.Equal("1", "1");
|
||||
//}
|
||||
|
||||
private ManualResetEvent _manualResetEvent = null;
|
||||
|
||||
[Fact]
|
||||
public void ReceiveBinaryData()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var binaryData = new byte[5];
|
||||
for (int i = 0; i < binaryData.Length; i++)
|
||||
{
|
||||
binaryData[i] = (byte)i;
|
||||
}
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Transports = new List<string>() { "polling" };
|
||||
|
||||
var socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
|
||||
socket.Send(binaryData);
|
||||
//socket.Send("cash money €€€");
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = d as string;
|
||||
log.Info(string.Format("EVENT_MESSAGE data ={0} d = {1} ", data, d));
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
events.Enqueue(d);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
log.Info("ReceiveBinaryData end");
|
||||
|
||||
var binaryData2 = new byte[5];
|
||||
for (int i = 0; i < binaryData2.Length; i++)
|
||||
{
|
||||
binaryData2[i] = (byte)(i + 1);
|
||||
}
|
||||
|
||||
object result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(binaryData, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReceiveBinaryDataAndMultibyteUTF8String()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var binaryData = new byte[5];
|
||||
for (int i = 0; i < binaryData.Length; i++)
|
||||
{
|
||||
binaryData[i] = (byte)i;
|
||||
}
|
||||
const string stringData = "cash money €€€";
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Transports = new List<string>() { "polling" };
|
||||
|
||||
var socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = d as string;
|
||||
log.Info(string.Format("EVENT_MESSAGE data ={0} d = {1} ", data, d));
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
events.Enqueue(d);
|
||||
if (events.Count > 1)
|
||||
{
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
socket.Send(binaryData);
|
||||
socket.Send(stringData);
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
var binaryData2 = new byte[5];
|
||||
for (int i = 0; i < binaryData2.Length; i++)
|
||||
{
|
||||
binaryData2[i] = (byte)(i + 1);
|
||||
}
|
||||
|
||||
object result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(binaryData, result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(stringData, (string)result);
|
||||
socket.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class BinaryWebSocketTest : Connection
|
||||
{
|
||||
private ManualResetEvent _manualResetEvent = null;
|
||||
|
||||
[Fact]
|
||||
public void ReceiveBinaryData()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var binaryData = new byte[5];
|
||||
for (int i = 0; i < binaryData.Length; i++)
|
||||
{
|
||||
binaryData[i] = (byte)(i + 0);
|
||||
}
|
||||
|
||||
var options = CreateOptions();
|
||||
|
||||
var socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info(Socket.EVENT_OPEN);
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADE, () =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE);
|
||||
socket.Send(binaryData);
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = d as string;
|
||||
log.Info(string.Format("EVENT_MESSAGE data ={0} d = {1} ", data, d));
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
events.Enqueue(d);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
log.Info("ReceiveBinaryData end");
|
||||
|
||||
var binaryData2 = new byte[5];
|
||||
for (int i = 0; i < binaryData2.Length; i++)
|
||||
{
|
||||
binaryData2[i] = (byte)(i + 1);
|
||||
}
|
||||
|
||||
object result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(binaryData, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ReceiveBinaryDataAndMultibyteUTF8String()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var binaryData = new byte[5];
|
||||
for (int i = 0; i < binaryData.Length; i++)
|
||||
{
|
||||
binaryData[i] = (byte)i;
|
||||
}
|
||||
const string stringData = "Ä ä Ü ü ß";
|
||||
|
||||
var options = CreateOptions();
|
||||
|
||||
var socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADE, () =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE);
|
||||
socket.Send(binaryData);
|
||||
socket.Send(stringData);
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = d as string;
|
||||
log.Info(string.Format("EVENT_MESSAGE data ={0} d = {1} ", data, d));
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
events.Enqueue(d);
|
||||
if (events.Count > 1)
|
||||
{
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
var binaryData2 = new byte[5];
|
||||
for (int i = 0; i < binaryData2.Length; i++)
|
||||
{
|
||||
binaryData2[i] = (byte)(i + 1);
|
||||
}
|
||||
|
||||
object result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(binaryData, result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(stringData, (string)result);
|
||||
log.Info("ReceiveBinaryDataAndMultibyteUTF8String end");
|
||||
}
|
||||
}
|
||||
}
|
||||
44
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/Connection.cs
vendored
Normal file
44
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/Connection.cs
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class Connection
|
||||
{
|
||||
static Connection()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
}
|
||||
|
||||
protected Socket.Options CreateOptions()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
|
||||
//var config = ConfigBase.Load();
|
||||
var options = new Socket.Options
|
||||
{
|
||||
Port = ConnectionConstants.PORT,
|
||||
Hostname = ConnectionConstants.HOSTNAME
|
||||
};
|
||||
log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
protected Socket.Options CreateOptionsSecure()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
|
||||
//var config = ConfigBase.Load();
|
||||
var options = new Socket.Options
|
||||
{
|
||||
Port = ConnectionConstants.SSL_PORT,
|
||||
Hostname = ConnectionConstants.HOSTNAME,
|
||||
Secure = true,
|
||||
IgnoreServerCertificateValidation = true
|
||||
};
|
||||
log.Info("Please add to your hosts file: 127.0.0.1 " + options.Hostname);
|
||||
return options;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public static class ConnectionConstants
|
||||
{
|
||||
public static int PORT = 80;
|
||||
public static string HOSTNAME = "testme.quobject.com";
|
||||
public static int SSL_PORT = 443;
|
||||
public static readonly int TIMEOUT = 300000;
|
||||
}
|
||||
}
|
||||
227
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/ConnectionTest.cs
vendored
Normal file
227
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/ConnectionTest.cs
vendored
Normal file
@@ -0,0 +1,227 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class ConnectionTest : Connection
|
||||
{
|
||||
private ManualResetEvent _manualResetEvent = null;
|
||||
private Socket socket;
|
||||
public string Message;
|
||||
|
||||
[Fact]
|
||||
public void ConnectToLocalhost()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var options = CreateOptions();
|
||||
|
||||
socket = new Socket(options);
|
||||
socket.On(Socket.EVENT_OPEN, new TestListener());
|
||||
socket.On(Socket.EVENT_MESSAGE, new MessageListener(socket, this));
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
Assert.Equal("hi", this.Message);
|
||||
}
|
||||
|
||||
public class TestListener : IListener
|
||||
{
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("open");
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class MessageListener : IListener
|
||||
{
|
||||
private Socket socket;
|
||||
private ConnectionTest connectionTest;
|
||||
|
||||
public MessageListener(Socket socket)
|
||||
{
|
||||
this.socket = socket;
|
||||
}
|
||||
|
||||
public MessageListener(Socket socket, ConnectionTest connectionTest)
|
||||
{
|
||||
this.socket = socket;
|
||||
this.connectionTest = connectionTest;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("message = " + args[0]);
|
||||
connectionTest.Message = (string)args[0];
|
||||
connectionTest._manualResetEvent.Set();
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConnectToLocalhost2()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
this.Message = "";
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Transports = new List<string>() { "polling" };
|
||||
socket = new Socket(options);
|
||||
|
||||
//socket = new Socket(CreateOptions());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("open");
|
||||
//socket.Send("test send");
|
||||
});
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
|
||||
log.Info("message2 = " + data);
|
||||
this.Message = data;
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
Assert.Equal("hi", this.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestmultibyteUtf8StringsWithPolling()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
const string SendMessage = "cash money €€€";
|
||||
|
||||
socket = new Socket(CreateOptions());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("open");
|
||||
|
||||
socket.Send(SendMessage);
|
||||
});
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
|
||||
log.Info("TestMessage data = " + data);
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Message = data;
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
log.Info("TestmultibyteUtf8StringsWithPolling this.Message = " + this.Message);
|
||||
Assert.Equal(SendMessage, this.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Testemoji()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
const string SendMessage = "\uD800-\uDB7F\uDB80-\uDBFF\uDC00-\uDFFF\uE000-\uF8FF";
|
||||
|
||||
var options = CreateOptions();
|
||||
socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("open");
|
||||
|
||||
socket.Send(SendMessage);
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
|
||||
log.Info(Socket.EVENT_MESSAGE);
|
||||
|
||||
if (data == "hi")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Message = data;
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
Assert.True(SendMessage == this.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotSendPacketsIfSocketCloses()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var noPacket = true;
|
||||
|
||||
socket = new Socket(CreateOptions());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
noPacket = true;
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
socket.On(Socket.EVENT_PACKET_CREATE, () =>
|
||||
{
|
||||
noPacket = false;
|
||||
log.Info("NotSendPacketsIfSocketCloses EVENT_PACKET_CREATE noPacket = " + noPacket);
|
||||
});
|
||||
socket.Close();
|
||||
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1));
|
||||
//await Task.Delay(1000);
|
||||
log.Info("NotSendPacketsIfSocketCloses end noPacket = " + noPacket);
|
||||
Assert.True(noPacket);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class HandshakeDataTests
|
||||
{
|
||||
[Fact]
|
||||
public void Test()
|
||||
{
|
||||
var json = @"{
|
||||
sid: 'nne323',
|
||||
upgrades: ['u1','u2'],
|
||||
pingInterval: 12,
|
||||
pingTimeout: 23
|
||||
}";
|
||||
|
||||
var handshakeData = new HandshakeData(json);
|
||||
Assert.Equal("u1", handshakeData.Upgrades[0]);
|
||||
Assert.Equal("u2", handshakeData.Upgrades[1]);
|
||||
|
||||
Assert.Equal(12, handshakeData.PingInterval);
|
||||
Assert.Equal(23, handshakeData.PingTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Client.Transports;
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class SSLServerConnectionTest : Connection
|
||||
{
|
||||
private ManualResetEvent _manualResetEvent = null;
|
||||
|
||||
[Fact]
|
||||
public void OpenAndClose()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<string>();
|
||||
|
||||
var socket = new Socket(CreateOptionsSecure());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
events.Enqueue(Socket.EVENT_OPEN);
|
||||
socket.Close();
|
||||
});
|
||||
socket.On(Socket.EVENT_CLOSE, () =>
|
||||
{
|
||||
log.Info("EVENT_CLOSE");
|
||||
events.Enqueue(Socket.EVENT_CLOSE);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
string result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(Socket.EVENT_OPEN, result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(Socket.EVENT_CLOSE, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Messages()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<string>();
|
||||
|
||||
var socket = new Socket(CreateOptionsSecure());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket.Send("hello");
|
||||
});
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
log.Info("EVENT_MESSAGE data = " + data);
|
||||
events.Enqueue(data);
|
||||
if (events.Count > 1)
|
||||
{
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
string result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("hi", result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("hello", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Handshake()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
HandshakeData handshake_data = null;
|
||||
|
||||
var socket = new Socket(CreateOptionsSecure());
|
||||
|
||||
socket.On(Socket.EVENT_HANDSHAKE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_HANDSHAKE + string.Format(" data = {0}", data));
|
||||
handshake_data = data as HandshakeData;
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
Assert.NotNull(handshake_data);
|
||||
Assert.NotNull(handshake_data.Upgrades);
|
||||
Assert.True(handshake_data.Upgrades.Count > 0);
|
||||
Assert.True(handshake_data.PingInterval > 0);
|
||||
Assert.True(handshake_data.PingTimeout > 0);
|
||||
}
|
||||
|
||||
public class TestHandshakeListener : IListener
|
||||
{
|
||||
public HandshakeData HandshakeData;
|
||||
private SSLServerConnectionTest serverConnectionTest;
|
||||
|
||||
public TestHandshakeListener(SSLServerConnectionTest serverConnectionTest)
|
||||
{
|
||||
this.serverConnectionTest = serverConnectionTest;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info(string.Format("open args[0]={0} args.Length={1}", args[0], args.Length));
|
||||
HandshakeData = args[0] as HandshakeData;
|
||||
serverConnectionTest._manualResetEvent.Set();
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Handshake2()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket = new Socket(CreateOptionsSecure());
|
||||
var testListener = new TestHandshakeListener(this);
|
||||
socket.On(Socket.EVENT_HANDSHAKE, testListener);
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
Assert.NotNull(testListener.HandshakeData);
|
||||
Assert.NotNull(testListener.HandshakeData.Upgrades);
|
||||
Assert.True(testListener.HandshakeData.Upgrades.Count > 0);
|
||||
Assert.True(testListener.HandshakeData.PingInterval > 0);
|
||||
Assert.True(testListener.HandshakeData.PingTimeout > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Upgrade()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var socket = new Socket(CreateOptionsSecure());
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADING, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADING + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
});
|
||||
socket.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
|
||||
object test = null;
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RememberWebsocket()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket1 = new Socket(CreateOptionsSecure());
|
||||
string socket1TransportName = null;
|
||||
string socket2TransportName = null;
|
||||
|
||||
socket1.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket1TransportName = socket1.Transport.Name;
|
||||
});
|
||||
|
||||
socket1.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
var transport = (Transport)data;
|
||||
socket1.Close();
|
||||
if (WebSocket.NAME == transport.Name)
|
||||
{
|
||||
var options = CreateOptionsSecure();
|
||||
options.RememberUpgrade = true;
|
||||
var socket2 = new Socket(options);
|
||||
socket2.Open();
|
||||
socket2TransportName = socket2.Transport.Name;
|
||||
socket2.Close();
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
|
||||
socket1.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
Assert.Equal(Polling.NAME, socket1TransportName);
|
||||
Assert.Equal(WebSocket.NAME, socket2TransportName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotRememberWebsocket()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket1 = new Socket(CreateOptionsSecure());
|
||||
string socket1TransportName = null;
|
||||
string socket2TransportName = null;
|
||||
|
||||
socket1.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket1TransportName = socket1.Transport.Name;
|
||||
});
|
||||
|
||||
socket1.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
var transport = (Transport)data;
|
||||
if (WebSocket.NAME == transport.Name)
|
||||
{
|
||||
socket1.Close();
|
||||
var options = CreateOptionsSecure();
|
||||
options.RememberUpgrade = false;
|
||||
var socket2 = new Socket(options);
|
||||
socket2.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN socket 2");
|
||||
socket2TransportName = socket2.Transport.Name;
|
||||
socket2.Close();
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
socket2.Open();
|
||||
}
|
||||
});
|
||||
|
||||
socket1.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
Assert.Equal(Polling.NAME, socket1TransportName);
|
||||
Assert.Equal(Polling.NAME, socket2TransportName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,373 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Client.Transports;
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class ServerConnectionTest : Connection
|
||||
{
|
||||
private ManualResetEvent _manualResetEvent = null;
|
||||
|
||||
[Fact]
|
||||
public void OpenAndClose()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<string>();
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
events.Enqueue(Socket.EVENT_OPEN);
|
||||
socket.Close();
|
||||
});
|
||||
socket.On(Socket.EVENT_CLOSE, () =>
|
||||
{
|
||||
log.Info("EVENT_CLOSE");
|
||||
events.Enqueue(Socket.EVENT_CLOSE);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
string result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(Socket.EVENT_OPEN, result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal(Socket.EVENT_CLOSE, result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Messages()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<string>();
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket.Send("hello");
|
||||
});
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
log.Info("EVENT_MESSAGE data = " + data);
|
||||
events.Enqueue(data);
|
||||
if (events.Count > 1)
|
||||
{
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
string result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("hi", result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("hello", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Handshake()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
HandshakeData handshake_data = null;
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
|
||||
socket.On(Socket.EVENT_HANDSHAKE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_HANDSHAKE + string.Format(" data = {0}", data));
|
||||
handshake_data = data as HandshakeData;
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
Assert.NotNull(handshake_data);
|
||||
Assert.NotNull(handshake_data.Upgrades);
|
||||
Assert.True(handshake_data.Upgrades.Count > 0);
|
||||
Assert.True(handshake_data.PingInterval > 0);
|
||||
Assert.True(handshake_data.PingTimeout > 0);
|
||||
}
|
||||
|
||||
public class TestHandshakeListener : IListener
|
||||
{
|
||||
public HandshakeData HandshakeData;
|
||||
private ServerConnectionTest serverConnectionTest;
|
||||
|
||||
public TestHandshakeListener(ServerConnectionTest serverConnectionTest)
|
||||
{
|
||||
this.serverConnectionTest = serverConnectionTest;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info(string.Format("open args[0]={0} args.Length={1}", args[0], args.Length));
|
||||
HandshakeData = args[0] as HandshakeData;
|
||||
serverConnectionTest._manualResetEvent.Set();
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Handshake2()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
var testListener = new TestHandshakeListener(this);
|
||||
socket.On(Socket.EVENT_HANDSHAKE, testListener);
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
Assert.NotNull(testListener.HandshakeData);
|
||||
Assert.NotNull(testListener.HandshakeData.Upgrades);
|
||||
Assert.True(testListener.HandshakeData.Upgrades.Count > 0);
|
||||
Assert.True(testListener.HandshakeData.PingInterval > 0);
|
||||
Assert.True(testListener.HandshakeData.PingTimeout > 0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Upgrade()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADING, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADING + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
});
|
||||
socket.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
|
||||
object test = null;
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RememberWebsocket()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket1 = new Socket(CreateOptions());
|
||||
string socket1TransportName = null;
|
||||
string socket2TransportName = null;
|
||||
|
||||
socket1.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket1TransportName = socket1.Transport.Name;
|
||||
});
|
||||
|
||||
socket1.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
var transport = (Transport)data;
|
||||
socket1.Close();
|
||||
if (WebSocket.NAME == transport.Name)
|
||||
{
|
||||
var options = CreateOptions();
|
||||
options.RememberUpgrade = true;
|
||||
var socket2 = new Socket(options);
|
||||
socket2.Open();
|
||||
socket2TransportName = socket2.Transport.Name;
|
||||
socket2.Close();
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
|
||||
socket1.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
Assert.Equal(Polling.NAME, socket1TransportName);
|
||||
Assert.Equal(WebSocket.NAME, socket2TransportName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NotRememberWebsocket()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var socket1 = new Socket(CreateOptions());
|
||||
string socket1TransportName = null;
|
||||
string socket2TransportName = null;
|
||||
|
||||
socket1.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket1TransportName = socket1.Transport.Name;
|
||||
});
|
||||
|
||||
socket1.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
var transport = (Transport)data;
|
||||
if (WebSocket.NAME == transport.Name)
|
||||
{
|
||||
socket1.Close();
|
||||
var options = CreateOptions();
|
||||
options.RememberUpgrade = false;
|
||||
var socket2 = new Socket(options);
|
||||
socket2.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN socket 2");
|
||||
socket2TransportName = socket2.Transport.Name;
|
||||
socket2.Close();
|
||||
_manualResetEvent.Set();
|
||||
});
|
||||
socket2.Open();
|
||||
}
|
||||
});
|
||||
|
||||
socket1.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
Assert.Equal(Polling.NAME, socket1TransportName);
|
||||
Assert.Equal(Polling.NAME, socket2TransportName);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Cookie()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<string>();
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Cookies.Add("foo", "bar");
|
||||
var socket = new Socket(options);
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
socket.Send("cookie");
|
||||
});
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
var data = (string)d;
|
||||
log.Info("EVENT_MESSAGE data = " + data);
|
||||
events.Enqueue(data);
|
||||
if (events.Count > 1)
|
||||
{
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
socket.Close();
|
||||
|
||||
string result;
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("hi", result);
|
||||
result = events.Dequeue();
|
||||
Assert.Equal("got cookie", result);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UpgradeCookie()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
_manualResetEvent = new ManualResetEvent(false);
|
||||
|
||||
var events = new Queue<object>();
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Cookies.Add("foo", "bar");
|
||||
var socket = new Socket(options);
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADING, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADING + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_UPGRADE, (data) =>
|
||||
{
|
||||
log.Info(Socket.EVENT_UPGRADE + string.Format(" data = {0}", data));
|
||||
events.Enqueue(data);
|
||||
socket.Send("cookie");
|
||||
});
|
||||
|
||||
socket.On(Socket.EVENT_MESSAGE, (d) =>
|
||||
{
|
||||
if (events.Count > 1)
|
||||
{
|
||||
var data = (string)d;
|
||||
log.Info("EVENT_MESSAGE data = " + data);
|
||||
events.Enqueue(data);
|
||||
_manualResetEvent.Set();
|
||||
}
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
_manualResetEvent.WaitOne();
|
||||
|
||||
object test = null;
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
|
||||
test = events.Dequeue();
|
||||
Assert.NotNull(test);
|
||||
Assert.IsAssignableFrom<Transport>(test);
|
||||
test = events.Dequeue();
|
||||
Assert.Equal("got cookie", test);
|
||||
}
|
||||
}
|
||||
}
|
||||
77
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/SocketTest.cs
vendored
Normal file
77
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/SocketTest.cs
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class SocketTest : Connection
|
||||
{
|
||||
private Socket socket;
|
||||
public string Message;
|
||||
|
||||
[Fact]
|
||||
public void FilterUpgrades()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = CreateOptions();
|
||||
options.Transports = new List<string>() { "polling" };
|
||||
|
||||
socket = new Socket(options);
|
||||
|
||||
var List = socket.FilterUpgrades(new List<string>() { "polling", "websocket" });
|
||||
|
||||
Assert.Equal("polling", List[0]);
|
||||
Assert.Equal(1, List.Count);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SocketClosing()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var closed = false;
|
||||
var error = false;
|
||||
|
||||
var options = CreateOptions();
|
||||
|
||||
socket = new Socket("ws://0.0.0.0:8080", options);
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
log.Info("EVENT_OPEN");
|
||||
//socket.Send("test send");
|
||||
});
|
||||
socket.On(Socket.EVENT_CLOSE, () =>
|
||||
{
|
||||
log.Info("EVENT_CLOSE = ");
|
||||
closed = true;
|
||||
});
|
||||
|
||||
socket.Once(Socket.EVENT_ERROR, () =>
|
||||
{
|
||||
log.Info("EVENT_ERROR = ");
|
||||
error = true;
|
||||
});
|
||||
|
||||
socket.Open();
|
||||
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));
|
||||
//Task.Delay(1000);
|
||||
Assert.True(closed);
|
||||
Assert.True(error);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SocketOptionCookies()
|
||||
{
|
||||
var options = new Socket.Options();
|
||||
options.Cookies.Add("foo", "bar");
|
||||
Assert.Equal("foo=bar", options.GetCookiesAsString());
|
||||
options.Cookies.Add("name2", "value2");
|
||||
Assert.Equal("foo=bar; name2=value2", options.GetCookiesAsString());
|
||||
}
|
||||
}
|
||||
}
|
||||
182
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/TransportTest.cs
vendored
Normal file
182
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/TransportTest.cs
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Client.Transports;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
// NOTE: tests for the rememberUpgrade option are on ServerConnectionTest.
|
||||
|
||||
public class TransportTest : Connection
|
||||
{
|
||||
[Fact]
|
||||
public void Constructors()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var socket = new Socket(CreateOptions());
|
||||
|
||||
socket.Open();
|
||||
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(3));
|
||||
Assert.NotNull(socket.Transport);
|
||||
|
||||
socket.Close();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Uri()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = this.CreateOptions().Hostname;
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = false;
|
||||
var polling = new Polling(options);
|
||||
var expected = string.Format("http://{0}/engine.io?sid=test&b64=1", options.Hostname);
|
||||
Assert.Contains(expected, polling.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriWithDefaultPort()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = this.CreateOptions().Hostname;
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = false;
|
||||
options.Port = 80;
|
||||
var polling = new Polling(options);
|
||||
//Assert.Contains("http://localhost/engine.io?sid=test&b64=1", polling.Uri());
|
||||
var expected = string.Format("http://{0}/engine.io?sid=test&b64=1", options.Hostname);
|
||||
Assert.Contains(expected, polling.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UriWithPort()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = this.CreateOptions().Hostname;
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = false;
|
||||
options.Port = 3000;
|
||||
var polling = new Polling(options);
|
||||
//Assert.Contains("http://localhost:3000/engine.io?sid=test&b64=1", polling.Uri());
|
||||
var expected = string.Format("http://{0}:{1}/engine.io?sid=test&b64=1", options.Hostname, options.Port);
|
||||
Assert.Contains(expected, polling.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HttpsUriWithDefaultPort()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = this.CreateOptions().Hostname;
|
||||
options.Secure = true;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = false;
|
||||
options.Port = 443;
|
||||
var polling = new Polling(options);
|
||||
//Assert.Contains("https://localhost/engine.io?sid=test&b64=1", polling.Uri());
|
||||
var expected = string.Format("https://{0}/engine.io?sid=test&b64=1", options.Hostname);
|
||||
Assert.Contains(expected, polling.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TimestampedUri()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = "test";
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = true;
|
||||
options.TimestampParam = "t";
|
||||
var polling = new Polling(options);
|
||||
|
||||
string pat = @"http://test/engine.io\?sid=test&(t=[0-9]+-[0-9]+)";
|
||||
var r = new Regex(pat, RegexOptions.IgnoreCase);
|
||||
var test = polling.Uri();
|
||||
log.Info(test);
|
||||
Match m = r.Match(test);
|
||||
Assert.True(m.Success);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WsUri()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = "test";
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "transport", "websocket" } };
|
||||
options.TimestampRequests = false;
|
||||
var ws = new WebSocket(options);
|
||||
Assert.Contains("ws://test/engine.io?transport=websocket", ws.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WssUri()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = "test";
|
||||
options.Secure = true;
|
||||
options.Query = new Dictionary<string, string> { { "transport", "websocket" } };
|
||||
options.TimestampRequests = false;
|
||||
var ws = new WebSocket(options);
|
||||
Assert.Contains("wss://test/engine.io?transport=websocket", ws.Uri());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WsTimestampedUri()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = new Transport.Options();
|
||||
options.Path = "/engine.io";
|
||||
options.Hostname = "test";
|
||||
options.Secure = false;
|
||||
options.Query = new Dictionary<string, string> { { "sid", "test" } };
|
||||
options.TimestampRequests = true;
|
||||
options.TimestampParam = "woot";
|
||||
var ws = new WebSocket(options);
|
||||
|
||||
string pat = @"ws://test/engine.io\?sid=test&(woot=[0-9]+-[0-9]+)";
|
||||
var r = new Regex(pat, RegexOptions.IgnoreCase);
|
||||
var test = ws.Uri();
|
||||
log.Info(test);
|
||||
Match m = r.Match(test);
|
||||
Assert.True(m.Success);
|
||||
}
|
||||
}
|
||||
}
|
||||
52
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/UsageTest.cs
vendored
Normal file
52
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ClientTests/UsageTest.cs
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
using Quobject.EngineIoClientDotNet.Client;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ClientTests
|
||||
{
|
||||
public class UsageTest : Connection
|
||||
{
|
||||
[Fact]
|
||||
public void Usage1()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = CreateOptions();
|
||||
var socket = new Socket(options);
|
||||
|
||||
//You can use `Socket` to connect:
|
||||
//var socket = new Socket("ws://localhost");
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
socket.Send("hi");
|
||||
socket.Close();
|
||||
});
|
||||
socket.Open();
|
||||
|
||||
//System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Usage2()
|
||||
{
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var options = CreateOptions();
|
||||
var socket = new Socket(options);
|
||||
|
||||
//Receiving data
|
||||
//var socket = new Socket("ws://localhost:3000");
|
||||
socket.On(Socket.EVENT_OPEN, () =>
|
||||
{
|
||||
socket.On(Socket.EVENT_MESSAGE, (data) => Console.WriteLine((string)data));
|
||||
});
|
||||
socket.Open();
|
||||
|
||||
System.Threading.Thread.Sleep(TimeSpan.FromSeconds(2));
|
||||
socket.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,399 @@
|
||||
using Quobject.EngineIoClientDotNet.ComponentEmitter;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ComponentEmitterTests
|
||||
{
|
||||
public class EmitterTests
|
||||
{
|
||||
public class TestListener1 : IListener
|
||||
{
|
||||
private readonly List<object> _calls;
|
||||
|
||||
public TestListener1(List<object> calls)
|
||||
{
|
||||
this._calls = calls;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
_calls.Add("one");
|
||||
_calls.Add(args[0]);
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public class TestListener2 : IListener
|
||||
{
|
||||
private readonly List<object> _calls;
|
||||
|
||||
public TestListener2(List<object> calls)
|
||||
{
|
||||
this._calls = calls;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
_calls.Add("two");
|
||||
_calls.Add(args[0]);
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void On()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener1 = new TestListener1(calls);
|
||||
emitter.On("foo", listener1);
|
||||
|
||||
var listener2 = new TestListener2(calls);
|
||||
emitter.On("foo", listener2);
|
||||
|
||||
emitter.Emit("foo", 1);
|
||||
emitter.Emit("bar", 1);
|
||||
emitter.Emit("foo", 2);
|
||||
|
||||
var expected = new Object[] {"one", 1, "two", 1, "one", 2, "two", 2};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Once()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener1 = new TestListener1(calls);
|
||||
emitter.Once("foo", listener1);
|
||||
|
||||
emitter.Emit("foo", 1);
|
||||
emitter.Emit("foo", 2);
|
||||
emitter.Emit("foo", 3);
|
||||
emitter.Emit("bar", 1);
|
||||
|
||||
var expected = new Object[] {"one", 1};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
|
||||
public class TestListener3 : IListener
|
||||
{
|
||||
private readonly List<object> _calls;
|
||||
|
||||
public TestListener3(List<object> calls)
|
||||
{
|
||||
this._calls = calls;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
_calls.Add("one");
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TestListener4 : IListener
|
||||
{
|
||||
private readonly List<object> _calls;
|
||||
|
||||
public TestListener4(List<object> calls)
|
||||
{
|
||||
this._calls = calls;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
_calls.Add("two");
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Off()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
emitter.On("foo", listener3);
|
||||
|
||||
var listener4 = new TestListener4(calls);
|
||||
emitter.On("foo", listener4);
|
||||
emitter.Off("foo", listener4);
|
||||
|
||||
emitter.Emit("foo");
|
||||
|
||||
var expected = new Object[] {"one"};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OffWithOnce()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
|
||||
emitter.Once("foo", listener3);
|
||||
emitter.Off("foo", listener3);
|
||||
|
||||
emitter.Emit("foo");
|
||||
|
||||
var expected = new Object[] {};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
|
||||
public class TestListener5 : IListener
|
||||
{
|
||||
private readonly List<bool> _called;
|
||||
|
||||
public TestListener5(List<bool> called)
|
||||
{
|
||||
this._called = called;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
this._called[0] = true;
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class TestListener6 : IListener
|
||||
{
|
||||
private readonly Emitter _emitter;
|
||||
private readonly IListener _bListener;
|
||||
|
||||
public TestListener6(Emitter emitter, IListener bListener)
|
||||
{
|
||||
this._emitter = emitter;
|
||||
this._bListener = bListener;
|
||||
}
|
||||
|
||||
public void Call(params object[] args)
|
||||
{
|
||||
_emitter.Off("tobi", _bListener);
|
||||
}
|
||||
|
||||
public int CompareTo(IListener other)
|
||||
{
|
||||
return this.GetId().CompareTo(other.GetId());
|
||||
}
|
||||
|
||||
public int GetId()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OffWhenCalledfromEvent()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var called = new List<bool>() {false};
|
||||
|
||||
|
||||
var listener5 = new TestListener5(called);
|
||||
var listener6 = new TestListener6(emitter, listener5);
|
||||
emitter.On("tobi", listener6);
|
||||
|
||||
emitter.Once("tobi", listener5);
|
||||
emitter.Emit("tobi");
|
||||
Assert.True(called[0]);
|
||||
called[0] = false;
|
||||
emitter.Emit("tobi");
|
||||
Assert.False(called[0]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OffEvent()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
emitter.On("foo", listener3);
|
||||
|
||||
var listener4 = new TestListener4(calls);
|
||||
|
||||
emitter.On("foo", listener3);
|
||||
emitter.On("foo", listener4);
|
||||
emitter.Off("foo");
|
||||
|
||||
emitter.Emit("foo");
|
||||
emitter.Emit("foo");
|
||||
|
||||
var expected = new Object[] {};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void OffAll()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
|
||||
var listener4 = new TestListener4(calls);
|
||||
|
||||
|
||||
|
||||
emitter.On("foo", listener3);
|
||||
emitter.On("bar", listener4);
|
||||
|
||||
emitter.Emit("foo");
|
||||
emitter.Emit("bar");
|
||||
|
||||
emitter.Off();
|
||||
|
||||
emitter.Emit("foo");
|
||||
emitter.Emit("bar");
|
||||
|
||||
|
||||
var expected = new Object[] {"one", "two"};
|
||||
Assert.Equal(expected, calls.ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Listeners()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
emitter.On("foo", listener3);
|
||||
var expected = new IListener[] {listener3};
|
||||
Assert.Equal(expected, emitter.Listeners("foo").ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ListenersWithoutHandlers()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var emitter = new Emitter();
|
||||
var expected = new IListener[] {};
|
||||
Assert.Equal(expected, emitter.Listeners("foo").ToArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasListeners()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
var calls = new List<object>();
|
||||
Assert.False(emitter.HasListeners("foo"));
|
||||
|
||||
var listener3 = new TestListener3(calls);
|
||||
emitter.On("foo", listener3);
|
||||
Assert.True(emitter.HasListeners("foo"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasListenersWithoutHandlers()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var emitter = new Emitter();
|
||||
Assert.False(emitter.HasListeners("foo"));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{BA788BBE-0FE8-4C2F-8A02-457A5E9E2703}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>EngineIoClientDotNet.Tests.net35</RootNamespace>
|
||||
<AssemblyName>EngineIoClientDotNet.Tests.net35</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\EngineIoClientDotNet.net35\packages\Newtonsoft.Json.9.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="SuperSocket.ClientEngine, Version=0.9.0.0, Culture=neutral, PublicKeyToken=ee9af13f57f00acc, processorArchitecture=MSIL">
|
||||
<HintPath>..\EngineIoClientDotNet.net35\packages\SuperSocket.ClientEngine.Core.0.9.0\lib\net35-client\SuperSocket.ClientEngine.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Threading.Tasks.NET35, Version=3.0.2.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\EngineIoClientDotNet.net35\packages\System.Threading.Tasks.Unofficial.3.1\lib\net35\System.Threading.Tasks.NET35.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="WebSocket4Net, Version=0.15.1.10, Culture=neutral, PublicKeyToken=eb4e154b696bf72a, processorArchitecture=MSIL">
|
||||
<HintPath>..\EngineIoClientDotNet.net35\packages\WebSocket4Net.0.15.1\lib\net35\WebSocket4Net.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
|
||||
<HintPath>..\EngineIoClientDotNet.net35\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ClientTests\BinaryPollingTest.cs" />
|
||||
<Compile Include="ClientTests\BinaryWebSocketTest.cs" />
|
||||
<Compile Include="ClientTests\Connection.cs" />
|
||||
<Compile Include="ClientTests\ConnectionConstants.cs" />
|
||||
<Compile Include="ClientTests\ConnectionTest.cs" />
|
||||
<Compile Include="ClientTests\HandshakeDataTests.cs" />
|
||||
<Compile Include="ClientTests\ServerConnectionTest.cs" />
|
||||
<Compile Include="ClientTests\SocketTest.cs" />
|
||||
<Compile Include="ClientTests\SSLServerConnectionTest.cs" />
|
||||
<Compile Include="ClientTests\TransportTest.cs" />
|
||||
<Compile Include="ClientTests\UsageTest.cs" />
|
||||
<Compile Include="ComponentEmitterTests\EmitterTests.cs" />
|
||||
<Compile Include="ModulesTests\ParseQSTests.cs" />
|
||||
<Compile Include="ModulesTests\UTF8Tests.cs" />
|
||||
<Compile Include="ParserTests\DecodeTests.cs" />
|
||||
<Compile Include="ParserTests\TestsParser.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\EngineIoClientDotNet.net35\EngineIoClientDotNet.net35.csproj">
|
||||
<Project>{568d67d0-3253-4601-9b04-7730a9ec5cc0}</Project>
|
||||
<Name>EngineIoClientDotNet.net35</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
|
||||
using System.Collections.Concurrent;
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System.Collections.Generic;
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ModulesTests
|
||||
{
|
||||
public class ParseQsTests
|
||||
{
|
||||
//should parse a querystring and return an object
|
||||
[Fact]
|
||||
public void Decode()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
// Single assignment
|
||||
var queryObj = ParseQS.Decode("foo=bar");
|
||||
Assert.Equal("bar", queryObj["foo"]);
|
||||
|
||||
// Multiple assignments
|
||||
queryObj = ParseQS.Decode("france=grenoble&germany=mannheim");
|
||||
Assert.Equal("grenoble", queryObj["france"]);
|
||||
Assert.Equal("mannheim", queryObj["germany"]);
|
||||
|
||||
// Assignments containing non-alphanumeric characters
|
||||
queryObj = ParseQS.Decode("india=new%20delhi");
|
||||
Assert.Equal("new delhi", queryObj["india"]);
|
||||
}
|
||||
|
||||
//should construct a query string from an object'
|
||||
[Fact]
|
||||
public void Encode()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
//Dictionary<string, string> obj;
|
||||
|
||||
//obj = new Dictionary<string, string> {{"a", "b"}};
|
||||
//var imObj = ImmutableDictionary.Create<string, string>().AddRange(obj);
|
||||
var imObj = new ConcurrentDictionary<string, string>();
|
||||
imObj.TryAdd("a","b");
|
||||
Assert.Equal("a=b", ParseQS.Encode(imObj));
|
||||
|
||||
//obj = new Dictionary<string, string> {{"a", "b"}, {"c", "d"}};
|
||||
//imObj = ImmutableDictionary.Create<string, string>().AddRange(obj);
|
||||
imObj = new ConcurrentDictionary<string, string>();
|
||||
imObj.TryAdd("a", "b");
|
||||
imObj.TryAdd("c", "d");
|
||||
Assert.Equal("a=b&c=d", ParseQS.Encode(imObj));
|
||||
|
||||
//obj = new Dictionary<string, string> {{"a", "b"}, {"c", "tobi rocks"}};
|
||||
//imObj = ImmutableDictionary.Create<string, string>().AddRange(obj);
|
||||
imObj = new ConcurrentDictionary<string, string>();
|
||||
imObj.TryAdd("a", "b");
|
||||
imObj.TryAdd("c", "tobi rocks");
|
||||
Assert.Equal("a=b&c=tobi%20rocks", ParseQS.Encode(imObj));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
144
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ModulesTests/UTF8Tests.cs
vendored
Normal file
144
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ModulesTests/UTF8Tests.cs
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ModulesTests
|
||||
{
|
||||
public class Utf8Tests
|
||||
{
|
||||
private static readonly Data[] DATA = new Data[]
|
||||
{
|
||||
// 1-byte
|
||||
new Data(0x0000, "\x00", "\x00"),
|
||||
new Data(0x005c, "\u005C\u005C", "\u005C\u005C"), // = backslash
|
||||
new Data(0x007f, "\u007F", "\u007F"),
|
||||
// 2-byte
|
||||
new Data(0x0080, "\u0080", "\u00C2\u0080"),
|
||||
new Data(0x05CA, "\u05CA", "\u00D7\u008A"),
|
||||
new Data(0x07FF, "\u07FF", "\u00DF\u00BF"),
|
||||
// 3-byte
|
||||
new Data(0x0800, "\u0800", "\u00E0\u00A0\u0080"),
|
||||
new Data(0x2C3C, "\u2C3C", "\u00E2\u00B0\u00BC"),
|
||||
new Data(0x07FF, "\uFFFF", "\u00EF\u00BF\u00BF"),
|
||||
// unmatched surrogate halves
|
||||
// high surrogates: 0xD800 to 0xDBFF
|
||||
new Data(0xD800, "\uD800", "\u00ED\u00A0\u0080"),
|
||||
new Data("High surrogate followed by another high surrogate",
|
||||
"\uD800\uD800", "\u00ED\u00A0\u0080\u00ED\u00A0\u0080"),
|
||||
new Data("High surrogate followed by a symbol that is not a surrogate",
|
||||
"\uD800A", "\u00ED\u00A0\u0080A"),
|
||||
new Data(
|
||||
"Unmatched high surrogate, followed by a surrogate pair, followed by an unmatched high surrogate",
|
||||
"\uD800\uD834\uDF06\uD800", "\u00ED\u00A0\u0080\u00F0\u009D\u008C\u0086\u00ED\u00A0\u0080"),
|
||||
new Data(0xD9AF, "\uD9AF", "\u00ED\u00A6\u00AF"),
|
||||
new Data(0xDBFF, "\uDBFF", "\u00ED\u00AF\u00BF"),
|
||||
// low surrogates: 0xDC00 to 0xDFFF
|
||||
new Data(0xDC00, "\uDC00", "\u00ED\u00B0\u0080"),
|
||||
new Data("Low surrogate followed by another low surrogate",
|
||||
"\uDC00\uDC00", "\u00ED\u00B0\u0080\u00ED\u00B0\u0080"),
|
||||
new Data("Low surrogate followed by a symbol that is not a surrogate",
|
||||
"\uDC00A", "\u00ED\u00B0\u0080A"),
|
||||
new Data(
|
||||
"Unmatched low surrogate, followed by a surrogate pair, followed by an unmatched low surrogate",
|
||||
"\uDC00\uD834\uDF06\uDC00", "\u00ED\u00B0\u0080\u00F0\u009D\u008C\u0086\u00ED\u00B0\u0080"),
|
||||
new Data(0xDEEE, "\uDEEE", "\u00ED\u00BB\u00AE"),
|
||||
new Data(0xDFFF, "\uDFFF", "\u00ED\u00BF\u00BF"),
|
||||
// 4-byte
|
||||
new Data(0x010000, "\uD800\uDC00", "\u00F0\u0090\u0080\u0080"),
|
||||
new Data(0x01D306, "\uD834\uDF06", "\u00F0\u009D\u008C\u0086"),
|
||||
new Data(0x010FFF, "\uDBFF\uDFFF", "\u00F4\u008F\u00BF\u00BF"),
|
||||
};
|
||||
|
||||
//
|
||||
[Fact]
|
||||
public void EncodeAndDecode()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
foreach (var data in DATA)
|
||||
{
|
||||
data.Test();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private class Data
|
||||
{
|
||||
private readonly int _codePoint = -1;
|
||||
private String Description { get; set; }
|
||||
private String Decoded { get; set; }
|
||||
private String Encoded { get; set; }
|
||||
|
||||
public Data(int codePoint, String decoded, String encoded)
|
||||
{
|
||||
this._codePoint = codePoint;
|
||||
this.Decoded = decoded;
|
||||
this.Encoded = encoded;
|
||||
}
|
||||
|
||||
public Data(String description, String decoded, String encoded)
|
||||
{
|
||||
this.Description = description;
|
||||
this.Decoded = decoded;
|
||||
this.Encoded = encoded;
|
||||
}
|
||||
|
||||
public void Test()
|
||||
{
|
||||
EncodingTest();
|
||||
DecodingTest();
|
||||
ExceptionTest();
|
||||
}
|
||||
|
||||
private void EncodingTest()
|
||||
{
|
||||
var value = UTF8.Encode(Decoded);
|
||||
Assert.Equal(Encoded, value);
|
||||
}
|
||||
|
||||
private void DecodingTest()
|
||||
{
|
||||
Assert.Equal(Decoded, UTF8.Decode(Encoded));
|
||||
}
|
||||
|
||||
private void ExceptionTest()
|
||||
{
|
||||
Assert.Throws<UTF8Exception>(
|
||||
delegate
|
||||
{
|
||||
UTF8.Decode("\uFFFF");
|
||||
});
|
||||
|
||||
Assert.Throws<UTF8Exception>(
|
||||
delegate
|
||||
{
|
||||
UTF8.Decode("\xE9\x00\x00");
|
||||
});
|
||||
|
||||
Assert.Throws<UTF8Exception>(
|
||||
delegate
|
||||
{
|
||||
UTF8.Decode("\xC2\uFFFF");
|
||||
});
|
||||
|
||||
Assert.Throws<UTF8Exception>(
|
||||
delegate
|
||||
{
|
||||
UTF8.Decode("\xF0\x9D");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
private string Reason
|
||||
{
|
||||
get { return Description ?? "U+" + _codePoint.ToString("X4").ToUpper(); }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
98
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ParserTests/DecodeTests.cs
vendored
Normal file
98
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ParserTests/DecodeTests.cs
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using Quobject.EngineIoClientDotNet.Parser;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ParserTests
|
||||
{
|
||||
public class DecodeTests
|
||||
{
|
||||
private const string PARSER_ERROR = "parser error";
|
||||
|
||||
[Fact]
|
||||
public void DecodeBadFormat()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet p = Parser.DecodePacket(":::");
|
||||
Assert.Equal(Packet.ERROR, p.Type);
|
||||
Assert.Equal(PARSER_ERROR, p.Data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DecodeInexistingTypes()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet p = Parser.DecodePacket("94103");
|
||||
Assert.Equal(Packet.ERROR, p.Type);
|
||||
Assert.Equal(PARSER_ERROR, p.Data);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DecodeInvalidUTF8()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet p = Parser.DecodePacket("4\uffff", true);
|
||||
Assert.Equal(Packet.ERROR, p.Type);
|
||||
Assert.Equal(PARSER_ERROR, p.Data);
|
||||
}
|
||||
|
||||
|
||||
public class DecodePayloadBadFormat_DecodeCallback : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
var isLast = index + 1 == total;
|
||||
Assert.True(isLast);
|
||||
Assert.Equal(Packet.ERROR, packet.Type);
|
||||
Assert.Equal(PARSER_ERROR, packet.Data);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAndDecodeEmptyPayloads()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet.DecodePayload("1!", new DecodePayloadBadFormat_DecodeCallback());
|
||||
Packet.DecodePayload("", new DecodePayloadBadFormat_DecodeCallback());
|
||||
Packet.DecodePayload("))", new DecodePayloadBadFormat_DecodeCallback());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DecodePayloadBadPacketFormat()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet.DecodePayload("3:99", new DecodePayloadBadFormat_DecodeCallback());
|
||||
Packet.DecodePayload("1:aa", new DecodePayloadBadFormat_DecodeCallback());
|
||||
Packet.DecodePayload("1:a2:b", new DecodePayloadBadFormat_DecodeCallback());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DecodePayloadInvalidUTF8()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
Packet.DecodePayload("2:4\uffff", new DecodePayloadBadFormat_DecodeCallback());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
477
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ParserTests/TestsParser.cs
vendored
Normal file
477
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/ParserTests/TestsParser.cs
vendored
Normal file
@@ -0,0 +1,477 @@
|
||||
using Quobject.EngineIoClientDotNet.Modules;
|
||||
using Quobject.EngineIoClientDotNet.Parser;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
using Xunit;
|
||||
|
||||
namespace Quobject.EngineIoClientDotNet_Tests.ParserTests
|
||||
{
|
||||
public class TestsParser
|
||||
{
|
||||
|
||||
public interface IPacketTest
|
||||
{
|
||||
Packet GetPacket();
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeTests()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var testList = new List<IPacketTest>()
|
||||
{
|
||||
new EncodeAsStringCallback(),
|
||||
new DecodeAsPacketCallback(),
|
||||
new NoDataCallback(),
|
||||
new EncodeOpenPacket(),
|
||||
new EncodeClosePacket(),
|
||||
new EncodePingPacket(),
|
||||
new EncodePongPacket(),
|
||||
new EncodeMessagePacket(),
|
||||
new EncodeUTF8SpecialCharsPacket(),
|
||||
new EncodeUpgradePacket(),
|
||||
new EncodeFormat1(),
|
||||
new EncodeFormat2(),
|
||||
|
||||
|
||||
};
|
||||
|
||||
foreach (var test in testList)
|
||||
{
|
||||
Parser.EncodePacket(test.GetPacket(), (IEncodeCallback) test);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class EncodeAsStringCallback : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Assert.IsType<string>(data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE, "test");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class DecodeAsPacketCallback : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Assert.IsType<Packet>(Parser.DecodePacket((string) data));
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE, "test");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public class NoDataCallback : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.MESSAGE, p.Type);
|
||||
Assert.Null(p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeOpenPacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
private static string Json = "{\"some\":\"json\"}";
|
||||
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.OPEN, p.Type);
|
||||
Assert.Equal(Json, p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.OPEN, Json);
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeClosePacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.CLOSE, p.Type);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.CLOSE);
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodePingPacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.PING, p.Type);
|
||||
Assert.Equal("1", p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.PING, "1");
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodePongPacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.PONG, p.Type);
|
||||
Assert.Equal("1", p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.PONG, "1");
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeMessagePacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.MESSAGE, p.Type);
|
||||
Assert.Equal("aaa", p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE, "aaa");
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeUTF8SpecialCharsPacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.MESSAGE, p.Type);
|
||||
Assert.Equal("utf8 — string", p.Data);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE, "utf8 — string");
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeUpgradePacket : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Packet p = Parser.DecodePacket((string) data);
|
||||
Assert.Equal(Packet.UPGRADE, p.Type);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.UPGRADE);
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeFormat1 : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
var dataString = data as string;
|
||||
var r = new Regex(@"[0-9]", RegexOptions.IgnoreCase);
|
||||
Assert.True(r.Match(dataString).Success);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
public class EncodeFormat2 : IEncodeCallback, IPacketTest
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
var dataString = data as string;
|
||||
Assert.Equal("4test", dataString);
|
||||
}
|
||||
|
||||
public Packet GetPacket()
|
||||
{
|
||||
return new Packet(Packet.MESSAGE, "test");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class EncodePayloadsCallback : IEncodeCallback
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Assert.IsType<byte[]>(data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodePayloads()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var packets = new Packet[] {new Packet(Packet.PING), new Packet(Packet.PONG),};
|
||||
Parser.EncodePayload(packets, new EncodePayloadsCallback());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class EncodeAndDecodePayloads_EncodeCallback : IEncodeCallback
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Parser.DecodePayload((byte[]) data, new EncodeAndDecodePayloads_DecodeCallback());
|
||||
}
|
||||
|
||||
public class EncodeAndDecodePayloads_DecodeCallback : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
bool isLast = index + 1 == total;
|
||||
Assert.True(isLast);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAndDecodePayloads()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var packets = new Packet[] {new Packet(Packet.MESSAGE, "a"),};
|
||||
Parser.EncodePayload(packets, new EncodeAndDecodePayloads_EncodeCallback());
|
||||
|
||||
}
|
||||
|
||||
public class EncodeAndDecodePayloads_EncodeCallback2 : IEncodeCallback
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Parser.DecodePayload((byte[]) data, new EncodeAndDecodePayloads_DecodeCallback2());
|
||||
}
|
||||
|
||||
public class EncodeAndDecodePayloads_DecodeCallback2 : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
var isLast = index + 1 == total;
|
||||
Assert.Equal(isLast ? Packet.PING : Packet.MESSAGE, packet.Type);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAndDecodePayloads2()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var packets = new Packet[] {new Packet(Packet.MESSAGE, "a"), new Packet(Packet.PING),};
|
||||
Parser.EncodePayload(packets, new EncodeAndDecodePayloads_EncodeCallback2());
|
||||
|
||||
}
|
||||
|
||||
public class EncodeAndDecodeEmptyPayloads_EncodeCallback : IEncodeCallback
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Parser.DecodePayload((byte[]) data, new EncodeAndDecodeEmptyPayloads_DecodeCallback());
|
||||
}
|
||||
|
||||
public class EncodeAndDecodeEmptyPayloads_DecodeCallback : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
Assert.Equal(Packet.OPEN, packet.Type);
|
||||
var isLast = index + 2 == total;
|
||||
Assert.True(isLast);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAndDecodeEmptyPayloads()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var packets = new Packet[] {};
|
||||
Parser.EncodePayload(packets, new EncodeAndDecodeEmptyPayloads_EncodeCallback());
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class EncodeAndDecodeBinaryContents_EncodeCallback : IEncodeCallback
|
||||
{
|
||||
public void Call(object data)
|
||||
{
|
||||
Parser.DecodePayload((byte[]) data, new EncodeAndDecodeBinaryContents_DecodeCallback());
|
||||
}
|
||||
|
||||
public class EncodeAndDecodeBinaryContents_DecodeCallback : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
Assert.Equal(Packet.MESSAGE, packet.Type);
|
||||
var isLast = index + 1 == total;
|
||||
if (!isLast)
|
||||
{
|
||||
Assert.Equal(FirstBuffer(), packet.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(SecondBuffer(), packet.Data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeAndDecodeBinaryContents()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var firstBuffer = FirstBuffer();
|
||||
var secondBuffer = SecondBuffer();
|
||||
|
||||
var packets = new Packet[]
|
||||
{new Packet(Packet.MESSAGE, firstBuffer), new Packet(Packet.MESSAGE, secondBuffer)};
|
||||
Parser.EncodePayload(packets, new EncodeAndDecodeBinaryContents_EncodeCallback());
|
||||
|
||||
}
|
||||
|
||||
private static byte[] SecondBuffer()
|
||||
{
|
||||
var secondBuffer = new byte[4];
|
||||
for (int i = 0; i < secondBuffer.Length; i++)
|
||||
{
|
||||
secondBuffer[i] = (byte) (5 + i);
|
||||
}
|
||||
return secondBuffer;
|
||||
}
|
||||
|
||||
private static byte[] FirstBuffer()
|
||||
{
|
||||
var firstBuffer = new byte[5];
|
||||
for (int i = 0; i < firstBuffer.Length; i++)
|
||||
{
|
||||
firstBuffer[i] = (byte) i;
|
||||
}
|
||||
return firstBuffer;
|
||||
}
|
||||
|
||||
private static byte[] ThirdBuffer()
|
||||
{
|
||||
var result = new byte[123];
|
||||
for (int i = 0; i < result.Length; i++)
|
||||
{
|
||||
result[i] = (byte) i;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public class EncodeMixedBinaryAndStringContents_EncodeCallback : IEncodeCallback
|
||||
{
|
||||
|
||||
public void Call(object data)
|
||||
{
|
||||
Parser.DecodePayload((byte[]) data, new EncodeMixedBinaryAndStringContents_DecodeCallback());
|
||||
}
|
||||
|
||||
public class EncodeMixedBinaryAndStringContents_DecodeCallback : IDecodePayloadCallback
|
||||
{
|
||||
|
||||
public bool Call(Packet packet, int index, int total)
|
||||
{
|
||||
if (index == 0)
|
||||
{
|
||||
Assert.Equal(Packet.MESSAGE, packet.Type);
|
||||
Assert.Equal(ThirdBuffer(), packet.Data);
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
Assert.Equal(Packet.MESSAGE, packet.Type);
|
||||
Assert.Equal("hello", packet.Data);
|
||||
}
|
||||
else
|
||||
{
|
||||
Assert.Equal(Packet.CLOSE, packet.Type);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EncodeMixedBinaryAndStringContents()
|
||||
{
|
||||
LogManager.SetupLogManager();
|
||||
var log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod());
|
||||
log.Info("Start");
|
||||
|
||||
var packets = new Packet[]
|
||||
{
|
||||
new Packet(Packet.MESSAGE, ThirdBuffer()),
|
||||
new Packet(Packet.MESSAGE, "hello"),
|
||||
new Packet(Packet.CLOSE),
|
||||
};
|
||||
Parser.EncodePayload(packets, new EncodeMixedBinaryAndStringContents_EncodeCallback());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
36
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/Properties/AssemblyInfo.cs
vendored
Normal file
36
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/Properties/AssemblyInfo.cs
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("EngineIoClientDotNet.Tests2.net35")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("EngineIoClientDotNet.Tests2.net35")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("ba788bbe-0fe8-4c2f-8a02-457a5e9e2703")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
11
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/app.config
vendored
Normal file
11
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/app.config
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="SuperSocket.ClientEngine" publicKeyToken="ee9af13f57f00acc" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-0.9.0.0" newVersion="0.9.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
9
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/packages.config
vendored
Normal file
9
ThirdParty/EngineIoClientDotNet/Src/EngineIoClientDotNet.Tests.net35/packages.config
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="more.xunit.runner.visualstudio" version="2.3.1" targetFramework="net35" developmentDependency="true" />
|
||||
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net35" />
|
||||
<package id="SuperSocket.ClientEngine.Core" version="0.9.0" targetFramework="net35" />
|
||||
<package id="System.Threading.Tasks.Unofficial" version="3.1" targetFramework="net35" />
|
||||
<package id="WebSocket4Net" version="0.15.1" targetFramework="net35" />
|
||||
<package id="xunit" version="1.9.2" targetFramework="net35" />
|
||||
</packages>
|
||||
Reference in New Issue
Block a user