public void should_be_able_to_read_a_string_from_multiple_segments() { string expected = "The quick brown fox jumps over the lazy dog"; Encoding encoding = Encoding.ASCII; // create n-segments of each word and space Random random = new Random(0); List <ArraySegment <byte> > segments = new List <ArraySegment <byte> >(); var words = expected.Split(' '); for (int i = 0; i < words.Length; i++) { if (i != 0) { segments.Add(GetSegment(encoding.GetBytes(" "), random.Next(0, 256), random.Next(1, 4) * 1024)); } segments.Add(GetSegment(encoding.GetBytes(words[i]), random.Next(0, 256), random.Next(1, 4) * 1024)); } BufferListStream sut = new BufferListStream(); sut.Initialize(segments); // pre-condition Assert.AreEqual(expected.Length, sut.Length); string actual = sut.ReadString(expected.Length, encoding); Assert.AreEqual(expected, actual); Assert.AreEqual(expected.Length, sut.Position); }
public void should_be_able_to_read_a_string_from_segments() { string expected = "The quick brown fox jumps over the lazy dog"; BufferListStream sut = new BufferListStream(); sut.Initialize(GetSegments(expected, Encoding.ASCII, 2)); // pre-condition Assert.AreEqual(expected.Length, sut.Length); var actual = sut.ReadString(expected.Length, Encoding.ASCII); // assert Assert.AreEqual(expected, actual); Assert.AreEqual(expected.Length, sut.Position); }
public void should_be_able_to_read_a_string_from_one_segment() { string expected = "The quick brown fox jumps over the lazy dog"; var encoding = Encoding.ASCII; var bytes = encoding.GetBytes(expected); ArraySegment <byte> segment = new ArraySegment <byte>(bytes); BufferListStream sut = new BufferListStream(); sut.Initialize(new[] { segment }); // act var actual = sut.ReadString(expected.Length, encoding); // assert Assert.AreEqual(expected, actual); Assert.AreEqual(expected.Length, sut.Position); }