public void CreateVariableValue() { // arrange var inputFormatter = new InputFormatter(); ISchema schema = SchemaBuilder.New() .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String a: String }") .Use(_ => _) .ModifyOptions(o => o.StrictValidation = false) .Create(); var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.ObjectType).Returns( schema.GetType <ObjectType>("Query")); context.SetupGet(t => t.Field).Returns( schema.GetType <ObjectType>("Query").Fields["foo"]); context.Setup(t => t.Parent <object>()) .Returns(new Dictionary <string, object> { { "a", "baz" } }); context.Setup(t => t.Service <InputFormatter>()).Returns(inputFormatter); var scopedVariable = new ScopedVariableNode( null, new NameNode("fields"), new NameNode("a")); // act var resolver = new FieldScopedVariableResolver(); ScopedVariableValue value = resolver.Resolve( context.Object, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Null(value.DefaultValue); Assert.Equal("__fields_a", value.Name); Assert.IsType <NamedTypeNode>(value.Type); Assert.Equal("baz", value.Value.Value); }
public void CreateVariableValue() { // arrange ISchema schema = SchemaBuilder.New() .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }") .Use(_ => _) .ModifyOptions(o => o.StrictValidation = false) .Create(); ObjectField field = schema.GetType <ObjectType>("Query").Fields["foo"]; var selection = new Mock <IFieldSelection>(MockBehavior.Strict); selection.SetupGet(t => t.Field).Returns(field); var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.Selection).Returns(selection.Object); context.Setup(t => t.ArgumentLiteral <IValueNode>("a")) .Returns(new StringValueNode("baz")); var scopedVariable = new ScopedVariableNode( null, new NameNode("arguments"), new NameNode("a")); // act var resolver = new ArgumentScopedVariableResolver(); ScopedVariableValue value = resolver.Resolve( context.Object, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Equal("bar", Assert.IsType <StringValueNode>(value.DefaultValue).Value); Assert.Equal("__arguments_a", value.Name); Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value); Assert.Equal("baz", value.Value !.Value); }
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(); ImmutableDictionary <string, object> contextData = ImmutableDictionary <string, object> .Empty .Add("a", "AbcDef"); var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.ScopedContextData).Returns(contextData); context.Setup(t => t.Service <InputFormatter>()).Returns(inputFormatter); var scopedVariable = new ScopedVariableNode( null, new NameNode("scopedContextData"), new NameNode("a")); // act var resolver = new ScopedContextDataScopedVariableResolver(); ScopedVariableValue value = resolver.Resolve( context.Object, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Null(value.DefaultValue); Assert.Equal("__scopedContextData_a", value.Name); Assert.Equal("String", Assert.IsType <NamedTypeNode>(value.Type).Name.Value); Assert.Equal("AbcDef", value.Value !.Value); }