Example #1
0
        public void GetTypeRef()
        {
            // arrange
            Type type          = typeof(Foo);
            var  typeInspector = new DefaultTypeInspector();

            // act
            ExtendedTypeReference typeReference =
                typeInspector.GetTypeRef(type !, TypeContext.Output);

            // assert
            Assert.Equal("Foo", typeReference.Type.ToString());
            Assert.Equal(TypeContext.Output, typeReference.Context);
            Assert.Null(typeReference.Scope);
        }
Example #2
0
        public void GetReturnTypeRef_FromMethod()
        {
            // arrange
            MethodInfo method        = typeof(Foo).GetMethod(nameof(Foo.Bar));
            var        typeInspector = new DefaultTypeInspector();

            // act
            ExtendedTypeReference typeReference =
                typeInspector.GetReturnTypeRef(method !, TypeContext.Output);

            // assert
            Assert.Equal("List<String!>!", typeReference.Type.ToString());
            Assert.Equal(TypeContext.Output, typeReference.Context);
            Assert.Null(typeReference.Scope);
        }
        public void ClrTypeReference_With_Scope()
        {
            // arrange
            ExtendedTypeReference typeReference1 = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                TypeContext.Input,
                scope: "foo");

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

            // assert
            Assert.Equal(typeReference1.Type, typeReference2.Type);
            Assert.Equal(typeReference1.Context, typeReference2.Context);
            Assert.Equal("bar", typeReference2.Scope);
        }
        public void GetArgumentTypeRef_With_Scope()
        {
            // arrange
            ParameterInfo parameter     = typeof(Foo).GetMethod(nameof(Foo.Baz)) !.GetParameters()[0];
            var           typeInspector = new DefaultTypeInspector();

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

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

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

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

            Assert.Equal("List<String!>!", extTypeRef.Type.ToString());
            Assert.Equal(TypeContext.Output, typeReference.Context);
            Assert.Equal("abc", typeReference.Scope);
        }
        public void TypeReference_Create(
            Type clrType,
            TypeContext context,
            string scope)
        {
            // arrange
            // act
            ExtendedTypeReference typeReference = TypeReference.Create(
                _typeInspector.GetType(clrType),
                context,
                scope: scope);

            // assert
            Assert.Equal(clrType, typeReference.Type.Source);
            Assert.Equal(context, typeReference.Context);
            Assert.Equal(scope, typeReference.Scope);
        }
        public void ClrTypeReference_Equals_Context_None_Does_Not_Matter()
        {
            // arrange
            ExtendedTypeReference x = TypeReference.Create(
                _typeInspector.GetType(typeof(string)));

            ExtendedTypeReference y = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                TypeContext.Output);

            ExtendedTypeReference z = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                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);
        }
        public void ClrTypeReference_GetHashCode_Context_HasNoEffect()
        {
            // arrange
            ExtendedTypeReference x = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                TypeContext.None);

            ExtendedTypeReference y = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                TypeContext.Output);

            ExtendedTypeReference z = TypeReference.Create(
                _typeInspector.GetType(typeof(string)),
                TypeContext.Input);

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

            // assert
            Assert.Equal(xh, yh);
            Assert.Equal(xh, zh);
        }