Example #1
0
        public static DescriptorContext Create(IServiceProvider services)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var naming =
                (INamingConventions)services.GetService(
                    typeof(INamingConventions));

            if (naming == null)
            {
                naming = new DefaultNamingConventions();
            }

            var inspector =
                (ITypeInspector)services.GetService(
                    typeof(ITypeInspector));

            if (inspector == null)
            {
                inspector = new DefaultTypeInspector();
            }

            return(new DescriptorContext(naming, inspector));
        }
Example #2
0
        public void ExtractNamedType_From_SchemaType()
        {
            // arrange
            var typeInspector = new DefaultTypeInspector();

            // act
            Type type = typeInspector.ExtractNamedType(typeof(ListType <StringType>));

            // assert
            Assert.Equal(typeof(StringType), type);
        }
Example #3
0
        public void GetEnumValueMember_Type_Is_Null()
        {
            // arrange
            var typeInspector = new DefaultTypeInspector();

            // act
            void Action() => typeInspector.GetEnumValueMember(null !);

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
Example #4
0
        public void GetEnumValueMember()
        {
            // arrange
            var typeInspector = new DefaultTypeInspector();

            // act
            MemberInfo valueMember = typeInspector.GetEnumValueMember(BarEnum.Bar);

            // assert
            Assert.Equal("Bar", valueMember !.Name);
        }
Example #5
0
        public void GetType2_Nullable_Is_Null()
        {
            // arrange
            var typeInspector = new DefaultTypeInspector();

            // act
            void Action() => typeInspector.GetType(typeof(Foo), default(bool?[]) !);

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
Example #6
0
        public void GetEnumValues()
        {
            // arrange
            var typeInspector = new DefaultTypeInspector();

            // act
            IEnumerable <object> values = typeInspector.GetEnumValues(typeof(BarEnum));

            // assert
            Assert.Collection(
                values,
                t => Assert.Equal(BarEnum.Bar, t),
                t => Assert.Equal(BarEnum.Baz, t));
        }
Example #7
0
        public void GetArgumentTypeRef_With_Scope()
        {
            // arrange
            ParameterInfo parameter     = typeof(Foo).GetMethod(nameof(Foo.Baz)) !.GetParameters()[0];
            var           typeInspector = new DefaultTypeInspector();

            // act
            ExtendedTypeReference typeReference = typeInspector.GetArgumentTypeRef(parameter !, "abc");

            // assert
            Assert.Equal("String!", typeReference.Type.ToString());
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
        }
Example #8
0
        public void GetReturnTypeRef_FromMethod_With_Scope()
        {
            // arrange
            var        typeInspector = new DefaultTypeInspector();
            MethodInfo method        = typeof(Foo).GetMethod(nameof(Foo.Bar));
            // act
            ExtendedTypeReference typeReference =
                typeInspector.GetReturnTypeRef(method !, TypeContext.Output, "abc");

            // assert
            Assert.Equal("List<String!>!", typeReference.Type.ToString());
            Assert.Equal(TypeContext.Output, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
        }
        public void Create_With_Custom_TypeInspector()
        {
            // arrange
            var options   = new SchemaOptions();
            var inspector = new DefaultTypeInspector();
            var services  = new DictionaryServiceProvider(
                typeof(ITypeInspector),
                inspector);

            // act
            DescriptorContext context =
                DescriptorContext.Create(options, services);

            // assert
            Assert.Equal(inspector, context.Inspector);
            Assert.NotNull(context.Naming);
            Assert.Equal(options, context.Options);
        }