Example #1
0
        public void ReadNull()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write(null);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.IsNull(channel.Read());
        }
Example #2
0
        public void ReadString()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));

            output.Write("foo");
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual("foo", channel.Read());
        }
Example #3
0
        public void ReadByte()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));
            byte          bt     = 64;

            output.Write(bt);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(bt, channel.Read());
        }
Example #4
0
        public void ReadCharacter()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));
            char          ch     = 'a';

            output.Write(ch);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(ch, channel.Read());
        }
Example #5
0
        public void ReadLongInteger()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));
            long          ln     = long.MaxValue;

            output.Write(ln);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(ln, channel.Read());
        }
Example #6
0
        public void ReadShortInteger()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));
            short         sh     = short.MaxValue;

            output.Write(sh);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(sh, channel.Read());
        }
Example #7
0
        public void ReadDecimal()
        {
            MemoryStream  stream = new MemoryStream();
            OutputChannel output = new OutputChannel(new BinaryWriter(stream));
            decimal       dc     = 12.34m;

            output.Write(dc);
            stream.Seek(0, SeekOrigin.Begin);

            InputChannel channel = new InputChannel(new BinaryReader(stream));

            Assert.AreEqual(dc, channel.Read());
        }
Example #8
0
        public void WriteNull()
        {
            MemoryStream  stream  = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            channel.Write(null);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Null, reader.ReadByte());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
Example #9
0
        public void WriteFloat()
        {
            MemoryStream  stream  = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            channel.Write((float)123.45);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Single, reader.ReadByte());
            Assert.AreEqual((float)123.45, reader.ReadSingle());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
Example #10
0
        public void WriteDecimal()
        {
            MemoryStream  stream  = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            decimal dc = 12.34m;

            channel.Write(dc);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Decimal, reader.ReadByte());
            Assert.AreEqual(dc, reader.ReadDecimal());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
Example #11
0
        public void WriteLongInteger()
        {
            MemoryStream  stream  = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            long ln = 123;

            channel.Write(ln);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Long, reader.ReadByte());
            Assert.AreEqual(ln, reader.ReadInt64());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
Example #12
0
        public void WriteShortInteger()
        {
            MemoryStream  stream  = new MemoryStream();
            OutputChannel channel = new OutputChannel(new BinaryWriter(stream));

            short sh = 123;

            channel.Write(sh);

            stream.Seek(0, SeekOrigin.Begin);

            BinaryReader reader = new BinaryReader(stream);

            Assert.AreEqual((byte)Types.Short, reader.ReadByte());
            Assert.AreEqual(sh, reader.ReadInt16());
            Assert.AreEqual(-1, reader.PeekChar());

            reader.Close();
        }
Example #13
0
        public void SendMessagesToActor()
        {
            int             total = 0;
            EventWaitHandle wait  = new AutoResetEvent(false);

            Actor actor = new LambdaActor(c => { total += (int)c; if (total >= 6)
                                                 {
                                                     wait.Set();
                                                 }
                                          });

            ActorSystem system = new ActorSystem();
            var         server = new TcpServer("localhost", 3001, system);

            var result = system.ActorOf(actor, "myactor");
            var path   = result.Path.ToString();

            server.Start();

            var client = new System.Net.Sockets.TcpClient();

            client.Connect("localhost", 3001);
            var channel = new OutputChannel(new System.IO.BinaryWriter(client.GetStream()));

            channel.Write(path);
            channel.Write(1);
            channel.Write(path);
            channel.Write(2);
            channel.Write(path);
            channel.Write(3);

            wait.WaitOne();

            Assert.AreEqual(6, total);

            client.Close();
            server.Stop();
            system.Shutdown();
        }