public void InferName()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor desc = descriptor;

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

            Assert.Equal("CustomDirective", description.Name);
        }
        public void OverrideName()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor desc = descriptor;

            desc.Name("Foo");

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

            Assert.Equal("Foo", description.Name);
        }
        public void DeclareArgumentWithProperty()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor <CustomDirective> desc = descriptor;

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

            Assert.Collection(description.Arguments,
                              t => Assert.Equal("fieldA", t.Name),
                              t => Assert.Equal("fieldB", t.Name));
        }
        public void IgnoreArgumentBinding()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor <CustomDirective> desc = descriptor;

            desc.Argument(t => t.FieldA).Ignore();

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

            Assert.Collection(description.Arguments,
                              t => Assert.Equal("fieldB", t.Name));
        }
        public void DeclareArgument()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor();

            // act
            IDirectiveTypeDescriptor desc = descriptor;

            desc.Name("Foo");
            desc.Argument("arg").Type <BooleanType>();;

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

            Assert.Equal("arg", description.Arguments.Single().Name);
        }
        public void DeclareExplicitArgumentBinding()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor <CustomDirective> desc = descriptor;

            desc.BindArguments(BindingBehavior.Explicit);
            desc.Argument(t => t.FieldA);

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

            Assert.Collection(description.Arguments,
                              t => Assert.Equal("fieldA", t.Name));
        }
        public void DeclareLocation()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor();

            // act
            IDirectiveTypeDescriptor desc = descriptor;

            desc.Name("Foo");
            desc.Location(DirectiveLocation.Enum);
            desc.Location(DirectiveLocation.Enum);
            desc.Location(DirectiveLocation.EnumValue);

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

            Assert.Collection(description.Locations,
                              t => Assert.Equal(DirectiveLocation.Enum, t),
                              t => Assert.Equal(DirectiveLocation.EnumValue, t));
        }
        public void DeclareArgumentAndSpecifyType()
        {
            // arrange
            var descriptor = new DirectiveTypeDescriptor <CustomDirective>();

            // act
            IDirectiveTypeDescriptor <CustomDirective> desc = descriptor;

            desc.Argument(t => t.FieldA).Type <NonNullType <StringType> >();

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

            Assert.Collection(description.Arguments,
                              t => Assert.Equal(
                                  typeof(NonNullType <StringType>),
                                  t.TypeReference.ClrType),
                              t => Assert.Equal(
                                  typeof(string),
                                  t.TypeReference.ClrType));
        }
Esempio n. 9
0
        private void Initialize(Action <IDirectiveTypeDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            DirectiveTypeDescriptor descriptor = CreateDescriptor();

            configure(descriptor);

            DirectiveTypeDescription description =
                descriptor.CreateDescription();

            ClrType     = description.ClrType;
            SyntaxNode  = description.SyntaxNode;
            Name        = description.Name;
            Description = description.Description;
            Locations   = description.Locations.ToList().AsReadOnly();
            Arguments   = new FieldCollection <InputField>(
                description.Arguments.Select(t => new InputField(t)));
            _middleware = description.Middleware;
        }