Exemple #1
0
        public void CreateBytes_Creates_ByteArray_Of_The_Segment()
        {
            var segmentArr = new byte[0];
            var segment    = new ArraySegment <byte>(segmentArr, 0, 0);
            var createdArr = segment.CreateBytes();

            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 0);

            segmentArr = new byte[] { 0, 255 };
            segment    = new ArraySegment <byte>(segmentArr, 0, 0);
            createdArr = segment.CreateBytes();
            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 0);

            segment    = new ArraySegment <byte>(segmentArr, 0, 1);
            createdArr = segment.CreateBytes();
            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 1);
            Assert.True(createdArr[0].Equals(segmentArr[0]));

            segment    = new ArraySegment <byte>(segmentArr, 1, 1);
            createdArr = segment.CreateBytes();
            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 1);
            Assert.True(createdArr[0].Equals(segmentArr[1]));

            segment    = new ArraySegment <byte>(segmentArr, 0, 2);
            createdArr = segment.CreateBytes();
            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 2);
            Assert.True(createdArr[0].Equals(segmentArr[0]));
            Assert.True(createdArr[1].Equals(segmentArr[1]));

            segment    = new ArraySegment <byte>(segmentArr, 2, 0);
            createdArr = segment.CreateBytes();
            Assert.NotNull(createdArr);
            Assert.True(createdArr.Length == 0);
        }