Ejemplo n.º 1
0
        public void AsyncResolverMethodGenerator_GenerateWithSourceArgumentAndTwoArguments()
        {
            // arrange
            FieldResolverArgumentDescriptor argumentDescriptor1 =
                FieldResolverArgumentDescriptor.Create("a",
                                                       FieldResolverArgumentKind.Source,
                                                       typeof(GeneratorTestDummy));

            FieldResolverArgumentDescriptor argumentDescriptor2 =
                FieldResolverArgumentDescriptor.Create("b",
                                                       FieldResolverArgumentKind.Argument,
                                                       typeof(string));

            FieldResolverArgumentDescriptor argumentDescriptor3 =
                FieldResolverArgumentDescriptor.Create("c",
                                                       FieldResolverArgumentKind.Argument,
                                                       typeof(int));

            Type       sourceType = typeof(GeneratorTestDummy);
            MethodInfo method     = typeof(GeneratorTestDummyResolver).GetMethods()
                                    .Single(t => t.Name == "GetFooAsync" && t.GetParameters().Length == 3);
            FieldResolverDescriptor descriptor = FieldResolverDescriptor
                                                 .CreateCollectionMethod(new FieldReference("Foo", "bar"),
                                                                         method.ReflectedType, sourceType, method, true,
                                                                         new[] { argumentDescriptor1, argumentDescriptor2, argumentDescriptor3 });

            // act
            StringBuilder source = new StringBuilder();
            AsyncResolverMethodGenerator generator = new AsyncResolverMethodGenerator();
            string result = generator.Generate("abc", descriptor);

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }
        public void AsyncResolverMethodGenerator_GenerateWithContext()
        {
            // arrange
            var descriptor = CreateDescriptor(ArgumentKind.Context);

            // act
            var    source    = new StringBuilder();
            var    generator = new AsyncResolverMethodGenerator();
            string result    = generator.Generate("abc", descriptor);

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }
Ejemplo n.º 3
0
        public void AsyncResolverMethodGenerator_GenerateWithContext()
        {
            // arrange
            ResolverDescriptor descriptor = CreateDescriptor(ArgumentKind.Context);

            // act
            var    source    = new StringBuilder();
            var    generator = new AsyncResolverMethodGenerator();
            string result    = generator.Generate("abc", descriptor);

            // assert
            result.MatchSnapshot();
        }
        public void AsyncResolverMethodGenerator_GenerateWithQueryService()
        {
            // arrange
            var descriptor = CreateDescriptor(ArgumentKind.Service);

            var source    = new StringBuilder();
            var generator = new AsyncResolverMethodGenerator();

            // act
            string result = generator.Generate("abc", descriptor);

            // assert
            result.MatchSnapshot();
        }
        public void AsyncResolverMethodGenerator_GenerateWithCancellationToken()
        {
            // arrange
            var descriptor = CreateDescriptor(ArgumentKind.CancellationToken);

            var source    = new StringBuilder();
            var generator = new AsyncResolverMethodGenerator();

            // act
            string result = generator.Generate("abc", descriptor);

            // assert
            result.Snapshot();
        }
        public void AsyncResolverMethodGenerator_GenerateWithSourceArgument()
        {
            // arrange
            Type sourceType = typeof(GeneratorTestDummy);

            var fieldMember = new FieldMember(
                "Foo", "bar",
                GetMethod <GeneratorTestDummyResolver>("GetFooAsync", 1));

            var descriptor = new ResolverDescriptor(sourceType, fieldMember);
            var source     = new StringBuilder();
            var generator  = new AsyncResolverMethodGenerator();

            // act
            string result = generator.Generate("abc", descriptor);

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }
        public void AsyncResolverMethodGenerator_GenerateWithoutArguments()
        {
            // arrange
            Type sourceType = typeof(GeneratorTestDummy);

            var fieldMember = new FieldMember(
                "Foo", "bar",
                GetMethod <GeneratorTestDummyResolver>("GetFooAsync", 0));

            var descriptor = new ResolverDescriptor(sourceType, fieldMember);
            var source     = new StringBuilder();
            var generator  = new AsyncResolverMethodGenerator();

            // act
            string result = generator.Generate("abc", descriptor);

            // assert
            result.MatchSnapshot();
        }
Ejemplo n.º 8
0
        public void AsyncResolverMethodGenerator_GenerateWithoutArguments()
        {
            // arrange
            Type       sourceType = typeof(GeneratorTestDummy);
            MethodInfo method     = typeof(GeneratorTestDummyResolver).GetMethods()
                                    .Single(t => t.Name == "GetFooAsync" && t.GetParameters().Length == 0);
            FieldResolverDescriptor descriptor = FieldResolverDescriptor
                                                 .CreateCollectionMethod(new FieldReference("Foo", "bar"),
                                                                         method.ReflectedType, sourceType, method, true,
                                                                         Enumerable.Empty <FieldResolverArgumentDescriptor>());

            // act
            StringBuilder source = new StringBuilder();
            AsyncResolverMethodGenerator generator = new AsyncResolverMethodGenerator();
            string result = generator.Generate("abc", descriptor);

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }
        public void AsyncResolverMethodGenerator_GenerateWithQueryService()
        {
            // arrange
            var argumentDescriptor =
                new FieldResolverArgumentDescriptor("a", "b",
                                                    FieldResolverArgumentKind.Service,
                                                    typeof(GeneratorTestDummy));

            var        sourceType = typeof(GeneratorTestDummy);
            MethodInfo method     = typeof(GeneratorTestDummyResolver).GetMethods()
                                    .Single(t => t.Name == "GetFooAsync" && t.GetParameters().Length == 1);
            var descriptor = FieldResolverDescriptor
                             .CreateCollectionMethod(new FieldReference("Foo", "bar"),
                                                     method.ReflectedType, sourceType, method, true,
                                                     new[] { argumentDescriptor });

            // act
            var    source    = new StringBuilder();
            var    generator = new AsyncResolverMethodGenerator();
            string result    = generator.Generate("abc", descriptor);

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }