Exemple #1
0
        private void CompleteFields()
        {
            var fields            = new Dictionary <string, InputFieldDescription>();
            var handledProperties = new HashSet <PropertyInfo>();

            foreach (InputFieldDescriptor fieldDescriptor in Fields)
            {
                InputFieldDescription fieldDescription = fieldDescriptor
                                                         .CreateDescription();

                if (!fieldDescription.Ignored)
                {
                    fields[fieldDescription.Name] = fieldDescription;
                }

                if (fieldDescription.Property != null)
                {
                    handledProperties.Add(fieldDescription.Property);
                }
            }

            OnCompleteFields(fields, handledProperties);

            ObjectDescription.Fields.AddRange(fields.Values);
        }
Exemple #2
0
        public void InferTypeFromProperty()
        {
            // act
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(FieldCollection <InputField>),
                         description.TypeReference.ClrType);
            Assert.Equal("arguments", description.Name);
        }
Exemple #3
0
        public void OverwriteName()
        {
            // arrange
            var descriptor = new InputFieldDescriptor("1234");

            // act
            ((IInputFieldDescriptor)descriptor)
            .Name("args");

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal("args", description.Name);
        }
Exemple #4
0
        public void OverwriteName2()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Name("args");

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal("args", description.Name);
        }
Exemple #5
0
        public void SetDefaultValueAndInferType()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue("string");

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(typeof(string), description.TypeReference.ClrType);
            Assert.Equal("string", description.NativeDefaultValue);
        }
Exemple #6
0
        public void SetDescription()
        {
            // arrange
            string expectedDescription = Guid.NewGuid().ToString();
            var    descriptor          = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Description(expectedDescription);

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Equal(expectedDescription, description.Description);
        }
        public void SetSchemaType()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Type(new StringType());

            // assert
            InputFieldDescription description = descriptor.CreateDescription();
            TypeReference         typeRef     = description.TypeReference;

            Assert.IsType <StringType>(typeRef.SchemaType);
        }
Exemple #8
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .Type <NativeType <IReadOnlyDictionary <string, string> > >()
            .Type <ListType <StringType> >();

            // assert
            InputFieldDescription description = descriptor.CreateDescription();
            TypeReference         typeRef     = description.TypeReference;

            Assert.Equal(typeof(ListType <StringType>), typeRef.ClrType);
        }
Exemple #9
0
        public void OverwriteDefaultValueLiteralWithNativeDefaultValue()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string");

            // asser
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.Null(description.DefaultValue);
            Assert.Equal("string", description.NativeDefaultValue);
        }
Exemple #10
0
        public void SettingTheNativeDefaultValueToNullCreatesNullLiteral()
        {
            // arrange
            var descriptor = new InputFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            ((IInputFieldDescriptor)descriptor)
            .DefaultValue(new StringValueNode("123"))
            .DefaultValue("string")
            .DefaultValue(null);

            // assert
            InputFieldDescription description = descriptor.CreateDescription();

            Assert.IsType <NullValueNode>(description.DefaultValue);
            Assert.Null(description.NativeDefaultValue);
        }
 internal InputField(InputFieldDescription inputFieldDescription)
     : this(inputFieldDescription,
            DirectiveLocation.InputFieldDefinition)
 {
     Property = inputFieldDescription.Property;
 }
Exemple #12
0
 internal InputField(InputFieldDescription inputFieldDescription)
     : this((ArgumentDescription)inputFieldDescription)
 {
     Property = inputFieldDescription.Property;
 }