示例#1
0
        public void ReadExactly()
        {
            byte[] abySource = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    byte[] read = stream.ReadExactly(5);
                    CollectionAssert.AreEqual(abySource.Take(5), read);

                    read = stream.ReadExactly(6);
                    CollectionAssert.AreEqual(abySource.Skip(5), read);

                    Assert.Throws <EndOfStreamException>(() => stream.ReadExactly(1));
                }

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    byte[] read = stream.ReadExactly(11);
                    CollectionAssert.AreEqual(abySource, read);
                }

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    Assert.Throws <EndOfStreamException>(() => stream.ReadExactly(12));
                }
        }
示例#2
0
        public void ReadExactlyArray()
        {
            byte[] abySource = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    byte[] buffer = new byte[20];
                    stream.ReadExactly(buffer, 3, 8);
                    CollectionAssert.AreEqual(new byte[3].Concat(abySource.Take(8)).Concat(new byte[9]), buffer);
                }

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    byte[] buffer = new byte[20];
                    stream.ReadExactly(buffer, 5, 11);
                    CollectionAssert.AreEqual(new byte[5].Concat(abySource).Concat(new byte[4]), buffer);
                }

            using (Stream streamSource = new MemoryStream(abySource))
                using (Stream stream = new SlowStream(streamSource))
                {
                    byte[] buffer = new byte[20];
                    Assert.Throws <EndOfStreamException>(() => stream.ReadExactly(buffer, 5, 12));
                }
        }
		public void ReadExactly()
		{
			byte[] abySource = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				byte[] read = stream.ReadExactly(5);
				CollectionAssert.AreEqual(abySource.Take(5), read);

				read = stream.ReadExactly(6);
				CollectionAssert.AreEqual(abySource.Skip(5), read);

				Assert.Throws<EndOfStreamException>(() => stream.ReadExactly(1));
			}

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				byte[] read = stream.ReadExactly(11);
				CollectionAssert.AreEqual(abySource, read);
			}

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				Assert.Throws<EndOfStreamException>(() => stream.ReadExactly(12));
			}
		}
		public void ReadExactlyArray()
		{
			byte[] abySource = new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				byte[] buffer = new byte[20];
				stream.ReadExactly(buffer, 3, 8);
				CollectionAssert.AreEqual(new byte[3].Concat(abySource.Take(8)).Concat(new byte[9]), buffer);
			}

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				byte[] buffer = new byte[20];
				stream.ReadExactly(buffer, 5, 11);
				CollectionAssert.AreEqual(new byte[5].Concat(abySource).Concat(new byte[4]), buffer);
			}

			using (Stream streamSource = new MemoryStream(abySource))
			using (Stream stream = new SlowStream(streamSource))
			{
				byte[] buffer = new byte[20];
				Assert.Throws<EndOfStreamException>(() => stream.ReadExactly(buffer, 5, 12));
			}
		}