Ejemplo n.º 1
0
        public void ShouldWaitForBuffer()
        {
            var receiveCalled = false;
            var receiveWaiter = new ManualResetEvent(false);
            var worker        = new TestWorkScheduler();

            worker.QueueForeverAction = (action, span) =>
            {
                Task.Factory.StartNew(() =>
                {
                    while (true)
                    {
                        action();
                    }
                });
            };
            var bufferAllocator = new TestBufferAllocator();
            var connection      = new TestConnection();

            //var io = new ConnectionIoActor(worker);

            bufferAllocator.AllocateFunc = i => new ArraySegment <byte>();
            connection.ReceiveAction     = (buffer) => {
                receiveCalled = true;
                receiveWaiter.Set();
                return(new Task <int>(() => 19));
            };
            //io.Receive(new byte[128], connection, new BandwidthController(), null, null );
            bufferAllocator.AllocateFunc = i => new ArraySegment <byte>(new byte[128]);
            receiveWaiter.WaitOne(100);

            Assert.IsTrue(receiveCalled, "Receive was not called.");
        }
        public void ShouldWaitForBuffer()
        {
            var receiveCalled = false;
            var receiveWaiter = new ManualResetEvent(false);
            var worker = new TestWorkScheduler();
            worker.QueueForeverAction = (action, span) =>
            {
                Task.Factory.StartNew(() =>
                {
                    while (true) action();
                });
            };
            var bufferAllocator = new TestBufferAllocator();
            var connection = new TestConnection();
            //var io = new ConnectionIoActor(worker);

            bufferAllocator.AllocateFunc= i => new ArraySegment<byte>();
            connection.ReceiveAction = (buffer) => {
                receiveCalled = true;
                receiveWaiter.Set();
                return new Task<int>(()=>19);
            };
            //io.Receive(new byte[128], connection, new BandwidthController(), null, null );
            bufferAllocator.AllocateFunc = i => new ArraySegment<byte>(new byte[128]);
            receiveWaiter.WaitOne(100);

            Assert.IsTrue(receiveCalled, "Receive was not called.");
        }