public void WriteEntryAsAvroTest() { MemoryStream ms = new MemoryStream(); var ctx = this.CreateOutputContext(ms); ODataAvroWriter aw = new ODataAvroWriter(ctx, value => ctx.AvroWriter.Write(value), ctx.AvroWriter.UpdateSchema(null, TestEntityType), false); aw.WriteStart(entry0); aw.WriteEnd(); aw.Flush(); ms.Seek(0, SeekOrigin.Begin); IEnumerable<object> results; IAvroReader<object> reader = null; try { reader = AvroContainer.CreateGenericReader(ms); using (var seqReader = new SequentialReader<object>(reader)) { reader = null; results = seqReader.Objects; } } finally { if (reader != null) reader.Dispose(); } dynamic record = results.Single() as AvroRecord; Assert.IsNotNull(record); Assert.AreEqual(true, record.TBoolean); Assert.AreEqual(32, record.TInt32); var col = record.TCollection as object[]; Assert.IsNotNull(col); Assert.IsTrue(longCollection0.SequenceEqual(col.Cast<long>())); dynamic cpx = record.TComplex as AvroRecord; Assert.IsNotNull(cpx); Assert.IsTrue(binary0.SequenceEqual((byte[])cpx.TBinary)); Assert.AreEqual("iamstr", cpx.TString); }
public void WriteFeedAsAvroTest() { ODataEntry entry1 = new ODataEntry { Properties = new[] { new ODataProperty {Name = "TBoolean", Value = true,}, new ODataProperty {Name = "TInt32", Value = 32,}, }, TypeName = "NS.SimpleEntry" }; ODataEntry entry2 = new ODataEntry { Properties = new[] { new ODataProperty {Name = "TBoolean", Value = false,}, new ODataProperty {Name = "TInt32", Value = 325,}, }, TypeName = "NS.SimpleEntry" }; MemoryStream ms = new MemoryStream(); var ctx = this.CreateOutputContext(ms); ODataAvroWriter aw = new ODataAvroWriter(ctx, value => ctx.AvroWriter.Write(value), null, true); aw.WriteStart(new ODataFeed()); aw.WriteStart(entry1); aw.WriteEnd(); aw.WriteStart(entry2); aw.WriteEnd(); aw.WriteEnd(); aw.Flush(); ms.Seek(0, SeekOrigin.Begin); IEnumerable<object> results; IAvroReader<object> reader = null; try { reader = AvroContainer.CreateGenericReader(ms); using (var seqReader = new SequentialReader<object>(reader)) { reader = null; results = seqReader.Objects; } } finally { if (reader != null) reader.Dispose(); } var records = results.Cast<object[]>().Single(); Assert.AreEqual(2, records.Count()); dynamic record = records[0]; Assert.AreEqual(true, record.TBoolean); Assert.AreEqual(32, record.TInt32); record = records[1]; Assert.AreEqual(false, record.TBoolean); Assert.AreEqual(325, record.TInt32); }