コード例 #1
0
        public void TypeSlimToTypeConverter_Resolve_ThrowsInvalidOperation()
        {
            var visitor     = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);
            var intTypeSlim = typeof(int).ToTypeSlim();

            visitor.MapType(intTypeSlim, typeof(string));
            Assert.ThrowsException <InvalidOperationException>(() => visitor.MapType(intTypeSlim, typeof(long)));
        }
コード例 #2
0
        public void TypeSlimToTypeConverter_ArgumentChecks()
        {
            var converter = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);

            AssertEx.ThrowsException <ArgumentNullException>(() => converter.Visit(type: null), ex => Assert.AreEqual(ex.ParamName, "type"));
            AssertEx.ThrowsException <ArgumentNullException>(() => converter.MapType(typeSlim: null, type: null), ex => Assert.AreEqual(ex.ParamName, "typeSlim"));
            AssertEx.ThrowsException <ArgumentNullException>(() => converter.MapType(SlimType, type: null), ex => Assert.AreEqual(ex.ParamName, "type"));
        }
コード例 #3
0
        public void TypeSlimToTypeConverter_VisitGenericParameter_ThrowsInvalidOperation()
        {
            var visitor = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);

            visitor.Push(new Dictionary <TypeSlim, Type>());
            var param = TypeSlim.GenericParameter("T");

            Assert.ThrowsException <InvalidOperationException>(() => visitor.Visit(param));
        }
コード例 #4
0
        public void TypeToTypeSlimConverter_System()
        {
            var ttsc = new TypeToTypeSlimConverter();
            var tstc = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);

            foreach (var t in typeof(Uri).Assembly.GetTypes().Where(t => t.Namespace == "System"))
            {
                Roundtrip(ttsc, tstc, t);
            }
        }
コード例 #5
0
        public void TypeSlimToTypeConverter_Resolve_Success()
        {
            var typeToSlim   = new TypeToTypeSlimConverter();
            var visitor      = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);
            var longTypeSlim = typeToSlim.Visit(typeof(long));

            visitor.MapType(longTypeSlim, typeof(int));
            var longType = visitor.Visit(longTypeSlim);

            Assert.AreEqual(typeof(int), longType);
            visitor.MapType(longTypeSlim, typeof(int));
        }
コード例 #6
0
        public void TypeSlimToTypeConverter_VisitSimpleFake_ThrowsException()
        {
            var visitor = new TypeSlimToTypeConverter(DefaultReflectionProvider.Instance);
            var simple  = TypeSlim.Simple(new AssemblySlim("MyFakeAssembly"), "MyFakeType");

            if (Type.GetType("Mono.Runtime") == null)
            {
                Assert.ThrowsException <FileNotFoundException>(() => visitor.Visit(simple));
            }
            else
            {
                Assert.ThrowsException <TypeLoadException>(() => visitor.Visit(simple));
            }
        }
コード例 #7
0
        private static void Roundtrip(TypeToTypeSlimConverter ttsc, TypeSlimToTypeConverter tstc, global::System.Type t)
        {
            var slim = ttsc.Visit(t);

            var exp = t.IsGenericTypeDefinition ? TypeSlimKind.GenericDefinition : TypeSlimKind.Simple;

            Assert.AreEqual(exp, slim.Kind);

            var simple = slim as SimpleTypeSlimBase;

            Assert.IsNotNull(simple, t.Name);

            Assert.AreEqual(t.FullName, simple.Name);

            var asm = simple.Assembly;

            Assert.IsNotNull(asm, t.Name);

            Assert.AreEqual(t.Assembly.FullName, asm.Name);

            var res = tstc.Visit(slim);

            Assert.AreSame(t, res);
        }