Ejemplo n.º 1
0
        public void Response_stream_is_rebuffered()
        {
            // strategy:
            // reuse a single buffer for all writes.
            // don't spool through the scheduler until after app is done writing.
            //
            // if implementation simply keeps a reference to the supplied buffer, 
            // its contents will be the contents of the final write and the
            // received body will be garbage. consumer must copy out of
            // producer's buffer.

            byte[] b = new byte[6];

            Func<string, ArraySegment<byte>> bytes = s =>
            {
                var sb = Encoding.ASCII.GetBytes(s);
                System.Buffer.BlockCopy(sb, 0, b, 0, sb.Length);
                return new ArraySegment<byte>(b, 0, sb.Length);
            };

            var app = new StaticApp(null, null, (write, end, cancel) =>
            {
                write(bytes("alpha "), null);
                write(bytes("beta "), null);
                write(bytes("gamma "), null);
                write(bytes("delta "), null);
                write(bytes("omega."), null);
                end(null);
            });

            var scheduler = new MockScheduler();
            var middleware = new RescheduleCallbacksMiddleware(app.Invoke, scheduler);
            var responseDelegate = new MockResponseDelegate();

            BufferingConsumer bodyConsumer = null;

            scheduler.Post(() =>
                {
                    middleware.Invoke(new Dictionary<string, object>(), (status, headers, body) =>
                        {
                            bodyConsumer = body.Consume();
                        }, e => { });
                });

            scheduler.Start();

            var bodyString = bodyConsumer.Buffer.GetString();

            Assert.That(bodyString, Is.EqualTo("alpha beta gamma delta omega."));
        }
Ejemplo n.º 2
0
 public void SetUp()
 {
     mockResponseDelegate = new MockResponseDelegate();
 }
Ejemplo n.º 3
0
 public void SetUp()
 {
     mockResponseDelegate = new MockResponseDelegate();
 }