/// <summary> /// Runs a client disconnect test on the given listener and connection. /// </summary> /// <param name="listener">The listener to test.</param> /// <param name="connection">The connection to test.</param> internal static void RunClientDisconnectTest(ConnectionListener listener, SCMTOperationCore.Connection.Connection connection) { ManualResetEvent mutex = new ManualResetEvent(false); ManualResetEvent mutex2 = new ManualResetEvent(false); listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { args.Connection.Disconnected += delegate(object sender2, DisconnectedEventArgs args2) { mutex2.Set(); }; mutex.Set(); }; listener.Start(); connection.Connect(); mutex.WaitOne(); connection.Close(); mutex2.WaitOne(); }
/// <summary> /// Runs a general test on the given listener and connection. /// </summary> /// <param name="listener">The listener to test.</param> /// <param name="connection">The connection to test.</param> internal static void RunClientToServerTest(ConnectionListener listener, SCMTOperationCore.Connection.Connection connection, int dataSize, SendOption sendOption) { //Setup meta stuff byte[] data = BuildData(dataSize); ManualResetEvent mutex = new ManualResetEvent(false); ManualResetEvent mutex2 = new ManualResetEvent(false); //Setup listener listener.NewConnection += delegate(object sender, NewConnectionEventArgs args) { args.Connection.DataReceived += delegate(object innerSender, DataReceivedEventArgs innerArgs) { Trace.WriteLine("Data was received correctly."); Assert.AreEqual(data.Length, innerArgs.Bytes.Length); for (int i = 0; i < data.Length; i++) { Assert.AreEqual(data[i], innerArgs.Bytes[i]); } Assert.AreEqual(sendOption, innerArgs.SendOption); mutex2.Set(); }; mutex.Set(); }; listener.Start(); //Connect connection.Connect(); mutex.WaitOne(); connection.SendBytes(data, sendOption); //Wait until data is received mutex2.WaitOne(); }