Example #1
0
        public void TestConnectionStreamLotsOfDataAndCheckAllReads()
        {
            var connStream = new ConnectionStream();
            var producerStream = new ProducerStream(connStream);
            var consumerStream = new ConsumerStream(connStream);
            var t = new Task(() =>
            {
                var streamWriter = new StreamWriter(producerStream);
                for (int i = 0; i < 1000; i++) streamWriter.WriteLine("mother f*****g stream crap " + i);
                streamWriter.Close();
            });

            t.Start();

            Thread.Sleep(1000);

            int j = 0;
            using (var sr = new StreamReader(consumerStream))
            {
                var result = sr.ReadLine();
                Assert.AreEqual(result, "mother f*****g stream crap " + j);
                j++;
            }

            Task.WaitAll(t);
        }
Example #2
0
        public void TestConnectionStream()
        {
            var connStream = new ConnectionStream();
            var producerStream = new ProducerStream(connStream);
            var consumerStream = new ConsumerStream(connStream);

            var t = new Task(() =>
                                 {
                                     var streamWriter = new StreamWriter(producerStream);
                                     streamWriter.WriteLine("mother f*****g stream crap");
                                     streamWriter.Close();
                                 });

            t.Start();

            var sr = new StreamReader(consumerStream);
            var result = sr.ReadToEnd();
            Assert.AreEqual("mother f*****g stream crap\r\n", result);

            Task.WaitAll(t);
        }
Example #3
0
        public void TestConnectionStreamLotsOfData()
        {
            var connStream = new ConnectionStream();
            var producerStream = new ProducerStream(connStream);
            var consumerStream = new ConsumerStream(connStream);
            var t = new Task(() =>
            {
                var streamWriter = new StreamWriter(producerStream);
                for (int i = 0; i < 1000; i++) streamWriter.WriteLine("mother f*****g stream crap " + i);
                streamWriter.Close();
            });

            t.Start();

            Thread.Sleep(1000);

            var sr = new StreamReader(consumerStream);                   
            var result = sr.ReadToEnd();
            Assert.IsTrue(result.StartsWith("mother f*****g stream crap 0"));
            Assert.IsTrue(result.EndsWith("mother f*****g stream crap 999\r\n"));
            
            Task.WaitAll(t);
        }
Example #4
0
        public void TestConnectionClientTermination()
        {
            var connStream = new ConnectionStream();
            var producerStream = new ProducerStream(connStream);
            var consumerStream = new ConsumerStream(connStream);
            var t = new Task(() =>
            {
                var streamWriter = new StreamWriter(producerStream);
                for (int i = 0; i < 1000; i++) streamWriter.WriteLine("mother f*****g stream crap " + i);
                streamWriter.Close();
            });

            t.Start();

            // Thread.Sleep(1000);

            var sr = new StreamReader(consumerStream);
            sr.Close();

            Task.WaitAll(t);
        }
Example #5
0
        public void TestConnectionStreamBuffering()
        {
            var connStream = new ConnectionStream();
            var producerStream = new ProducerStream(connStream);
            var consumerStream = new ConsumerStream(connStream);
            var t = new Task(() =>
            {
                var streamWriter = new StreamWriter(producerStream);
                for (int i = 0; i < 1000; i++) streamWriter.WriteLine("mother f*****g stream crap " + i);
                streamWriter.Close();
            });

            t.Start();
            Task.WaitAll(t);

            using (var sr = new StreamReader(consumerStream))
            {
                // read one line
                var line = sr.ReadLine();
                Assert.AreEqual("mother f*****g stream crap 0", line);
            }

        }