public void Replace_Variable_In_Object_List_Object() { // arrange ISchema schema = CreateSchemaBuilder() .AddType(new InputObjectType(d => d .Name("Foo1") .Field("bar") .Type(new ListTypeNode(new NamedTypeNode("Foo2"))))) .AddType(new InputObjectType(d => d .Name("Foo2") .Field("bar") .Type <ListType <StringType> >())) .Create(); var value = new ObjectValueNode( new ObjectFieldNode( "bar", new ListValueNode( new ObjectValueNode( new ObjectFieldNode( "bar", new VariableNode("abc")))))); var type = schema.GetType <InputObjectType>("Foo1"); var variables = new VariableCollectionMock("abc", "def"); var typeConversion = new TypeConversion(); // act IValueNode rewritten = VariableToValueRewriter.Rewrite( value, type, variables, typeConversion); // assert QuerySyntaxSerializer.Serialize(rewritten).MatchSnapshot(); }
public void Value_Is_Null() { // arrange ISchema schema = CreateSchemaBuilder() .AddType(new InputObjectType(d => d .Name("Foo") .Field("bar").Type <StringType>())) .Create(); var type = schema.GetType <InputObjectType>("Foo"); var variables = Mock.Of <IVariableValueCollection>(); var typeConversion = new TypeConversion(); // act Action action = () => VariableToValueRewriter.Rewrite( null, type, variables, typeConversion); // assert Assert.Throws <ArgumentNullException>(action); }
public void Variables_Is_Null() { // arrange ISchema schema = CreateSchemaBuilder() .AddType(new InputObjectType(d => d .Name("Foo") .Field("bar").Type <StringType>())) .Create(); var value = new ObjectValueNode( new ObjectFieldNode( "a", new StringValueNode("abc"))); var type = schema.GetType <InputObjectType>("Foo"); var typeConversion = new TypeConversion(); // act Action action = () => VariableToValueRewriter.Rewrite( value, type, null, typeConversion); // assert Assert.Throws <ArgumentNullException>(action); }
public void Cannot_Convert_Variable() { // arrange ISchema schema = CreateSchemaBuilder() .AddType(new InputObjectType(d => d .Name("Foo") .Field("bar").Type <StringType>())) .Create(); var value = new ObjectValueNode( new ObjectFieldNode( "bar", new VariableNode("abc"))); var type = schema.GetType <InputObjectType>("Foo"); var variables = new VariableCollectionMock("abc", new Foo()); var typeConversion = new TypeConversion(); // act Action action = () => VariableToValueRewriter.Rewrite( value, type, variables, typeConversion); // assert Assert.Throws <QueryException>(action).Errors.MatchSnapshot(); }