Ejemplo n.º 1
0
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public override void Process(SchemaBuilderContext context)
 {
     if (!context.Property.GetCustomAttributes().Any(a => a.GetType().GetTypeInfo().IsSubclassOf(typeof(FormAttribute))))
     {
         context.FinishProcessing = true;
     }
 }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            Type propertyType = DeterminePropertyType(context);

            string schemaType = DetermineSimpleSchemaType(propertyType);

            if (schemaType != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                // If the schema was found create the type element to the context
                currentSchemaObject["type"] = schemaType;

                if (propertyType.GetTypeInfo().IsEnum)
                {
                    // If the property type is an enumeration then additionally to the type we have to set the enum property
                    FieldInfo[] enumMembers = propertyType.GetFields(BindingFlags.Public | BindingFlags.Static);

                    JArray enumItemsArray = new JArray();

                    foreach (FieldInfo enumMember in enumMembers)
                    {
                        enumItemsArray.Add(Convert.ChangeType(enumMember.GetValue(null), typeof(int)));
                    }

                    currentSchemaObject["enum"] = enumItemsArray;
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            Type propertyType = DeterminePropertyType(context);

            string schemaType = DetermineSimpleSchemaType(propertyType);

            if (schemaType != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                // If the schema was found create the type element to the context
                currentSchemaObject["type"] = schemaType;

                if (propertyType.GetTypeInfo().IsEnum)
                {
                    // If the property type is an enumeration then additionally to the type we have to set the enum property
                    FieldInfo[] enumMembers = propertyType.GetFields(BindingFlags.Public | BindingFlags.Static);

                    JArray enumItemsArray = new JArray();

                    foreach (FieldInfo enumMember in enumMembers)
                    {
                        enumItemsArray.Add(Convert.ChangeType(enumMember.GetValue(null), typeof(int)));
                    }

                    currentSchemaObject["enum"] = enumItemsArray;
                }
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public override void Process(SchemaBuilderContext context)
 {
     if (context.Property.GetCustomAttribute <FormRequiredAttribute>() != null)
     {
         // The property is a required property
         context.Element.IsRequired = true;
     }
 }
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public override void Process(SchemaBuilderContext context)
 {
     if (context.Property.GetCustomAttribute<FormRequiredAttribute>() != null)
     {
         // The property is a required property
         context.Element.IsRequired = true;
     }
 }
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public override void Process(SchemaBuilderContext context)
 {
     if (context.Property.GetCustomAttribute<FormValidationMessageAttribute>() != null)
     {
         FormValidationMessageAttribute validationMessage = context.Property.GetCustomAttribute<FormValidationMessageAttribute>();
         context.Element.GetOrCreateSchemaObject()["validationMessage"] = GetTextForKey(validationMessage.MessageText, context);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public override void Process(SchemaBuilderContext context)
 {
     if (context.Property.GetCustomAttribute <FormValidationMessageAttribute>() != null)
     {
         FormValidationMessageAttribute validationMessage = context.Property.GetCustomAttribute <FormValidationMessageAttribute>();
         context.Element.GetOrCreateSchemaObject()["validationMessage"] = GetTextForKey(validationMessage.MessageText, context);
     }
 }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute<FormRegExValidationAttribute>() != null)
            {
                FormRegExValidationAttribute regExValidation = context.Property.GetCustomAttribute<FormRegExValidationAttribute>();

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the regex and the validation message to the current element
                schemaObject["pattern"] = new JValue(regExValidation.RegEx);
            }
        }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute<FormMaxLengthAttribute>() != null)
            {
                FormMaxLengthAttribute maxLength = context.Property.GetCustomAttribute<FormMaxLengthAttribute>();

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the regex and the validation message to the current element
                schemaObject["maxLength"] = new JValue(maxLength.Length);
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute <FormTitleAttribute>() != null)
            {
                string title = context.Property.GetCustomAttribute <FormTitleAttribute>().Title;

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the title to the current element
                schemaObject["title"] = GetTextForKey(title, context);
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute <FormMaxLengthAttribute>() != null)
            {
                FormMaxLengthAttribute maxLength = context.Property.GetCustomAttribute <FormMaxLengthAttribute>();

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the regex and the validation message to the current element
                schemaObject["maxLength"] = new JValue(maxLength.Length);
            }
        }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute<FormTitleAttribute>() != null)
            {
                string title = context.Property.GetCustomAttribute<FormTitleAttribute>().Title;

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the title to the current element
                schemaObject["title"] = GetTextForKey(title, context);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute <FormRegExValidationAttribute>() != null)
            {
                FormRegExValidationAttribute regExValidation = context.Property.GetCustomAttribute <FormRegExValidationAttribute>();

                JObject schemaObject = context.Element.GetOrCreateSchemaObject();

                // Set the regex and the validation message to the current element
                schemaObject["pattern"] = new JValue(regExValidation.RegEx);
            }
        }
 /// <summary>
 /// Gets the text for key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="schemaBuilderContext">The schema builder context.</param>
 /// <returns>
 /// The string for the requested key.
 /// </returns>
 protected string GetTextForKey(string key, SchemaBuilderContext schemaBuilderContext)
 {
     if (_languageProvider != null)
     {
         // If a language provider is availabe call it to get the text
         return _languageProvider.GetTextForKey(key, schemaBuilderContext.GetLanguageContext());
     }
     else
     {
         // If no language provider is available return the key as text
         return key;
     }
 }
        /// <summary>
        /// Determines the type of the property.
        /// </summary>
        /// <param name="context">The context to determine the type from.</param>
        /// <returns>The type of the property.</returns>
        private static Type DeterminePropertyType(SchemaBuilderContext context)
        {
            // Get the type of the property to build a schema for
            Type propertyType = context.Property.PropertyType;

            if (propertyType.GetTypeInfo().IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
            {
                // If the property type is a nullable type get the underlying type
                propertyType = Nullable.GetUnderlyingType(propertyType);
            }

            return propertyType;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Gets the text for key.
 /// </summary>
 /// <param name="key">The key.</param>
 /// <param name="schemaBuilderContext">The schema builder context.</param>
 /// <returns>
 /// The string for the requested key.
 /// </returns>
 protected string GetTextForKey(string key, SchemaBuilderContext schemaBuilderContext)
 {
     if (_languageProvider != null)
     {
         // If a language provider is availabe call it to get the text
         return(_languageProvider.GetTextForKey(key, schemaBuilderContext.GetLanguageContext()));
     }
     else
     {
         // If no language provider is available return the key as text
         return(key);
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Determines the type of the property.
        /// </summary>
        /// <param name="context">The context to determine the type from.</param>
        /// <returns>The type of the property.</returns>
        private static Type DeterminePropertyType(SchemaBuilderContext context)
        {
            // Get the type of the property to build a schema for
            Type propertyType = context.Property.PropertyType;

            if (propertyType.GetTypeInfo().IsGenericType&& propertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                // If the property type is a nullable type get the underlying type
                propertyType = Nullable.GetUnderlyingType(propertyType);
            }

            return(propertyType);
        }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            FormUrlLookupAttribute urlLookupAttribute = context.Property.GetCustomAttribute<FormUrlLookupAttribute>();

            if (urlLookupAttribute != null && _urlLookupProvider != null)
            {
                string url = _urlLookupProvider.GetUrlForLookupType(urlLookupAttribute.LookupType);

                // Set up the link object
                JObject link = new JObject();
                link["rel"] = new JValue("options");
                link["href"] = new JValue(url);

                // Add link object as array to the schema
                context.Element.GetOrCreateSchemaObject()["links"] = new JArray(link);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            FormUrlLookupAttribute urlLookupAttribute = context.Property.GetCustomAttribute <FormUrlLookupAttribute>();

            if (urlLookupAttribute != null && _urlLookupProvider != null)
            {
                string url = _urlLookupProvider.GetUrlForLookupType(urlLookupAttribute.LookupType);

                // Set up the link object
                JObject link = new JObject();
                link["rel"]  = new JValue("options");
                link["href"] = new JValue(url);

                // Add link object as array to the schema
                context.Element.GetOrCreateSchemaObject()["links"] = new JArray(link);
            }
        }
Ejemplo n.º 20
0
 public virtual SchemaBuilderCaseResult BuildSchema(Type type, SchemaBuilderContext context)
 {
     if (type == typeof(IOrderEvent))
     {
         return(SchemaBuilderCaseResult.FromSchema(
                    new UnionSchema(new[]
         {
             schemaBuilder.BuildSchema <OrderCreationEvent>(context),
             schemaBuilder.BuildSchema <OrderLineItemModificationEvent>(context),
             schemaBuilder.BuildSchema <OrderCancellationEvent>(context),
         })));
     }
     else
     {
         return(SchemaBuilderCaseResult.FromException(
                    new UnsupportedTypeException(type, $"{nameof(OrderEventUnionSchemaBuilderCase)} can only be applied to the {typeof(IOrderEvent)} type.")));
     }
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute <FormSubObjectAttribute>() != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                // A schema type for a simple type could not be found, we assume the property references an complex type
                // Build the schema for a complext type
                JObject complexSchema = context.SchemaBuilder.BuildSchema(context.Property.PropertyType, context.OriginDtoType, context.TargetCulture);

                currentSchemaObject["title"] = new JValue(context.Property.Name);

                // Add the properties of the complex schema to the current schema
                foreach (KeyValuePair <string, JToken> schemaItem in complexSchema)
                {
                    currentSchemaObject[schemaItem.Key] = schemaItem.Value;
                }
            }
        }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            if (context.Property.GetCustomAttribute<FormSubObjectAttribute>() != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                // A schema type for a simple type could not be found, we assume the property references an complex type
                // Build the schema for a complext type
                JObject complexSchema = context.SchemaBuilder.BuildSchema(context.Property.PropertyType, context.OriginDtoType, context.TargetCulture);

                currentSchemaObject["title"] = new JValue(context.Property.Name);

                // Add the properties of the complex schema to the current schema
                foreach (KeyValuePair<string, JToken> schemaItem in complexSchema)
                {
                    currentSchemaObject[schemaItem.Key] = schemaItem.Value;
                }
            }
        }
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            FormArrayAttribute arrayAttribute = context.Property.GetCustomAttribute<FormArrayAttribute>();

            if (arrayAttribute != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                if (context.Property.PropertyType.GetInterfaces()
                    .Where(i => i.GetTypeInfo().IsGenericType)
                    .Select(i => i.GetGenericTypeDefinition()).Any(i => i == typeof (IEnumerable<>)))
                {
                    // The property is an generic enumerable type
                    Type underlyingType = context.Property.PropertyType.GetGenericArguments()[0];

                    // Build the schema for a complext type
                    JObject complexSchema = context.SchemaBuilder.BuildSchema(underlyingType, context.OriginDtoType, context.TargetCulture);

                    currentSchemaObject["title"] = new JValue(context.Property.Name);
                    currentSchemaObject["type"] = new JValue("array");
                    currentSchemaObject["items"] = complexSchema;

                    // Add minItems constraint if available
                    if (arrayAttribute.MinItems > 0)
                    {
                        currentSchemaObject["minItems"] = new JValue(arrayAttribute.MinItems);
                    }

                    // Add maxItems constraint if available
                    if (arrayAttribute.MaxItems > 0)
                    {
                        currentSchemaObject["maxItems"] = new JValue(arrayAttribute.MaxItems);
                    }
                }
                else
                {
                    throw new InvalidOperationException("The FormArray attibute may be used only on properties using types implementing IEnumerable<>.");
                }
            }

        }
Ejemplo n.º 24
0
        /// <summary>
        /// Processes the specified context.
        /// </summary>
        /// <param name="context">The context to process.</param>
        public override void Process(SchemaBuilderContext context)
        {
            FormArrayAttribute arrayAttribute = context.Property.GetCustomAttribute <FormArrayAttribute>();

            if (arrayAttribute != null)
            {
                JObject currentSchemaObject = context.Element.GetOrCreateSchemaObject();

                if (context.Property.PropertyType.GetInterfaces()
                    .Where(i => i.GetTypeInfo().IsGenericType)
                    .Select(i => i.GetGenericTypeDefinition()).Any(i => i == typeof(IEnumerable <>)))
                {
                    // The property is an generic enumerable type
                    Type underlyingType = context.Property.PropertyType.GetGenericArguments()[0];

                    // Build the schema for a complext type
                    JObject complexSchema = context.SchemaBuilder.BuildSchema(underlyingType, context.OriginDtoType, context.TargetCulture);

                    currentSchemaObject["title"] = new JValue(context.Property.Name);
                    currentSchemaObject["type"]  = new JValue("array");
                    currentSchemaObject["items"] = complexSchema;

                    // Add minItems constraint if available
                    if (arrayAttribute.MinItems > 0)
                    {
                        currentSchemaObject["minItems"] = new JValue(arrayAttribute.MinItems);
                    }

                    // Add maxItems constraint if available
                    if (arrayAttribute.MaxItems > 0)
                    {
                        currentSchemaObject["maxItems"] = new JValue(arrayAttribute.MaxItems);
                    }
                }
                else
                {
                    throw new InvalidOperationException("The FormArray attibute may be used only on properties using types implementing IEnumerable<>.");
                }
            }
        }
Ejemplo n.º 25
0
        public void BuildClassesWithNullableProperties()
        {
            var context = new SchemaBuilderContext();
            var schema  = Assert.IsType <RecordSchema>(builder.BuildSchema <NullableMemberClass>(context));

            Assert.Collection(
                context.Schemas.Keys,
                type => Assert.Equal(typeof(NullableMemberClass), type),
                type => Assert.Equal(typeof(string[]), type),
                type => Assert.Equal(typeof(string), type),
                type => Assert.Equal(typeof(Dictionary <string, object>), type),
                type => Assert.Equal(typeof(object), type),
                type => Assert.Equal(typeof(Guid), type),
                type => Assert.Equal(typeof(List <string>), type),
                type => Assert.Equal(typeof(Guid?), type));

            Assert.Collection(
                schema.Fields,
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ArrayOfNullableStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                var union = Assert.IsType <UnionSchema>(array.Item);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <StringSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ArrayOfStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                Assert.IsType <StringSchema>(array.Item);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.DictionaryOfNullableObjectsProperty), field.Name);

                var map   = Assert.IsType <MapSchema>(field.Type);
                var union = Assert.IsType <UnionSchema>(map.Value);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <RecordSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.DictionaryOfObjectsProperty), field.Name);

                var map = Assert.IsType <MapSchema>(field.Type);
                Assert.IsType <RecordSchema>(map.Value);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.GuidProperty), field.Name);
                Assert.IsType <StringSchema>(field.Type);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ListOfNullableStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                var union = Assert.IsType <UnionSchema>(array.Item);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <StringSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ListOfStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                Assert.IsType <StringSchema>(array.Item);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableArrayOfNullableStringsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var array = Assert.IsType <ArraySchema>(child);
                    var union = Assert.IsType <UnionSchema>(array.Item);
                    Assert.Collection(
                        union.Schemas,
                        child =>
                    {
                        Assert.IsType <NullSchema>(child);
                    },
                        child =>
                    {
                        Assert.IsType <StringSchema>(child);
                    });
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableArrayOfStringsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var array = Assert.IsType <ArraySchema>(child);
                    Assert.IsType <StringSchema>(array.Item);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableDictionaryOfNullableObjectsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var map   = Assert.IsType <MapSchema>(child);
                    var union = Assert.IsType <UnionSchema>(map.Value);
                    Assert.Collection(
                        union.Schemas,
                        child =>
                    {
                        Assert.IsType <NullSchema>(child);
                    },
                        child =>
                    {
                        Assert.IsType <RecordSchema>(child);
                    });
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableDictionaryOfObjectsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var map = Assert.IsType <MapSchema>(child);
                    Assert.IsType <RecordSchema>(map.Value);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableGuidProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <StringSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableListOfNullableStringsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var array = Assert.IsType <ArraySchema>(child);
                    var union = Assert.IsType <UnionSchema>(array.Item);
                    Assert.Collection(
                        union.Schemas,
                        child =>
                    {
                        Assert.IsType <NullSchema>(child);
                    },
                        child =>
                    {
                        Assert.IsType <StringSchema>(child);
                    });
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableListOfStringsProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    var array = Assert.IsType <ArraySchema>(child);
                    Assert.IsType <StringSchema>(array.Item);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.NullableStringProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <StringSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousArrayOfStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                Assert.IsType <StringSchema>(array.Item);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousDictionaryOfObjectsProperty), field.Name);

                var map = Assert.IsType <MapSchema>(field.Type);
                Assert.IsType <RecordSchema>(map.Value);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousGuidProperty), field.Name);
                Assert.IsType <StringSchema>(field.Type);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousListOfStringsProperty), field.Name);

                var array = Assert.IsType <ArraySchema>(field.Type);
                Assert.IsType <StringSchema>(array.Item);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousNullableGuidProperty), field.Name);

                var union = Assert.IsType <UnionSchema>(field.Type);
                Assert.Collection(
                    union.Schemas,
                    child =>
                {
                    Assert.IsType <NullSchema>(child);
                },
                    child =>
                {
                    Assert.IsType <StringSchema>(child);
                });
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.ObliviousStringProperty), field.Name);
                Assert.IsType <StringSchema>(field.Type);
            },
                field =>
            {
                Assert.Equal(nameof(NullableMemberClass.StringProperty), field.Name);
                Assert.IsType <StringSchema>(field.Type);
            });
            Assert.Null(schema.LogicalType);
            Assert.Equal(typeof(NullableMemberClass).Name, schema.Name);
            Assert.Equal(typeof(NullableMemberClass).Namespace, schema.Namespace);
        }
Ejemplo n.º 26
0
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public abstract void Process(SchemaBuilderContext context);
        /// <summary>
        /// Processes a property through the pipeline modules.
        /// </summary>
        /// <param name="objectType">Type of the object beeing processed.</param>
        /// <param name="originObjectType">Type of the origin object.</param>
        /// <param name="propertyInfo">The property information.</param>
        /// <param name="cultureInfo">The culture information.</param>
        /// <returns>
        /// The schema element.
        /// </returns>
        private SchemaElement ProcessProperty(Type objectType, Type originObjectType, PropertyInfo propertyInfo, CultureInfo cultureInfo)
        {
            // Create the context for this property
            SchemaBuilderContext context = new SchemaBuilderContext();
            context.Property = propertyInfo;
            context.SchemaBuilder = this;
            context.TargetCulture = cultureInfo;
            context.DtoType = objectType;
            context.OriginDtoType = originObjectType;

            // Run the property through each pipeline module
            foreach (ISchemaBuilderModule builderModule in _pipelineModules)
            {
                builderModule.Process(context);

                if (context.FinishProcessing)
                {
                    // Stop the pipeline to run the next module
                    break;
                }
            }

            return context.Element;
        }
 /// <summary>
 /// Processes the specified context.
 /// </summary>
 /// <param name="context">The context to process.</param>
 public abstract void Process(SchemaBuilderContext context);