コード例 #1
0
 public static ClrTypeReference FromSchemaType <T>()
     where T : ITypeSystemMember
 {
     return(new ClrTypeReference(
                typeof(T),
                SchemaTypeReference.InferTypeContext(typeof(T))));
 }
コード例 #2
0
        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);
        }
コード例 #3
0
        public void SchemaTypeReference_InferTypeContext_Object_From_SchemaType()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext((object)typeof(ObjectType <Foo>));

            // assert
            Assert.Equal(TypeContext.Output, context);
        }
コード例 #4
0
        public void SchemaTypeReference_InferTypeContext_Object_From_String_None()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext((object)"foo");

            // assert
            Assert.Equal(TypeContext.None, context);
        }
コード例 #5
0
        public void SchemaTypeReference_InferTypeContext_From_RuntimeType_None()
        {
            // arrange
            // act
            TypeContext context = SchemaTypeReference.InferTypeContext(typeof(Foo));

            // assert
            Assert.Equal(TypeContext.None, context);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }
コード例 #15
0
        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);
        }
コード例 #16
0
        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);
        }
コード例 #17
0
        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);
        }
コード例 #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);
        }
コード例 #19
0
        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);
        }
コード例 #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.");
        }
コード例 #21
0
        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);
        }
コード例 #22
0
        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);
        }
コード例 #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);
        }
コード例 #24
0
        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);
        }