public void SequentialReaderWriter_Reset() { var expected = new List <ClassOfListOfGuid>(); for (var i = 0; i < 7; i++) { expected.Add(ClassOfListOfGuid.Create(true)); } var w = AvroContainer.CreateWriter <ClassOfListOfGuid>(this.resultStream, Codec.Deflate); using (var writer = new SequentialWriter <ClassOfListOfGuid>(w, 3)) { expected.ForEach(writer.Write); } this.resultStream.Seek(0, SeekOrigin.Begin); var r = AvroContainer.CreateReader <ClassOfListOfGuid>(this.resultStream); using (var reader = new SequentialReader <ClassOfListOfGuid>(r)) { Assert.IsTrue(expected.SequenceEqual(reader.Objects)); var enumerator = (IEnumerator)reader.Objects.GetEnumerator(); Assert.IsFalse(enumerator.MoveNext()); } }
public void Container_Reset() { var expected = new List <ClassOfListOfGuid>(); for (var i = 0; i < 7; i++) { expected.Add(ClassOfListOfGuid.Create(true)); } using (var memoryStream = new MemoryStream()) { var writer = AvroContainer.CreateWriter <ClassOfListOfGuid>(memoryStream, new AvroSerializerSettings { Resolver = new AvroDataContractResolver(true) }, Codec.Deflate); var i = 0; while (i < expected.Count) { var block = writer.CreateBlockAsync().Result; for (var j = 0; j < 3; j++) { if (i >= expected.Count) { break; } block.Write(expected[i]); i++; } writer.WriteBlockAsync(block).Wait(); } writer.Dispose(); memoryStream.Seek(0, SeekOrigin.Begin); var reader = AvroContainer.CreateReader <ClassOfListOfGuid>(memoryStream, true, new AvroSerializerSettings { Resolver = new AvroDataContractResolver(true) }, new CodecFactory()); var actual = new List <ClassOfListOfGuid>(); var resetActual = new List <ClassOfListOfGuid>(); while (reader.MoveNext()) { actual.AddRange(reader.Current.Objects); var e = reader.Current.Objects.GetEnumerator(); while (e.MoveNext()) { resetActual.Add(e.Current); } } Assert.True(expected.SequenceEqual(actual)); Assert.True(expected.SequenceEqual(resetActual)); } }