Пример #1
0
        public void ResolverPropertyGenerator_Generate()
        {
            // arrange
            PropertyInfo            property   = typeof(GeneratorTestDummyResolver).GetProperties().Single();
            FieldResolverDescriptor descriptor = FieldResolverDescriptor
                                                 .CreateCollectionProperty(new FieldReference("Foo", "bar"),
                                                                           property.ReflectedType, typeof(GeneratorTestDummy), property);

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

            // assert
            Assert.Equal(Snapshot.Current(), Snapshot.New(result));
        }
        private FieldResolverDescriptor CreateResolverDescriptor(
            FieldResolverMember fieldResolverMember,
            Type resolverType, Type sourceType)
        {
            if (fieldResolverMember.Member is PropertyInfo p)
            {
                return(FieldResolverDescriptor.CreateCollectionProperty(
                           fieldResolverMember, resolverType, sourceType, p));
            }
            else if (fieldResolverMember.Member is MethodInfo m)
            {
                bool isAsync = typeof(Task).IsAssignableFrom(m.ReturnType);
                IReadOnlyCollection <FieldResolverArgumentDescriptor> argumentDescriptors =
                    CreateResolverArgumentDescriptors(m, resolverType, sourceType);
                return(FieldResolverDescriptor.CreateCollectionMethod(
                           fieldResolverMember, resolverType, sourceType, m,
                           isAsync, argumentDescriptors));
            }

            throw new NotSupportedException();
        }