public void ThrowsException_WhenUnexpectedEndOfStream_InValue(byte[] valueEnding)
        {
            var key         = "butcher.png";
            var keyBytes    = Encoding.ASCII.GetBytes(key);
            var streamBytes = keyBytes
                              .Concat(new byte[] { 0, 1 })
                              .Concat(new byte[] { 1, 2, 3, 4, 5 })
                              .Concat(valueEnding)
                              .ToArray();

            testStream = new TestStream(streamBytes);
            AssertThrowsExceptionWhenReadKey(key, testStream);
        }
        private List <byte> Read(string key, TestStream stream)
        {
            var reader = new ResourceReaderStream(stream, key);
            var buffer = new byte[100];
            var result = new List <byte>();

            while (true)
            {
                var count = reader.Read(buffer, 0, 100);
                if (count == 0)
                {
                    break;
                }
                result.AddRange(buffer.Take(count));
            }

            return(result);
        }
        void Read(string key, TestStream stream)
        {
            var reader = new ResourceReaderStream(stream, key);
            var buffer = new byte[100];
            var result = new List <byte>();

            while (true)
            {
                var count = reader.Read(buffer, 0, 100);
                if (count == 0)
                {
                    break;
                }
                result.AddRange(buffer.Take(count));
            }
            var str = Encoding.ASCII.GetString(result.ToArray());

            Assert.AreEqual(data[key], str);
        }
 public void SetUp()
 {
     testStream = new TestStream(GetKeysAndValues());
 }
 private void AssertThrowsExceptionWhenReadKey(string key, TestStream stream)
 {
     Assert.Throws <EndOfStreamException>(() => Read(key, stream));
 }
 private void AssertReadKeyEqualsData(string key, TestStream stream)
 {
     AssertReadKeyEqualsData(key, stream, data[key]);
 }
 public void WorksCorrectly_WithInfiniteStream()
 {
     testStream = new TestStream(GetKeysAndValues(), infinityMode: true);
     AssertReadKeyEqualsData("mapObjectsList.txt", testStream);
 }