Ejemplo n.º 1
0
 public TestNetwork()
 {
     var writeBuffer = new TestBuffer();
     var readBuffer = new TestBuffer();
     Server = new TestStream(writeBuffer, readBuffer);
     Client = new TestStream(readBuffer, writeBuffer);
 }
Ejemplo n.º 2
0
        public void test_read_block()
        {
            var testStream = new TestStream();

            var toWrite = new ManualResetEvent(false);

            var w = new Thread(() =>
                                   {
                                       Console.WriteLine("w: Waiting to write..");
                                       toWrite.WaitOne();

                                       Console.WriteLine("w: Ready to write..");
                                       Thread.Sleep(100);
                                       Console.WriteLine("w: Writting..");

                                       var streamWriter = new StreamWriter(testStream, Encoding.ASCII);

                                       streamWriter.WriteLine("ABC");

                                       streamWriter.Flush();

                                       Console.WriteLine("w: done.");
                                   }) { Name = "w" };
            w.Start();

            var r = new Thread(() =>
                                   {
                                       Console.WriteLine("r: about ot start read..");
                                       var streamReader = new StreamReader(testStream, Encoding.ASCII);
                                       Console.WriteLine("r: should hang a bit..");
                                       string readLine = streamReader.ReadLine();

                                       Assert.That(readLine == "ABC");

                                       Console.WriteLine("r: done.");
                                   }) { Name = "r" };
            r.Start();

            Console.WriteLine("About to let write go..");
            Thread.Sleep(100);
            toWrite.Set();
            Console.WriteLine("Let write go..");

            w.Join();
            r.Join();
        }
Ejemplo n.º 3
0
        public void test()
        {
            var testStream = new TestStream();

            var streamWriter = new StreamWriter(testStream, Encoding.ASCII);

            streamWriter.WriteLine("ABC");

            streamWriter.Flush();

            var streamReader = new StreamReader(testStream, Encoding.ASCII);
            string readLine = streamReader.ReadLine();

            Assert.That(readLine == "ABC");
        }