public void WriteByte()
        {
            const int length = 1000;

            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);

                var bytes = ArrayHelpers.CreateByteArray(length);
                for (int index = 0; index < bytes.Length; index++)
                {
                    stream.WriteByte(bytes[index]);
                }
                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer <byte>());

                stream.SetLength(0);
                stream.Position = 1;
                bytes           = ArrayHelpers.CreateByteArray(length);
                for (int index = 1; index < bytes.Length; index++)
                {
                    stream.WriteByte(bytes[index]);
                }
                stream.Position = 0;
                stream.WriteByte(bytes[0]);
                memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer <byte>());
            }
        }
Beispiel #2
0
        public static void ReadWrite()
        {
            var length = 1000;

            using (var manager = new UmsManager(FileAccess.ReadWrite, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.ReadWriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                var copy  = bytes.Copy();
                stream.Write(copy, 0, length);

                var memory = manager.ToArray();
                Assert.True(ArrayHelpers.Comparer <byte>().Equals(bytes, memory));

                stream.Seek(0, SeekOrigin.Begin);
                byte[] read = UmsReadTests.ReadAllBytes(stream);
                Assert.Equal(stream.Position, read.Length);

                byte[] current = manager.ToArray();
                Assert.True(ArrayHelpers.Comparer <byte>().Equals(read, current));
                Assert.True(ArrayHelpers.Comparer <byte>().Equals(read, bytes));

                stream.Write(new byte[0], 0, 0);
            }
        }
        public void ReadWrite()
        {
            const int length = 1000;

            using (var manager = new UmsManager(FileAccess.ReadWrite, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.ReadWriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                var copy  = bytes.Copy();
                Write(stream, copy, 0, length);

                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer <byte>());

                stream.Seek(0, SeekOrigin.Begin);
                byte[] read = ReadAllBytes(stream);
                Assert.Equal(stream.Position, read.Length);

                byte[] current = manager.ToArray();
                Assert.Equal(current, read, ArrayHelpers.Comparer <byte>());
                Assert.Equal(bytes, read, ArrayHelpers.Comparer <byte>());

                Write(stream, new byte[0], 0, 0);
            }
        }
Beispiel #4
0
        public static void ReadWrite()
        {
            const int length = 1000;
            using (var manager = new UmsManager(FileAccess.ReadWrite, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.ReadWriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                var copy = bytes.Copy();
                stream.Write(copy, 0, length);

                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>());

                stream.Seek(0, SeekOrigin.Begin);
                byte[] read = UmsReadTests.ReadAllBytes(stream);
                Assert.Equal(stream.Position, read.Length);

                byte[] current = manager.ToArray();
                Assert.Equal(current, read, ArrayHelpers.Comparer<byte>());
                Assert.Equal(bytes, read, ArrayHelpers.Comparer<byte>());

                stream.Write(new byte[0], 0, 0);
            }
        }
Beispiel #5
0
        public static void WriteByte()
        {
            const int length = 1000;
            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);

                var bytes = ArrayHelpers.CreateByteArray(length);
                for (int index = 0; index < bytes.Length; index++)
                {
                    stream.WriteByte(bytes[index]);
                }
                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>());

                stream.SetLength(0);
                stream.Position = 1;
                bytes = ArrayHelpers.CreateByteArray(length);
                for (int index = 1; index < bytes.Length; index++)
                {
                    stream.WriteByte(bytes[index]);
                }
                stream.Position = 0;
                stream.WriteByte(bytes[0]);
                memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>());
            }
        }
Beispiel #6
0
        public static void ReadWriteByte()
        {
            var length = 1000;

            using (var manager = new UmsManager(FileAccess.ReadWrite, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.ReadWriteUmsInvariants(stream);

                var bytes = ArrayHelpers.CreateByteArray(length);

                for (int index = 0; index < bytes.Length; index++)
                {
                    byte byteToWrite = bytes[index];
                    stream.WriteByte(byteToWrite);
                    stream.Position--;
                    int read = stream.ReadByte();
                    Assert.Equal((byte)read, byteToWrite);
                }

                var memory = manager.ToArray();

                Assert.True(ArrayHelpers.Comparer <byte>().Equals(bytes, memory));
            }
        }
        public void Write()
        {
            const int length = 1000;

            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                Write(stream, bytes.Copy(), 0, length);
                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer <byte>());

                Write(stream, new byte[0], 0, 0);

                stream.SetLength(1);
                Assert.Equal(1, stream.Length);
                stream.SetLength(4);
                Assert.Equal(4, stream.Length);
                stream.SetLength(0);
                Assert.Equal(0, stream.Length);

                stream.Position = 1;
                bytes           = ArrayHelpers.CreateByteArray(length - 1);
                Write(stream, bytes, 0, length - 1);
                memory = manager.ToArray();
                for (int i = 0; i < bytes.Length; i++)
                {
                    Assert.Equal(bytes[i], memory[i + 1]);
                }

                Assert.True(stream.WriteAsync(bytes, 0, bytes.Length, new CancellationToken(true)).IsCanceled);

                stream.Position = 0;
                bytes           = ArrayHelpers.CreateByteArray(length);
                for (int i = 0; i < 4; i++)
                {
                    Task t = stream.WriteAsync(bytes, i * (bytes.Length / 4), bytes.Length / 4);
                    Assert.True(t.Status == TaskStatus.RanToCompletion);
                }
                Assert.Equal(bytes, manager.ToArray(), ArrayHelpers.Comparer <byte>());
            }
        }
Beispiel #8
0
        public static void Write()
        {
            const int length = 1000;
            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                stream.Write(bytes.Copy(), 0, length);
                var memory = manager.ToArray();
                Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>());

                stream.Write(new byte[0], 0, 0);

                stream.SetLength(1);
                Assert.Equal(1, stream.Length);
                stream.SetLength(4);
                Assert.Equal(4, stream.Length);
                stream.SetLength(0);
                Assert.Equal(0, stream.Length);

                stream.Position = 1;
                bytes = ArrayHelpers.CreateByteArray(length - 1);
                stream.Write(bytes, 0, length - 1);
                memory = manager.ToArray();
                for (int i = 0; i < bytes.Length; i++)
                {
                    Assert.Equal(bytes[i], memory[i + 1]);
                }
                
                Assert.True(stream.WriteAsync(bytes, 0, bytes.Length, new CancellationToken(true)).IsCanceled);

                stream.Position = 0;
                bytes = ArrayHelpers.CreateByteArray(length);
                for (int i = 0; i < 4; i++)
                {
                    Task t = stream.WriteAsync(bytes, i * (bytes.Length / 4), bytes.Length / 4);
                    Assert.True(t.Status == TaskStatus.RanToCompletion);
                }
                Assert.Equal(bytes, manager.ToArray(), ArrayHelpers.Comparer<byte>());
            }
        }
Beispiel #9
0
 void ReadToEnd(UmsManager manager)
 {
     Stream stream = manager.Stream;
     if (stream.CanRead)
     {
         byte[] read = ReadAllBytes(stream);
         Assert.Equal(stream.Position, read.Length);
         Assert.True(ArrayHelpers.Comparer<byte>().Equals(read, manager.ToArray()));
     }
     else
     {
         Assert.Throws<NotSupportedException>(() => stream.ReadByte());
     }
 }
Beispiel #10
0
        void ReadToEnd(UmsManager manager)
        {
            Stream stream = manager.Stream;

            if (stream.CanRead)
            {
                byte[] read = ReadAllBytes(stream);
                Assert.Equal(stream.Position, read.Length);
                Assert.Equal(manager.ToArray(), read, ArrayHelpers.Comparer <byte>());
            }
            else
            {
                Assert.Throws <NotSupportedException>(() => stream.ReadByte());
            }
        }
Beispiel #11
0
        public static void Write()
        {
            var length = 1000;
            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                stream.Write(bytes.Copy(), 0, length);

                var memory = manager.ToArray();

                Assert.True(ArrayHelpers.Comparer<byte>().Equals(bytes, memory));

                stream.Write(new byte[0], 0, 0);
            }
        }
Beispiel #12
0
        public static void WriteByte()
        {
            var length = 1000;
            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);

                var bytes = ArrayHelpers.CreateByteArray(length);

                for (int index = 0; index < bytes.Length; index++)
                {
                    stream.WriteByte(bytes[index]);
                }

                var memory = manager.ToArray();

                Assert.True(ArrayHelpers.Comparer<byte>().Equals(bytes, memory));
            }
        }
Beispiel #13
0
        public static void Write()
        {
            const int length = 1000;

            using (var manager = new UmsManager(FileAccess.Write, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.WriteUmsInvariants(stream);
                Assert.Equal(stream.Length, length);

                var bytes = ArrayHelpers.CreateByteArray(length);
                stream.Write(bytes.Copy(), 0, length);

                var memory = manager.ToArray();

                Assert.Equal(bytes, memory, ArrayHelpers.Comparer <byte>());

                stream.Write(new byte[0], 0, 0);
            }
        }
Beispiel #14
0
        public static void ReadWriteByte()
        {
            const int length = 1000;
            using (var manager = new UmsManager(FileAccess.ReadWrite, length))
            {
                UnmanagedMemoryStream stream = manager.Stream;
                UmsTests.ReadWriteUmsInvariants(stream);

                var bytes = ArrayHelpers.CreateByteArray(length);

                for (int index = 0; index < bytes.Length; index++)
                {
                    byte byteToWrite = bytes[index];
                    stream.WriteByte(byteToWrite);
                    stream.Position--;
                    int read = stream.ReadByte();
                    Assert.Equal((byte)read, byteToWrite);
                }

                var memory = manager.ToArray();

                Assert.Equal(bytes, memory, ArrayHelpers.Comparer<byte>());
            }
        }