public void Test_Unregister() { using (DdeContext context = new DdeContext()) { EventListener listener = new EventListener(); context.Unregister += listener.OnEvent; context.Initialize(); using (DdeServer server = new TestServer(ServiceName)) { server.Register(); server.Unregister(); } Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); } }
public void Test_StartAdvise_Variation_1() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Advise += listener.OnEvent; client.Connect(); client.StartAdvise(ItemName, 1, true, Timeout); server.Advise(TopicName, ItemName); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); DdeAdviseEventArgs args = (DdeAdviseEventArgs)listener.Events[0]; Assert.AreEqual(ItemName, args.Item); Assert.AreEqual(1, args.Format); Assert.AreEqual(TestData, Encoding.ASCII.GetString(args.Data)); Assert.AreEqual(TestData, args.Text); } } }
public void Test_IsConnected_Variation_4() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Disconnected += listener.OnEvent; client.Connect(); server.Disconnect(); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); Assert.IsFalse(client.IsConnected); } } }
public void Test_Disconnected_Variation_3() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Disconnected += listener.OnEvent; client.Connect(); client.Dispose(); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); DdeDisconnectedEventArgs args = (DdeDisconnectedEventArgs)listener.Events[0]; Assert.IsFalse(args.IsServerInitiated); Assert.IsTrue(args.IsDisposed); } } }
public void Test_BeginStartAdvise_Variation_3() { using (TestServer server = new TestServer(ServiceName)) { server.Register(); server.SetData(TopicName, ItemName, 1, Encoding.ASCII.GetBytes(TestData)); using (DdeClient client = new DdeClient(ServiceName, TopicName)) { EventListener listener = new EventListener(); client.Advise += listener.OnEvent; client.Connect(); IAsyncResult ar = client.BeginStartAdvise(ItemName, 1, true, true, null, null, "MyStateObject"); Assert.IsTrue(ar.AsyncWaitHandle.WaitOne(Timeout, false)); server.Advise(TopicName, ItemName); Assert.IsTrue(listener.Received.WaitOne(Timeout, false)); DdeAdviseEventArgs args = (DdeAdviseEventArgs)listener.Events[0]; Assert.AreEqual(ItemName, args.Item); Assert.AreEqual(1, args.Format); Assert.AreEqual("MyStateObject", args.State); Assert.AreEqual(TestData, Encoding.ASCII.GetString(args.Data)); } } }