示例#1
0
        public void InferTypeFromProperty()
        {
            // act
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal(typeof(List <Argument>),
                         Assert.IsType <ClrTypeReference>(description.Type).Type);
            Assert.Equal("arguments", description.Name);
        }
示例#2
0
        public void OverwriteName2()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal("args", description.Name);
        }
示例#3
0
        public void OverwriteName()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                "field1234");

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal("args", description.Name);
        }
示例#4
0
        public void SetDescription()
        {
            // arrange
            string expectedDescription = Guid.NewGuid().ToString();
            var    descriptor          = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Description(expectedDescription);

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal(expectedDescription, description.Description);
        }
示例#5
0
        public void SetSchemaType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.IsType <StringType>(
                Assert.IsType <SchemaTypeReference>(typeRef).Type);
        }
示例#6
0
        public void SetDefaultValueAndInferType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Equal(typeof(string),
                         Assert.IsType <ClrTypeReference>(description.Type).Type);
            Assert.Equal("string", description.NativeDefaultValue);
        }
示例#7
0
        public void SetNonGenericType()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

            // act
            descriptor.Type(typeof(StringType));

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.Equal(
                typeof(StringType),
                Assert.IsType <ClrTypeReference>(typeRef).Type);
        }
示例#8
0
        public void OverwriteDefaultValueLiteralWithNativeDefaultValue()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // asser
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.Null(description.DefaultValue);
            Assert.Equal("string", description.NativeDefaultValue);
        }
示例#9
0
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();
            ITypeReference       typeRef     = description.Type;

            Assert.Equal(typeof(ListType <StringType>),
                         Assert.IsType <ClrTypeReference>(typeRef).Type);
        }
示例#10
0
        public void SettingTheNativeDefaultValueToNullCreatesNullLiteral()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.IsType <NullValueNode>(description.DefaultValue);
            Assert.Null(description.NativeDefaultValue);
        }
示例#11
0
        public void OverwriteNativeDefaultValueWithDefaultValueLiteral()
        {
            // arrange
            var descriptor = InputFieldDescriptor.New(
                Context,
                typeof(ObjectField).GetProperty("Arguments"));

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

            // assert
            InputFieldDefinition description = descriptor.CreateDefinition();

            Assert.IsType <StringValueNode>(description.DefaultValue);
            Assert.Equal("123",
                         ((StringValueNode)description.DefaultValue).Value);
            Assert.Null(description.NativeDefaultValue);
        }
示例#12
0
        public void Type_Syntax_Type_Null()
        {
            void Error() => InputFieldDescriptor.New(Context, "foo").Type((string)null);

            Assert.Throws <ArgumentNullException>(Error);
        }