public void GetArgumentFromCustomDirective()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            var barValue = directive.GetArgument <string>("bar");

            // assert
            Assert.Equal("123", barValue);
        }
        public void MapCustomDirectiveToDifferentType()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            FooChild mappedObject = directive.ToObject <FooChild>();

            // assert
            Assert.Equal("123", mappedObject.Bar);
        }
        public void ConvertCustomDirectiveToDirectiveNode()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = Directive.FromDescription(
                directiveType,
                new DirectiveDefinition(
                    fooDirective,
                    _typeInspector.GetTypeRef(fooDirective.GetType())),
                new object());
            DirectiveNode directiveNode = directive.ToNode();

            // assert
            Assert.Equal(directiveType.Name, directiveNode.Name.Value);
            Assert.Collection(directiveNode.Arguments,
                              t =>
            {
                Assert.Equal("bar", t.Name.Value);
                Assert.Equal("123", ((StringValueNode)t.Value).Value);
            },
                              t =>
            {
                Assert.Equal("child", t.Name.Value);
                Assert.Collection(((ObjectValueNode)t.Value).Fields,
                                  x =>
                {
                    Assert.Equal("bar", x.Name.Value);
                    Assert.Equal("456",
                                 ((StringValueNode)x.Value).Value);
                });
            });
        }
Esempio n. 4
0
        public void GetArgumentFromCustomDirective()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            string barValue = directive.GetArgument <string>("bar");

            // assert
            Assert.Equal("123", barValue);
        }
Esempio n. 5
0
        public void MapCustomDirectiveToDifferentType()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            FooChild mappedObject = directive.ToObject <FooChild>();

            // assert
            Assert.Equal("123", mappedObject.Bar);
        }
Esempio n. 6
0
        public void GetArgumentFromCustomDirectiveAndConvertIt()
        {
            // arrange
            ISchema       schema        = CreateSchema();
            DirectiveType directiveType = schema.GetDirectiveType("Foo");
            var           fooDirective  = new FooDirective
            {
                Bar   = "123",
                Child = new FooChild
                {
                    Bar = "456"
                }
            };

            // act
            var directive = new Directive(
                directiveType, fooDirective, new object());
            FooChild2 barValue = directive.GetArgument <FooChild2>("child");

            // assert
            Assert.Equal("456", barValue.Bar);
        }