コード例 #1
0
        public void SyntaxTypeReference_GetHashCode_NotEquals(
            string typeName,
            TypeContext context,
            bool?isTypeNullable,
            bool?isElementTypeNullable)
        {
            // arrange
            var x = new SyntaxTypeReference(
                new NamedTypeNode("abc"),
                TypeContext.Input,
                true,
                false);

            var y = new SyntaxTypeReference(
                new NamedTypeNode(typeName),
                context,
                isTypeNullable,
                isElementTypeNullable);

            // act
            int xhash = x.GetHashCode();
            int yhash = y.GetHashCode();

            // assert
            Assert.NotEqual(xhash, yhash);
        }
コード例 #2
0
        public void Object_Equals_Scope_Different()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None,
                scope: "a");

            SyntaxTypeReference y = TypeReference.Create(
                "Foo",
                TypeContext.Output,
                scope: "a");

            SyntaxTypeReference z = TypeReference.Create(
                "Foo",
                TypeContext.Input);

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

            // assert
            Assert.True(xy);
            Assert.False(xz);
            Assert.False(yz);
        }
コード例 #3
0
        public void SyntaxTypeReference_GetHashCode()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None,
                scope: "foo");

            SyntaxTypeReference y = TypeReference.Create(
                "Foo",
                TypeContext.None,
                scope: "foo");

            SyntaxTypeReference z = TypeReference.Create(
                "Foo",
                TypeContext.Input);

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

            // assert
            Assert.Equal(xh, yh);
            Assert.NotEqual(xh, zh);
        }
コード例 #4
0
        public void Object_Equals_Nullability()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None,
                nullable: new bool[] { true, false });

            SyntaxTypeReference y = TypeReference.Create(
                "Foo",
                TypeContext.Output,
                nullable: new bool[] { false, false });

            SyntaxTypeReference z = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                nullable: new bool[] { 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);
        }
コード例 #5
0
        public void ISyntaxTypeReference_Equals_True(
            string typeName,
            TypeContext context,
            bool?isTypeNullable,
            bool?isElementTypeNullable)
        {
            // arrange
            var x = new SyntaxTypeReference(
                new NamedTypeNode(typeName),
                context,
                isTypeNullable,
                isElementTypeNullable);

            ISyntaxTypeReference y = new SyntaxTypeReference(
                new NamedTypeNode(typeName),
                context,
                isTypeNullable,
                isElementTypeNullable);

            // act
            bool result = x.Equals(y);

            // assert
            Assert.True(result);
        }
コード例 #6
0
        public void SyntaxTypeReference_Equals_Context_None_Does_Not_Matter()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None);

            SyntaxTypeReference y = TypeReference.Create(
                "Foo",
                TypeContext.Output);

            SyntaxTypeReference z = TypeReference.Create(
                "Foo",
                TypeContext.Input);

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

            // assert
            Assert.True(xy);
            Assert.True(xz);
            Assert.False(yz);
        }
コード例 #7
0
        public void SyntaxTypeReference_RewriteType_Type_Is_The_Same()
        {
            // arrange
            SyntaxTypeReference typeReference = TypeReference.Create("Foo");

            // act
            SyntaxTypeReference rewritten = typeReference.Rewrite();

            // assert
            Assert.Equal(typeReference, rewritten);
        }
コード例 #8
0
        public void ITypeReference_Equals_To_SyntaxTypeRef()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None);

            // act
            var xx = x.Equals(TypeReference.Create(_typeInspector.GetType(typeof(int))));

            // assert
            Assert.False(xx);
        }
コード例 #9
0
        public void SyntaxTypeReference_ToString()
        {
            // arrange
            SyntaxTypeReference typeReference = TypeReference.Create(
                "Foo",
                TypeContext.Input);

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

            // assert
            Assert.Equal("Input: Foo", result);
        }
コード例 #10
0
        public void SyntaxTypeReference_Equals_To_Null()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None);

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

            // assert
            Assert.False(result);
        }
コード例 #11
0
        public void Object_Equals_To_Object()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None);

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

            // assert
            Assert.False(xx);
        }
コード例 #12
0
        public void SyntaxTypeReference_Equals_To_Same()
        {
            // arrange
            SyntaxTypeReference x = TypeReference.Create(
                "Foo",
                TypeContext.None);

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

            // assert
            Assert.True(xx);
        }
コード例 #13
0
        public void SyntaxTypeReference_With_Type_Null()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo");

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

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
コード例 #14
0
        public void TypeReference_Create_With_Name()
        {
            // arrange
            // act
            SyntaxTypeReference typeReference = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo");

            // assert
            Assert.Equal("Foo", typeReference.Type.NamedType().Name.Value);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("foo", typeReference.Scope);
        }
コード例 #15
0
        public void ISyntaxTypeReference_RefEquals_True()
        {
            // arrange
            var x = new SyntaxTypeReference(
                new NamedTypeNode("abc"),
                TypeContext.Input,
                true,
                false);

            // act
            bool result = x.Equals((ISyntaxTypeReference)x);

            // assert
            Assert.True(result);
        }
コード例 #16
0
        public void SyntaxTypeReference_RewriteType_NonNullToNullable()
        {
            // arrange
            SyntaxTypeReference typeReference = TypeReference.Create(
                new NonNullTypeNode(new NamedTypeNode("Foo")),
                nullable: new bool[] { true });

            // act
            SyntaxTypeReference rewritten = typeReference.Rewrite();

            // assert
            Assert.Equal("Foo",
                         Assert.IsType <NamedTypeNode>(
                             rewritten.Type).Name.Value);
        }
コード例 #17
0
        public void Object_NullEquals_False()
        {
            // arrange
            var x = new SyntaxTypeReference(
                new NamedTypeNode("abc"),
                TypeContext.Input,
                true,
                false);

            // act
            bool result = x.Equals((object)null);

            // assert
            Assert.False(result);
        }
コード例 #18
0
        public void ClrTypeReference_ToString()
        {
            // arrange
            var typeReference = new SyntaxTypeReference(
                new NonNullTypeNode(new NamedTypeNode("abc")),
                TypeContext.Input,
                true,
                false);

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

            // assert
            Assert.Equal("Input: abc!", result);
        }
コード例 #19
0
        public void TypeReference_Create()
        {
            // arrange
            var namedType = new NamedTypeNode("Foo");

            // act
            SyntaxTypeReference typeReference = TypeReference.Create(
                namedType,
                TypeContext.Input,
                scope: "foo");

            // assert
            Assert.Equal(namedType, typeReference.Type);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("foo", typeReference.Scope);
        }
コード例 #20
0
        public void TypeReference_Create_With_Name()
        {
            // arrange
            // act
            SyntaxTypeReference typeReference = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo",
                nullable: new bool[] { false });

            // assert
            Assert.Equal("Foo", typeReference.Type.NamedType().Name.Value);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("foo", typeReference.Scope);
            Assert.Collection(typeReference.Nullable, Assert.False);
        }
コード例 #21
0
        public void SyntaxTypeReference_With_Scope()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo");

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

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(typeReference1.Context, typeReference2.Context);
            Assert.Equal("bar", typeReference2.Scope);
        }
コード例 #22
0
        public void SyntaxTypeReference_With_Context()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo");

            // act
            SyntaxTypeReference typeReference2 = typeReference1.With(context: TypeContext.None);

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(TypeContext.None, typeReference2.Context);
            Assert.Equal(typeReference1.Scope, typeReference2.Scope);
        }
コード例 #23
0
        public void SyntaxTypeReference_With_Type()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo");

            // act
            SyntaxTypeReference typeReference2 = typeReference1.With(new NamedTypeNode("Bar"));

            // assert
            Assert.Equal("Bar", Assert.IsType <NamedTypeNode>(typeReference2.Type).Name.Value);
            Assert.Equal(typeReference1.Context, typeReference2.Context);
            Assert.Equal(typeReference1.Scope, typeReference2.Scope);
        }
コード例 #24
0
        public void GetMemberType_With_SyntaxTypeRef()
        {
            // arrange
            PropertyInfo property =
                typeof(ObjectPropWithSyntaxType)
                .GetProperty(nameof(ObjectPropWithSyntaxType.ShouldBeFound)) !;
            var typeInspector = new DefaultTypeInspector();

            // act
            ITypeReference typeReference = typeInspector.GetReturnTypeRef(property !);

            // assert
            SyntaxTypeReference extTypeRef = Assert.IsType <SyntaxTypeReference>(typeReference);

            Assert.Equal("[String]", extTypeRef.Type.ToString());
            Assert.Equal(TypeContext.None, typeReference.Context);
            Assert.Null(typeReference.Scope);
        }
コード例 #25
0
        public void SyntaxTypeReference_With_Nullable()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo",
                nullable: new[] { true });

            // act
            SyntaxTypeReference 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);
        }
コード例 #26
0
        public void TypeReference_Create()
        {
            // arrange
            var namedType = new NamedTypeNode("Foo");

            // act
            SyntaxTypeReference typeReference = TypeReference.Create(
                namedType,
                TypeContext.Input,
                scope: "foo",
                nullable: new bool[] { false });

            // assert
            Assert.Equal(namedType, typeReference.Type);
            Assert.Equal(TypeContext.Input, typeReference.Context);
            Assert.Equal("foo", typeReference.Scope);
            Assert.Collection(typeReference.Nullable, Assert.False);
        }
コード例 #27
0
        public void SyntaxTypeReference_CreateInstance(
            string typeName,
            TypeContext context,
            bool?isTypeNullable,
            bool?isElementTypeNullable)
        {
            // arrange
            // act
            var typeReference = new SyntaxTypeReference(
                new NamedTypeNode(typeName),
                context,
                isTypeNullable,
                isElementTypeNullable);

            // assert
            Assert.Equal(typeName, typeReference.Type.ToString());
            Assert.Equal(context, typeReference.Context);
            Assert.Equal(isTypeNullable, typeReference.IsTypeNullable);
            Assert.Equal(isElementTypeNullable,
                         typeReference.IsElementTypeNullable);
        }
コード例 #28
0
        public void ISyntaxTypeReference_Equals_False()
        {
            // arrange
            var x = new SyntaxTypeReference(
                new NamedTypeNode("abc"),
                TypeContext.Input,
                true,
                false);

            ISyntaxTypeReference y = new SyntaxTypeReference(
                new NamedTypeNode("cde"),
                TypeContext.Input,
                true,
                false);

            // act
            bool result = x.Equals(y);

            // assert
            Assert.False(result);
        }
コード例 #29
0
        public void SyntaxTypeReference_With()
        {
            // arrange
            SyntaxTypeReference typeReference1 = TypeReference.Create(
                "Foo",
                TypeContext.Input,
                scope: "foo",
                nullable: new[] { true });

            // act
            SyntaxTypeReference typeReference2 = typeReference1.With(
                new NamedTypeNode("Bar"),
                TypeContext.Output,
                scope: "bar",
                nullable: new[] { false });

            // assert
            Assert.Equal("Bar", Assert.IsType <NamedTypeNode>(typeReference2.Type).Name.Value);
            Assert.Equal(TypeContext.Output, typeReference2.Context);
            Assert.Equal("bar", typeReference2.Scope);
            Assert.Collection(typeReference2.Nullable !, Assert.False);
        }