public void TestSetup()
 {
     this.builder = new ReflectionSchemaBuilder(this.settings);
 }
 public void TestTeardown()
 {
     this.builder = null;
 }
        private static void RoundTripTestNullableSchema(
            AvroSerializerSettings settings,
            bool rootSchemaIsUnion,
            bool nullableValueSchemaNullableIsUnion,
            bool nullableValueSchemaNotNullableIsUnion,
            bool valueSchemaNullableIsUnion,
            bool valueSchemaNotNullableIsUnion,
            bool referenceSchemaNullableIsUnion,
            bool referenceSchemaNotNullableIsUnion)
        {
            var builder = new ReflectionSchemaBuilder(settings);
            var schema = builder.BuildSchema(typeof(ClassWithSchemaNullableField));
            RecordSchema recordSchema = null;

            if (rootSchemaIsUnion)
            {
                var asUnion = schema as UnionSchema;
                Assert.IsNotNull(asUnion);

                var innerNullSchema = asUnion.Schemas[0] is NullSchema
                ? asUnion.Schemas[0]
                : asUnion.Schemas[1];

                recordSchema = asUnion.Schemas.Single(s => s != innerNullSchema) as RecordSchema;
                Assert.IsNotNull(recordSchema);
            }
            else
            {
                recordSchema = schema as RecordSchema;
                Assert.IsNotNull(recordSchema);
            }

            Assert.AreEqual(typeof(ClassWithSchemaNullableField).GetAllFields().Count(), recordSchema.Fields.Count);

            var nullableValueSchemaNullable = recordSchema.Fields.Single(f => f.Name == "NullableValueNullableSchema");
            ValidateSchema(nullableValueSchemaNullable.TypeSchema, nullableValueSchemaNullableIsUnion, typeof(IntSchema));

            var nullableValueSchemaNotNullable = recordSchema.Fields.Single(f => f.Name == "NullableValueNotNullableSchema");
            ValidateSchema(nullableValueSchemaNotNullable.TypeSchema, nullableValueSchemaNotNullableIsUnion, typeof(IntSchema));

            var valueSchemaNullable = recordSchema.Fields.Single(f => f.Name == "NotNullableValueNullableSchema");
            ValidateSchema(valueSchemaNullable.TypeSchema, valueSchemaNullableIsUnion, typeof(IntSchema));

            var valueSchemaNotNullable = recordSchema.Fields.Single(f => f.Name == "NotNullableValueNotNullableSchema");
            ValidateSchema(valueSchemaNotNullable.TypeSchema, valueSchemaNotNullableIsUnion, typeof(IntSchema));

            var referenceSchemaNullable = recordSchema.Fields.Single(f => f.Name == "ReferenceFieldNullableSchema");
            ValidateSchema(referenceSchemaNullable.TypeSchema, referenceSchemaNullableIsUnion, typeof(RecordSchema));

            var referenceSchemaNotNullable = recordSchema.Fields.Single(f => f.Name == "ReferenceFieldNotNullableSchema");
            ValidateSchema(referenceSchemaNotNullable.TypeSchema, referenceSchemaNotNullableIsUnion, typeof(RecordSchema));
        }