public void Deserialize_List() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.ArgumentValue <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); var toDeserialize = new List <object> { new StringValueNode("Foo"), new StringValueNode("Bar") }; // act object value = type.Deserialize(toDeserialize); // assert Assert.Collection( Assert.IsType <object[]>(value) !, x => Assert.Equal("Foo", x), x => Assert.Equal("Bar", x)); }
public void Deserialize_NestedDictionary() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.ArgumentValue <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); var toDeserialize = new Dictionary <string, object> { { "Foo", new Dictionary <string, object> { { "Bar", new StringValueNode("Baz") } } } }; // act object value = type.Deserialize(toDeserialize); // assert object innerDictionary = Assert.IsType <Dictionary <string, object> >(value)["Foo"]; Assert.Equal("Baz", Assert.IsType <Dictionary <string, object> >(innerDictionary)["Bar"]); }
public void ParseValue_Foo() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.Argument <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); // act IValueNode literal = type.ParseValue(new Foo()); // assert Assert.IsType <ObjectValueNode>(literal); }
public void ParseValue_ScalarValues(object value, Type expectedType) { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.Argument <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); // act IValueNode literal = type.ParseValue(value); // assert Assert.IsType(expectedType, literal); }
public void IsInstanceOfType_Null_ArgumentNullException() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.Argument <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); // act Action action = () => type.IsInstanceOfType(null); // assert Assert.Throws <ArgumentNullException>(action); }
public void IsInstanceOfType_NullValue_True() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.Argument <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); // act bool result = type.IsInstanceOfType(NullValueNode.Default); // assert Assert.True(result); }
public void Deserialize_ValueNode() { // arrange ISchema schema = SchemaBuilder.New() .AddQueryType(d => d .Name("Query") .Field("foo") .Type <AnyType>() .Argument("input", a => a.Type <AnyType>()) .Resolver(ctx => ctx.ArgumentValue <object>("input"))) .Create(); AnyType type = schema.GetType <AnyType>("Any"); // act object value = type.Deserialize(new StringValueNode("Foo")); // assert Assert.Equal("Foo", value); }