Exemplo n.º 1
0
        public void Flush_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions {
                Flush = null
            });

            Assert.Throws <NotSupportedException>(() => actionStream.Flush());
        }
Exemplo n.º 2
0
        public void Position_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions());

            Assert.Throws <NotSupportedException>(() =>
            {
                long actionStreamPosition = actionStream.Position;
            });
        }
Exemplo n.º 3
0
        public void Length_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions());

            Assert.Throws <NotSupportedException>(() =>
            {
                long actionStreamLength = actionStream.Length;
            });
        }
Exemplo n.º 4
0
        public void Seek_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions());

            Assert.Throws <NotSupportedException>(() =>
            {
                actionStream.Seek(1, SeekOrigin.Begin);
            });
        }
Exemplo n.º 5
0
        public void SetLength_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions());

            Assert.Throws <NotSupportedException>(() =>
            {
                actionStream.SetLength(1);
            });
        }
Exemplo n.º 6
0
        public void Write_Not_Supported()
        {
            ActionStream actionStream = new ActionStream(new StreamActions());

            Assert.Throws <NotSupportedException>(() =>
            {
                byte[] buffer = new byte[1];
                actionStream.Write(buffer, 0, 1);
            });
        }
Exemplo n.º 7
0
        public void Flush()
        {
            bool         flushed      = false;
            ActionStream actionStream = new ActionStream(new StreamActions {
                Flush = () => flushed = true
            });

            actionStream.Flush();

            Assert.True(flushed);
        }
Exemplo n.º 8
0
        public void Set_Length()
        {
            long         expectedLength = 0;
            ActionStream actionStream   = new ActionStream(new StreamActions
            {
                SetLength = length => expectedLength = length
            });

            actionStream.SetLength(10);

            Assert.Equal(10, expectedLength);
        }
Exemplo n.º 9
0
        public void Read_Content()
        {
            ActionStream actionStream = new ActionStream(new StreamActions {
                Read = (buffer, offset, count) =>
                {
                    for (int i = 0; i < count; i++)
                    {
                        buffer[offset + i] = (byte)i;
                    }
                    return(count);
                }
            });

            byte[] readBuffer = new byte[10];
            actionStream.Read(readBuffer, 0, readBuffer.Length);

            Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, readBuffer);
        }
Exemplo n.º 10
0
        public void Set_Position()
        {
            long         expectedOffset = -1;
            SeekOrigin   expectedOrigin = SeekOrigin.End;
            ActionStream actionStream   = new ActionStream(new StreamActions
            {
                Seek = (offset, origin) =>
                {
                    expectedOrigin = origin;
                    expectedOffset = offset;
                    return(offset);
                }
            });

            actionStream.Position = 10;

            Assert.Equal(10, expectedOffset);
            Assert.Equal(SeekOrigin.Begin, expectedOrigin);
        }
Exemplo n.º 11
0
        public void Seek(long testOffset, SeekOrigin testOrigin)
        {
            long         expectedOffset = 0;
            SeekOrigin   expectedOrigin = SeekOrigin.Begin;
            ActionStream actionStream   = new ActionStream(new StreamActions
            {
                Seek = (offset, origin) =>
                {
                    expectedOffset = offset;
                    expectedOrigin = origin;
                    return(0);
                }
            });

            actionStream.Seek(testOffset, testOrigin);

            Assert.Equal(testOffset, expectedOffset);
            Assert.Equal(testOrigin, expectedOrigin);
        }
Exemplo n.º 12
0
        public void Write()
        {
            byte[]       expectedBuffer = new byte[10];
            ActionStream actionStream   = new ActionStream(new StreamActions
            {
                Write = (buffer, offset, count) =>
                {
                    for (int i = 0; i < count; i++)
                    {
                        expectedBuffer[i] = buffer[offset + i];
                    }
                }
            });

            byte[] writeBuffer = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
            actionStream.Write(writeBuffer, 0, writeBuffer.Length);

            Assert.Equal(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }, expectedBuffer);
        }
Exemplo n.º 13
0
        public void Read_Length()
        {
            ActionStream actionStream = new ActionStream(new StreamActions
            {
                Read = (buffer, offset, count) =>
                {
                    for (int i = 0; i < count; i++)
                    {
                        buffer[offset + i] = (byte)i;
                    }
                    return(count);
                }
            });

            byte[] readBuffer = new byte[10];
            int    readLength = actionStream.Read(readBuffer, 0, readBuffer.Length);

            Assert.Equal(readBuffer.Length, readLength);
        }
Exemplo n.º 14
0
        public void Get_Position()
        {
            long         expectedOffset = -1;
            SeekOrigin   expectedOrigin = SeekOrigin.End;
            ActionStream actionStream   = new ActionStream(new StreamActions
            {
                Seek = (offset, origin) =>
                {
                    expectedOrigin = origin;
                    expectedOffset = offset;
                    return(offset + 10);
                }
            });

            long currentPosition = actionStream.Position;

            Assert.Equal(0, expectedOffset);
            Assert.Equal(10, currentPosition);
            Assert.Equal(SeekOrigin.Current, expectedOrigin);
        }
Exemplo n.º 15
0
        public void One_Byte_Read_Result()
        {
            ActionStream stream = new ActionStream(new StreamActions
            {
                Read = (buffer, offset, count) =>
                {
                    buffer[offset] = 32;
                    return(1);
                },
                Seek      = (l, origin) => 0,
                GetLength = () => 10
            });

            SubStream subStream = new SubStream(stream, 5);

            byte[] readBuffer = new byte[10];
            int    readCount  = subStream.Read(readBuffer, 0, 10);

            Assert.Equal(1, readCount);
        }