public void Container_MicrosoftWriterApacherReaderOfNestedType()
        {
            var expected = new List <NestedClass>();

            for (var i = 0; i < 7; i++)
            {
                expected.Add(NestedClass.Create(true));
            }

            using (var memoryStream = new MemoryStream())
            {
                var writer = AvroContainer.CreateWriter <NestedClass>(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 < 2; j++)
                    {
                        if (i >= expected.Count)
                        {
                            break;
                        }
                        block.Write(expected[i]);
                        i++;
                    }
                    writer.WriteBlockAsync(block).Wait();
                }
                writer.Dispose();

                memoryStream.Seek(0, SeekOrigin.Begin);

                var reader = DataFileReader <GenericRecord> .OpenReader(memoryStream);

                var actual = new List <GenericRecord>(reader);

                for (var k = 0; k < expected.Count; ++k)
                {
                    Assert.Equal(expected[k].PrimitiveInt, actual[k]["PrimitiveInt"]);
                    if (expected[k].ClassOfIntReference == null)
                    {
                        Assert.Null(actual[k]["ClassOfIntReference"]);
                    }
                    else
                    {
                        Assert.Equal(expected[k].ClassOfIntReference.PrimitiveInt, (actual[k]["ClassOfIntReference"] as GenericRecord)["PrimitiveInt"]);
                    }
                }
            }
        }
コード例 #2
0
        public void SequentialWriter_MicrosoftWriterApacherReaderOfNestedType()
        {
            var expected = new List <NestedClass>();

            for (var i = 0; i < 7; i++)
            {
                expected.Add(NestedClass.Create(true));
            }

            var w = AvroContainer.CreateWriter <NestedClass>(this.resultStream, new AvroSerializerSettings {
                Resolver = new AvroDataContractResolver(true)
            }, Codec.Deflate);

            using (var writer = new SequentialWriter <NestedClass>(w, 2))
            {
                expected.ForEach(writer.Write);
            }

            this.resultStream.Seek(0, SeekOrigin.Begin);

            var reader = DataFileReader <GenericRecord> .OpenReader(this.resultStream);

            var actual = new List <GenericRecord>(reader);

            for (var i = 0; i < expected.Count; ++i)
            {
                Assert.AreEqual(expected[i].PrimitiveInt, actual[i]["PrimitiveInt"]);
                if (expected[i].ClassOfIntReference == null)
                {
                    Assert.IsNull(actual[i]["ClassOfIntReference"]);
                }
                else
                {
                    Assert.IsNotNull(actual[i]["ClassOfIntReference"] as GenericRecord);
                    Assert.AreEqual(expected[i].ClassOfIntReference.PrimitiveInt, (actual[i]["ClassOfIntReference"] as GenericRecord)["PrimitiveInt"]);
                }
            }
        }
 public static AnotherClassWithoutParameterlessConstructor Create()
 {
     return(new AnotherClassWithoutParameterlessConstructor(NestedClass.Create(true)));
 }