예제 #1
0
        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));
        }
예제 #2
0
        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"]);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }