Exemplo n.º 1
0
        public void RegisterInstance_Valid()
        {
            var helper   = new MefHelper();
            var instance = new TestClass1()
            {
                Name = "test"
            };

            var container = new CompositionContainer();

            Assert.IsFalse(container.GetRegistrationInfo(typeof(ITestInterface)));

            helper.RegisterInstance(container, typeof(ITestInterface), instance);
            Assert.IsTrue(container.GetRegistrationInfo(typeof(ITestInterface)));
            Assert.AreEqual(instance, container.ResolveType <ITestInterface>());
        }
Exemplo n.º 2
0
        public void RegisterInstance_InstanceNull()
        {
            var helper = new MefHelper();

            var container = new CompositionContainer();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => helper.RegisterInstance(container, typeof(ITestInterface), null));
        }
Exemplo n.º 3
0
        public void RegisterInstance_InvalidContainer()
        {
            var helper = new MefHelper();

            var container = new object();

            ExceptionTester.CallMethodAndExpectException <NotSupportedException>(() => helper.RegisterInstance(container, typeof(ITestInterface), new TestClass1()));
        }
Exemplo n.º 4
0
        public void RegisterInstance_ContainerNull()
        {
            var helper = new MefHelper();

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