예제 #1
0
        public void CreateByteArrayData_Fact()
        {
            var x    = new byte[0];
            var mock = new MockIOBuffer(x);

            mock.Storage.ShouldReference(x);
        }
예제 #2
0
        public void ReadPastEndThrows_Fact()
        {
            var mock   = new MockIOBuffer(0x0a);
            var output = new byte[8];
            var e      = Trap.Exception(() => mock.ReadInto(output, 0, 4));

            e.ShouldBeOfType(typeof(IndexOutOfRangeException));
        }
예제 #3
0
        public void ShouldObserveOutput(ushort address, params byte[] expectedOutput)
        {
            MockIOBuffer output = GetDevice(address)
                                  .Output;

            output.Storage.ShouldEnumerateEqual(expectedOutput);
            output.Clear();
        }
예제 #4
0
        public void AppendWithBufferGrowth_Fact()
        {
            // storage is    | _A_ | _B_ | _C_ | _D_ |
            // readIndex is  0
            // append        | _1_ | _2_ |
            // storage should become => | _A_ | _B_ | _C_ | _D_ | _1_ | _2_ |
            var mock = new MockIOBuffer(0x0a, 0x0b, 0x0c, 0x0d);

            mock.Append(1, 2);
            mock.Storage.ShouldEnumerateEqual(0x0a, 0x0b, 0x0c, 0x0d, 1, 2);
        }
예제 #5
0
        public void AppendWithShiftingIndex_Fact()
        {
            // storage is    | _A_ | _B_ | _C_ | _D_ |
            // readIndex is  3
            // append        | _1_ | _2_ |
            // storage should become => | _A_ | _D_ | _1_ | _2_ |
            // readIndex should become 1
            var mock = new MockIOBuffer(0x0a, 0x0b, 0x0c, 0x0d);

            mock.ReadIndex = 3;
            mock.Append(1, 2);
            mock.Storage.ShouldEnumerateEqual(0x0A, 0x0D, 1, 2);
            mock.ReadIndex.ShouldEqual(1);
        }
예제 #6
0
        public void Read_Fact()
        {
            var mock   = new MockIOBuffer(0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f);
            var output = new byte[8];

            mock.ReadInto(output, 3, 2);
            output.ShouldEnumerateEqual(0, 0, 0, 0x0a, 0x0b, 0, 0, 0);
            mock.ReadIndex.ShouldEqual(2);
            mock.ReadInto(output, 3, 3);
            output.ShouldEnumerateEqual(0, 0, 0, 0x0c, 0x0d, 0x0e, 0, 0);
            mock.ReadIndex.ShouldEqual(5);
            mock.ReadInto(output, 0, 1);
            output.ShouldEnumerateEqual(0x0f, 0, 0, 0x0c, 0x0d, 0x0e, 0, 0);
            mock.ReadIndex.ShouldEqual(6);
        }
예제 #7
0
        public void CreateSingleByteData_Fact()
        {
            var mock = new MockIOBuffer(0xAB);

            mock.Storage.ShouldEnumerateEqual(0xab);
        }
예제 #8
0
        public void CreateNullData_Fact()
        {
            var exception = Trap.Exception(() => { var buffer = new MockIOBuffer(null); });

            exception.ShouldBeOfType(typeof(ArgumentNullException));
        }
예제 #9
0
        public void CreateNoData_Fact()
        {
            var mock = new MockIOBuffer();

            mock.Storage.Length.ShouldEqual(0);
        }
예제 #10
0
        public void CreateMultiByteData_Fact()
        {
            var mock = new MockIOBuffer(1, 2, 3);

            mock.Storage.ShouldEnumerateEqual(1, 2, 3);
        }
예제 #11
0
 public DeviceBuffers(ushort address)
 {
     Address = address;
     Input   = new MockIOBuffer();
     Output  = new MockIOBuffer();
 }