Esempio n. 1
0
        public void ResolveType_Singleton()
        {
            var helper = new MefHelper();

            var container = new CompositionContainer();

            container.RegisterType <ITestInterface, TestClass1>();

            var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance1);
            Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1));

            var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance2);
            Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1));

            Assert.IsTrue(ReferenceEquals(resolvedInstance1, resolvedInstance2));
        }
Esempio n. 2
0
        public void ResolveType_Transient()
        {
            var helper = new MefHelper();

            var container = new CompositionContainer();

            container.RegisterType <ITestInterface, TestClass1>();

            var resolvedInstance1 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance1);
            Assert.IsInstanceOfType(resolvedInstance1, typeof(TestClass1));

            var resolvedInstance2 = helper.ResolveType(container, typeof(ITestInterface));

            Assert.IsNotNull(resolvedInstance2);
            Assert.IsInstanceOfType(resolvedInstance2, typeof(TestClass1));

            // Note that MEF does not support transient types
            Assert.IsTrue(ReferenceEquals(resolvedInstance1, resolvedInstance2));
        }
Esempio n. 3
0
        public void ResolveType_ContainerWithoutTypeRegistered()
        {
            var helper = new MefHelper();

            var container = new CompositionContainer();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
Esempio n. 4
0
        public void ResolveType_InvalidContainer()
        {
            var helper = new MefHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.ResolveType(container, typeof(ITestInterface)));
        }
Esempio n. 5
0
        public void ResolveType_InterfaceTypeNull()
        {
            var helper = new MefHelper();

            var container = new CompositionContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.ResolveType(container, null));
        }
Esempio n. 6
0
        public void ResolveType_ContainerNull()
        {
            var helper = new MefHelper();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.ResolveType(null, typeof(ITestInterface)));
        }