示例#1
0
        public void TestConnectFuture()
        {
            DefaultConnectFuture future = new DefaultConnectFuture();

            Assert.IsFalse(future.Done);
            Assert.IsFalse(future.Connected);
            Assert.IsNull(future.Session);
            Assert.IsNull(future.Exception);

            TestThread thread = new TestThread(future);

            thread.Start();

            IoSession session = new DummySession();

            future.SetSession(session);
            thread.Join();

            Assert.IsTrue(thread.success);
            Assert.IsTrue(future.Done);
            Assert.IsTrue(future.Connected);
            Assert.AreSame(session, future.Session);
            Assert.IsNull(future.Exception);

            future = new DefaultConnectFuture();
            thread = new TestThread(future);
            thread.Start();
            future.Exception = new IOException();
            thread.Join();

            Assert.IsTrue(thread.success);
            Assert.IsTrue(future.Done);
            Assert.IsFalse(future.Connected);
            Assert.IsTrue(future.Exception is IOException);

            try
            {
                IoSession s = future.Session;
                Assert.Fail("IOException should be thrown.");
            }
            catch (Exception)
            {
                // Signifies a successful test execution
                Assert.IsTrue(true);
            }
        }