Ejemplo n.º 1
0
 public static ClrTypeReference FromSchemaType <T>()
     where T : ITypeSystemMember
 {
     return(new ClrTypeReference(
                typeof(T),
                SchemaTypeReference.InferTypeContext(typeof(T))));
 }
        public async Task SchemaTypeReference_GetHashCode()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(
                stringType,
                scope: "foo");

            SchemaTypeReference y = TypeReference.Create(
                stringType,
                scope: "foo");

            SchemaTypeReference z = TypeReference.Create(
                stringType);

            // act
            var xh = x.GetHashCode();
            var yh = y.GetHashCode();
            var zh = z.GetHashCode();

            // assert
            Assert.Equal(xh, yh);
            Assert.NotEqual(xh, zh);
        }
        public void SchemaTypeReference_InferTypeContext_Object_From_SchemaType()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext((object)typeof(ObjectType <Foo>));

            // assert
            Assert.Equal(TypeContext.Output, context);
        }
        public void SchemaTypeReference_InferTypeContext_Object_From_String_None()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext((object)"foo");

            // assert
            Assert.Equal(TypeContext.None, context);
        }
        public void SchemaTypeReference_InferTypeContext_From_RuntimeType_None()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext(typeof(Foo));

            // assert
            Assert.Equal(TypeContext.None, context);
        }
        public async Task SchemaTypeReference_Equals_To_Null()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type);

            // act
            var result = x.Equals((SchemaTypeReference)null);

            // assert
            Assert.False(result);
        }
        public async Task SchemaTypeReference_ToString()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference typeReference = TypeReference.Create(type);

            // act
            var result = typeReference.ToString();

            // assert
            Assert.Equal("None: HotChocolate.Types.StringType", result);
        }
        public async Task Object_Equals_To_Object()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type);

            // act
            var xx = x.Equals(new object());

            // assert
            Assert.False(xx);
        }
        public async Task ITypeReference_Equals_To_SyntaxTypeRef()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type);

            // act
            var xx = x.Equals(TypeReference.Create(new NameType("foo")));

            // assert
            Assert.False(xx);
        }
        public async Task SchemaTypeReference_Equals_To_Same()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type);

            // act
            var xx = x.Equals((SchemaTypeReference)x);

            // assert
            Assert.True(xx);
        }
        public async Task TypeReference_Create_From_ScalarType()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            // act
            SchemaTypeReference typeReference = TypeReference.Create(
                type,
                scope: "abc");

            // assert
            Assert.Equal(type, typeReference.Type);
            Assert.Equal(TypeContext.None, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
        }
        public async Task SchemaTypeReference_With_Type_Null()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            SchemaTypeReference typeReference1 = TypeReference.Create(
                stringType,
                scope: "foo");

            // act
            Action action = () => typeReference1.With(null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
        public async Task TypeReference_Create_From_InputType()
        {
            // arrange
            InputObjectType <Bar> type = await CreateTypeAsync <InputObjectType <Bar> >();

            // act
            SchemaTypeReference typeReference = TypeReference.Create(
                type,
                scope: "abc");

            // assert
            Assert.Equal(type, typeReference.Type);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
        }
        public async Task SchemaTypeReference_With_Scope()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            SchemaTypeReference typeReference1 = TypeReference.Create(
                stringType,
                scope: "foo");

            // act
            SchemaTypeReference typeReference2 = typeReference1.With(scope: "bar");

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(typeReference1.Context, typeReference2.Context);
            Assert.Equal("bar", typeReference2.Scope);
        }
        public async Task SchemaTypeReference_WithContext_Nothing()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            SchemaTypeReference typeReference1 = TypeReference.Create(
                stringType,
                scope: "foo");

            // act
            SchemaTypeReference typeReference2 = typeReference1.WithContext();

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(TypeContext.None, typeReference2.Context);
            Assert.Equal(typeReference1.Scope, typeReference2.Scope);
        }
        public async Task TypeReference_Create_From_ScalarType()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            // act
            SchemaTypeReference typeReference = TypeReference.Create(
                type,
                scope: "abc",
                nullable: new bool[] { true });

            // assert
            Assert.Equal(type, typeReference.Type);
            Assert.Equal(TypeContext.None, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
            Assert.Collection(typeReference.Nullable !, Assert.True);
        }
        public async Task TypeReference_Create_From_InputType()
        {
            // arrange
            InputObjectType <Bar> type = await CreateTypeAsync <InputObjectType <Bar> >();

            // act
            SchemaTypeReference typeReference = TypeReference.Create(
                type,
                scope: "abc",
                nullable: new bool[] { true });

            // assert
            Assert.Equal(type, typeReference.Type);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
            Assert.Collection(typeReference.Nullable !, Assert.True);
        }
Ejemplo n.º 18
0
        public static ClrTypeReference FromSchemaType(Type schemaType)
        {
            if (schemaType == null)
            {
                throw new ArgumentNullException(nameof(schemaType));
            }

            if (typeof(ITypeSystemMember).IsAssignableFrom(schemaType))
            {
                return(new ClrTypeReference(
                           schemaType,
                           SchemaTypeReference.InferTypeContext(schemaType)));
            }

            throw new ArgumentException(
                      TypeResources.ClrTypeReference_OnlyTsosAreAllowed);
        }
        public async Task SchemaTypeReference_Equals_Scope_Different()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type, scope: "abc");
            SchemaTypeReference y = TypeReference.Create(type, scope: "def");
            SchemaTypeReference z = TypeReference.Create(type, scope: "abc");

            // act
            var xy = x.Equals(y);
            var xz = x.Equals(y);

            // assert
            Assert.False(xy);
            Assert.False(xz);
        }
Ejemplo n.º 20
0
        public static ClrTypeReference FromSchemaType(Type schemaType)
        {
            if (schemaType == null)
            {
                throw new ArgumentNullException(nameof(schemaType));
            }

            if (typeof(ITypeSystem).IsAssignableFrom(schemaType))
            {
                return(new ClrTypeReference(
                           schemaType,
                           SchemaTypeReference.InferTypeContext(schemaType)));
            }

            // TODO : resources
            throw new ArgumentException(
                      "Only type system objects are allowed.");
        }
        public async Task Object_Equals_Nullability()
        {
            // arrange
            StringType type = await CreateTypeAsync <StringType>();

            SchemaTypeReference x = TypeReference.Create(type, nullable: new[] { true, false });
            SchemaTypeReference y = TypeReference.Create(type, nullable: new[] { false, false });
            SchemaTypeReference z = TypeReference.Create(type, nullable: new[] { true, false });

            // act
            var xy = x.Equals((object)y);
            var xz = x.Equals((object)z);
            var yz = y.Equals((object)z);

            // assert
            Assert.False(xy);
            Assert.True(xz);
            Assert.False(yz);
        }
        public async Task SchemaTypeReference_With_Nullable()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            SchemaTypeReference typeReference1 = TypeReference.Create(
                stringType,
                scope: "foo",
                nullable: new[] { true });

            // act
            SchemaTypeReference typeReference2 = typeReference1.With(nullable: null);

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(typeReference1.Context, typeReference2.Context);
            Assert.Equal(typeReference1.Scope, typeReference2.Scope);
            Assert.Null(typeReference2.Nullable);
        }
Ejemplo n.º 23
0
        public bool Equals(SchemaTypeReference other)
        {
            if (other is null)
            {
                return(false);
            }

            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            if (Type == other.Type ||
                (Type is IType a && other.Type is IType b && a.IsEqualTo(b)))
            {
                return(Context == other.Context &&
                       IsTypeNullable.Equals(other.IsTypeNullable) &&
                       IsElementTypeNullable.Equals(other.IsElementTypeNullable));
            }

            return(false);
        }
        public async Task SchemaTypeReference_With()
        {
            // arrange
            StringType stringType = await CreateTypeAsync <StringType>();

            IntType intType = await CreateTypeAsync <IntType>();

            SchemaTypeReference typeReference1 = TypeReference.Create(
                stringType,
                scope: "foo",
                nullable: new[] { true });

            // act
            SchemaTypeReference typeReference2 = typeReference1.With(
                intType,
                scope: "bar",
                nullable: new[] { false });

            // assert
            Assert.Equal(intType, typeReference2.Type);
            Assert.Equal(TypeContext.None, typeReference2.Context);
            Assert.Equal("bar", typeReference2.Scope);
            Assert.Collection(typeReference2.Nullable !, Assert.False);
        }