public void ContextIsNull()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("contextData"),
                new NameNode("b"));

            // act
            var    resolver = new ContextDataScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                null,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("context", Assert.Throws <ArgumentNullException>(a).ParamName);
        }
        public void ContextDataEntryDoesNotExist()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var contextData = new Dictionary <string, object>();

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

            context.SetupGet(t => t.ContextData).Returns(contextData);

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("contextData"),
                new NameNode("a"));

            // act
            var           resolver = new ContextDataScopedVariableResolver();
            VariableValue value    = resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Null(value.DefaultValue);
            Assert.Equal("contextData_a", value.Name);
            Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value);
            Assert.Equal(NullValueNode.Default, value.Value);
        }
        public void InvalidScope()
        {
            // arrange
            var schema = Schema.Create(
                "type Query { foo(a: String = \"bar\") : String }",
                c =>
            {
                c.UseNullResolver();
                c.Options.StrictValidation = false;
            });

            var context = new Mock <IMiddlewareContext>();

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("foo"),
                new NameNode("b"));

            // act
            var    resolver = new ContextDataScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("variable", Assert.Throws <ArgumentException>(a).ParamName);
        }
Exemplo n.º 4
0
        public void InvalidScope()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }")
                             .Use(_ => _)
                             .ModifyOptions(o => o.StrictValidation = false)
                             .Create();

            var context = new Mock <IMiddlewareContext>();

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("foo"),
                new NameNode("b"));

            // act
            var    resolver = new ContextDataScopedVariableResolver();
            Action a        = () => resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Equal("variable", Assert.Throws <ArgumentException>(a).ParamName);
        }
Exemplo n.º 5
0
        public void TargetTypeIsNull()
        {
            // arrange
            var context = new Mock <IMiddlewareContext>();

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("contextData"),
                new NameNode("b"));

            // act
            var resolver = new ContextDataScopedVariableResolver();

            void Action() => resolver.Resolve(context.Object, scopedVariable, null !);

            // assert
            Assert.Equal("targetType", Assert.Throws <ArgumentNullException>(Action).ParamName);
        }
Exemplo n.º 6
0
        public void CreateVariableValue()
        {
            // arrange
            var inputFormatter = new InputFormatter();

            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }")
                             .Use(_ => _)
                             .ModifyOptions(o => o.StrictValidation = false)
                             .Create();

            var contextData = new Dictionary <string, object> {
                ["a"] = "AbcDef"
            };

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

            context.SetupGet(t => t.ContextData).Returns(contextData);
            context.Setup(t => t.Service <InputFormatter>()).Returns(inputFormatter);

            var scopedVariable = new ScopedVariableNode(
                null,
                new NameNode("contextData"),
                new NameNode("a"));

            // act
            var resolver = new ContextDataScopedVariableResolver();
            ScopedVariableValue value = resolver.Resolve(
                context.Object,
                scopedVariable,
                schema.GetType <StringType>("String"));

            // assert
            Assert.Null(value.DefaultValue);
            Assert.Equal("__contextData_a", value.Name);
            Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value);
            Assert.Equal("AbcDef", value.Value?.Value);
        }