Exemplo n.º 1
0
        public void Schema_Type_Cache_Id_Distinguishes_Between_NonNull_And_Nullable()
        {
            // arrange
            // act
            ExtendedType extendedType1 = ExtendedType.FromType(
                typeof(NonNullType <ListType <StringType> >),
                _cache);

            ExtendedType extendedType2 = ExtendedType.FromType(
                typeof(NonNullType <StringType>),
                _cache);

            ExtendedType extendedType3 = ExtendedType.FromType(
                typeof(ListType <StringType>),
                _cache);

            ExtendedType extendedType4 = ExtendedType.FromType(
                typeof(StringType),
                _cache);

            // assert
            Assert.False(extendedType1.IsNullable);
            Assert.False(extendedType2.IsNullable);
            Assert.True(extendedType3.IsNullable);
            Assert.True(extendedType4.IsNullable);
        }
Exemplo n.º 2
0
        public void SupportedListTypes(Type type, string listTypeName, string elementTypeName)
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(type, _cache);

            // assert
            Assert.Equal(listTypeName, extendedType.ToString());
            Assert.Equal(elementTypeName, extendedType.ElementType?.ToString());
        }
Exemplo n.º 3
0
        public void IsEqual_Object_Byte_Null_False()
        {
            // arrange
            ExtendedType a = ExtendedType.FromType(typeof(byte), _cache);

            // act
            var result = a.Equals(default(object));

            // assert
            Assert.False(result);
        }
Exemplo n.º 4
0
        public void IsEqual_Ref_Object_Byte_Byte_True()
        {
            // arrange
            ExtendedType a = ExtendedType.FromType(typeof(byte), _cache);

            // act
            var result = a.Equals((object)a);

            // assert
            Assert.True(result);
        }
Exemplo n.º 5
0
        public void From_SchemaType_ListOfString()
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(typeof(ListType <StringType>), _cache);

            // assert
            Assert.True(extendedType.IsSchemaType);
            Assert.True(extendedType.IsGeneric);
            Assert.Collection(extendedType.TypeArguments.Select(t => t.Type),
                              t => Assert.Equal(typeof(StringType), t));
        }
Exemplo n.º 6
0
        public void From_SystemType_Dict()
        {
            // arrange
            // act
            ExtendedType dict = ExtendedType.FromType(
                typeof(Dictionary <string, string>),
                _cache);

            // assert
            Assert.True(dict.IsList);
            Assert.True(dict.IsArrayOrList);
        }
Exemplo n.º 7
0
        public void IsEqual_Object_Byte_String_False()
        {
            // arrange
            ExtendedType a = ExtendedType.FromType(typeof(byte), _cache);
            ExtendedType b = ExtendedType.FromType(typeof(string), _cache);

            // act
            var result = a.Equals((object)b);

            // assert
            Assert.False(result);
        }
Exemplo n.º 8
0
        public void From_SystemType_Array()
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(typeof(byte[]), _cache);

            // assert
            Assert.True(extendedType.IsArray);
            Assert.Collection(
                extendedType.TypeArguments.Select(t => t.Type),
                t => Assert.Equal(typeof(byte), t));
        }
Exemplo n.º 9
0
        public void IsEqual_Byte_Byte_True()
        {
            // arrange
            ExtendedType a = ExtendedType.FromType(typeof(byte), _cache);
            ExtendedType b = ExtendedType.FromType(typeof(byte), _cache);

            // act
            var result = a.Equals(b);

            // assert
            Assert.True(result);
        }
Exemplo n.º 10
0
        public void From_IExecutableScalar()
        {
            // arrange
            // act
            ExtendedType dict = ExtendedType.FromType(
                typeof(IExecutable <string>),
                _cache);

            // assert
            Assert.True(dict.IsList);
            Assert.True(dict.IsArrayOrList);
        }
Exemplo n.º 11
0
        public void From_SchemaType_NonNullListOfString()
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(
                typeof(NonNullType <ListType <StringType> >),
                _cache);

            // assert
            Assert.True(extendedType.IsSchemaType);
            Assert.True(extendedType.IsGeneric);
            Assert.False(extendedType.IsNullable);
        }
Exemplo n.º 12
0
        public void ChangeNullability_From_ElementType(Type listType)
        {
            // arrange
            // act
            IExtendedType list = ExtendedType.FromType(listType, _cache);

            list = ExtendedType.Tools.ChangeNullability(
                list, new bool?[] { null, false }, _cache);

            // assert
            Assert.False(list.ElementType !.IsNullable);
            Assert.Same(list.ElementType, list.TypeArguments[0]);
        }
Exemplo n.º 13
0
        public void From_NativeTypeIntType()
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(
                typeof(NativeType <IntType>),
                _cache);

            // assert
            Assert.True(extendedType.IsSchemaType);
            Assert.False(extendedType.IsGeneric);
            Assert.True(extendedType.IsNullable);
        }
            public static IReadOnlyList <ExtendedType> GetGenericArguments(
                Type type,
                TypeCache cache)
            {
                if (type.IsGenericType)
                {
                    Type[]         arguments         = type.GetGenericArguments();
                    ExtendedType[] extendedArguments = new ExtendedType[arguments.Length];

                    for (int i = 0; i < arguments.Length; i++)
                    {
                        extendedArguments[i] = ExtendedType.FromType(arguments[i], cache);
                    }

                    return(extendedArguments);
                }

                return(Array.Empty <ExtendedType>());
            }
Exemplo n.º 15
0
        public void From_InputObjectOfIntType()
        {
            // arrange
            // act
            ExtendedType extendedType = ExtendedType.FromType(
                typeof(InputObjectType <IntType>),
                _cache);

            // assert
            Assert.True(extendedType.IsSchemaType);
            Assert.True(extendedType.IsGeneric);
            Assert.True(extendedType.IsNamedType);
            Assert.True(extendedType.IsNullable);

            IExtendedType argument = extendedType.TypeArguments[0];

            Assert.True(argument.IsSchemaType);
            Assert.False(argument.IsGeneric);
            Assert.True(extendedType.IsNamedType);
            Assert.True(argument.IsNullable);
        }
Exemplo n.º 16
0
        public void From_SystemType_List()
        {
            // arrange
            // act
            IExtendedType list = ExtendedType.FromType(
                typeof(NativeType <List <byte?> >),
                _cache);

            list = ExtendedType.Tools.ChangeNullability(
                list, new bool?[] { false }, _cache);

            ExtendedType nullableList = ExtendedType.FromType(
                typeof(List <byte?>),
                _cache);

            // assert
            Assert.True(list.IsList);
            Assert.True(list.IsArrayOrList);
            Assert.False(list.IsNullable);
            Assert.True(nullableList.IsList);
            Assert.True(nullableList.IsArrayOrList);
            Assert.True(nullableList.IsNullable);
        }