public void ContextIsNull() { // arrange ISchema schema = SchemaBuilder.New() .AddDocumentFromString("type Query { foo(a: String = \"bar\") : String }") .Use(_ => _) .ModifyOptions(o => o.StrictValidation = false) .Create(); var scopedVariable = new ScopedVariableNode( null, new NameNode("scopedContextData"), new NameNode("b")); // act var resolver = new ScopedContextDataScopedVariableResolver(); void Action() => resolver.Resolve( null !, scopedVariable, schema.GetType <StringType>("String")); // assert Assert.Equal("context", Assert.Throws <ArgumentNullException>(Action).ParamName); }
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("scopedContextData"), new NameNode("b")); // act var resolver = new ScopedContextDataScopedVariableResolver(); Action a = () => resolver.Resolve(null, scopedVariable, new NamedTypeNode(new NameNode("abc"))); // 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 = ImmutableDictionary <string, object> .Empty; var context = new Mock <IResolverContext>(MockBehavior.Strict); context.SetupGet(t => t.ScopedContextData).Returns(contextData); var scopedVariable = new ScopedVariableNode( null, new NameNode("scopedContextData"), new NameNode("a")); // act var resolver = new ScopedContextDataScopedVariableResolver(); VariableValue value = resolver.Resolve( context.Object, scopedVariable, new NamedTypeNode(new NameNode("abc"))); // assert Assert.Null(value.DefaultValue); Assert.Equal("scopedContextData_a", value.Name); Assert.Equal("abc", Assert.IsType <NamedTypeNode>(value.Type).Name.Value); Assert.Null(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 ScopedContextDataScopedVariableResolver(); Action a = () => resolver.Resolve(context.Object, scopedVariable, new NamedTypeNode(new NameNode("abc"))); // assert Assert.Equal("variable", Assert.Throws <ArgumentException>(a).ParamName); }
public void TargetTypeIsNull() { // arrange var context = new Mock <IMiddlewareContext>(); var scopedVariable = new ScopedVariableNode( null, new NameNode("scopedContextData"), new NameNode("b")); // act var resolver = new ScopedContextDataScopedVariableResolver(); void Action() => resolver.Resolve(context.Object, scopedVariable, null !); // assert Assert.Equal("targetType", Assert.Throws <ArgumentNullException>(Action).ParamName); }
public void ScopedVariableIsNull() { // 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>(); // act var resolver = new ScopedContextDataScopedVariableResolver(); void Action() => resolver.Resolve( context.Object, null !, schema.GetType <StringType>("String")); // assert Assert.Equal("variable", Assert.Throws <ArgumentNullException>(Action).ParamName); }
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); }
public void ScopedVariableIsNull() { // arrange var schema = Schema.Create( "type Query { foo(a: String = \"bar\") : String }", c => { c.UseNullResolver(); c.Options.StrictValidation = false; }); var context = new Mock <IMiddlewareContext>(); // act var resolver = new ScopedContextDataScopedVariableResolver(); Action a = () => resolver.Resolve( context.Object, null, schema.GetType <StringType>("String")); // assert Assert.Equal("variable", Assert.Throws <ArgumentNullException>(a).ParamName); }