Ejemplo n.º 1
0
        public void SeekToEnd()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");

            var result = stream.Position;

            stream.Seek(0, System.IO.SeekOrigin.Begin);
            stream.Seek(0, System.IO.SeekOrigin.End);

            Assert.Equal(result, stream.Position);
        }
Ejemplo n.º 2
0
        public void TwoSeeks()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            var initilPoisition = stream.Position;

            stream.Seek(-2, System.IO.SeekOrigin.Current);
            Assert.Equal(initilPoisition - 2, stream.Position);

            stream.Seek(-2, System.IO.SeekOrigin.Current);
            Assert.Equal(initilPoisition - 4, stream.Position);
            Assert.Equal(initilPoisition, stream.Length);
        }
Ejemplo n.º 3
0
        public void SeekToBegin()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            Assert.Equal(0, stream.Position);
        }
Ejemplo n.º 4
0
        public void SeekWithCurrent()
        {
            var stream = new FastMemoryWriter();

            stream.Write("JonnoJ");
            var result = stream.Position;

            stream.Seek(-1, System.IO.SeekOrigin.Current);

            Assert.Equal(result - 1, stream.Position);
        }
Ejemplo n.º 5
0
        public void ReadString()
        {
            var text   = "hello";
            var memory = new FastMemoryWriter();

            memory.Write(text);
            memory.Seek(0, SeekOrigin.Begin);

            var reader = new FastReader(memory);
            var result = reader.ReadString();

            Assert.Equal(text, result);
        }
Ejemplo n.º 6
0
        public void ReadWrongByteArray()
        {
            var bytes  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            var memory = new FastMemoryWriter();

            memory.WriteByteArray(bytes);
            memory.SetLength(9);
            memory.Seek(0, SeekOrigin.Begin);

            var reader = new FastReader(memory);

            Assert.Throws <EndOfStreamException>(() => reader.ReadByteArray());
        }
Ejemplo n.º 7
0
        public void ReadByteArray()
        {
            var bytes  = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, };
            var memory = new FastMemoryWriter();

            memory.WriteByteArray(bytes);
            memory.Seek(0, SeekOrigin.Begin);

            var reader = new FastReader(memory);
            var result = reader.ReadByteArray();

            Assert.True(result.SequenceEqual(bytes));
        }
Ejemplo n.º 8
0
            public void Bytes()
            {
                var bytes = new byte[] { 10, 10, 11, 12 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes);
                writer.Seek(0, SeekOrigin.Begin);

                var result = new byte[4];

                writer.Read(result);

                Assert.True(bytes.SequenceEqual(result));
            }
Ejemplo n.º 9
0
            public async Task CopyToAsync()
            {
                var bytes = new byte[] { 10, 10 };

                var writer = new FastMemoryWriter();

                writer.Write(bytes);
                writer.Seek(0, SeekOrigin.Begin);

                var stream = new MemoryStream();
                await writer.CopyToAsync(stream);

                var result = stream.ToArray();

                Assert.Equal(bytes, result);
            }
Ejemplo n.º 10
0
        public void Read()
        {
            var text      = "JonnoJ";
            var textBytes = Encoding.UTF8.GetBytes(text);

            var stream = new FastMemoryWriter();

            stream.Write(text);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            var result = new byte[stream.Length];

            stream.Read(result, 0, result.Length);

            // skip string length
            Assert.True(textBytes.SequenceEqual(result.Skip(4)));
        }
Ejemplo n.º 11
0
        public void ReadOnEmpty()
        {
            var text = "JonnoJ";

            var stream = new FastMemoryWriter();

            stream.Write(text);
            stream.Seek(0, System.IO.SeekOrigin.Begin);

            var result = new byte[stream.Length];
            var read   = stream.Read(result, 0, result.Length);

            Assert.Equal(result.Length, read);

            read = stream.Read(result, 0, result.Length);
            Assert.Equal(0, read);
        }