public void OverwriteName()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                "Field", typeof(ObjectField).GetProperty("Arguments"),
                typeof(IReadOnlyDictionary <string, InputField>));

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

            // assert
            Assert.Equal("args", descriptor.CreateDescription().Name);
        }
Exemplo n.º 2
0
        private static ObjectFieldDescription ExecuteConfigure(
            NameString fieldName,
            Action <IObjectFieldDescriptor> configure)
        {
            if (configure == null)
            {
                throw new ArgumentNullException(nameof(configure));
            }

            var descriptor = new ObjectFieldDescriptor(fieldName);

            configure(descriptor);
            return(descriptor.CreateDescription());
        }
Exemplo n.º 3
0
        public void OverwriteName()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

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

            // assert
            Assert.Equal("args", descriptor.CreateDescription().Name);
        }
        public void SchemaTypesOverwriteDotNetTypes()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor("Type", "field");

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

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

            Assert.Equal(typeof(ListType <StringType>), typeRef.ClrType);
        }
Exemplo n.º 5
0
        public void SetDescription()
        {
            // arrange
            string expectedDescription = Guid.NewGuid().ToString();
            var    descriptor          = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

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

            // assert
            Assert.Equal(expectedDescription,
                         descriptor.CreateDescription().Description);
        }
Exemplo n.º 6
0
        public void ResolverTypeIsSet()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            descriptor.ResolverType(typeof(string));

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

            Assert.Equal(typeof(ObjectField), description.SourceType);
            Assert.Equal(typeof(string), description.ResolverType);
        }
Exemplo n.º 7
0
        public void SourceTypeIsSet()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

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

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

            Assert.Equal(typeof(ObjectField), description.SourceType);
        }
Exemplo n.º 8
0
        public void ResolverTypesDoNotOverwriteSchemaTypes()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Name("args")
            .Type <NonNullType <ListType <NonNullType <__InputValue> > > >()
            .Resolver(c => c.Parent <ObjectField>().Arguments);

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

            Assert.Equal(typeof(NonNullType <ListType <NonNullType <__InputValue> > >), typeRef.ClrType);
        }
Exemplo n.º 9
0
        public void SetResolverAndInferTypeIsAlwaysRecognosedAsDotNetType()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                typeof(ObjectField).GetProperty("Arguments"),
                typeof(ObjectField));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Type <__Type>()
            .Resolver(ctx => ctx.Schema
                      .GetType <INamedType>(ctx.Argument <string>("type")));

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

            Assert.Equal(typeof(__Type), description.TypeReference.ClrType);
            Assert.NotNull(description.Resolver);
        }
        public void SetResolverAndInferTypeFromResolver()
        {
            // arrange
            var descriptor = new ObjectFieldDescriptor(
                "Field", typeof(ObjectField).GetProperty("Arguments"),
                typeof(IReadOnlyDictionary <string, InputField>));

            // act
            ((IObjectFieldDescriptor)descriptor)
            .Resolver(() => "ThisIsAString");

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

            Assert.Equal(typeof(NativeType <string>), description.TypeReference.NativeType);
            Assert.NotNull(description.Resolver);

            Mock <IResolverContext> context = new Mock <IResolverContext>(MockBehavior.Strict);

            Assert.Equal("ThisIsAString", description.Resolver(context.Object, default));
        }