public void ShouldForwardResolveToInnerContainerWhenKeyIsUsed() { object myInstance = new object(); CompositionContainer compositionContainer = new CompositionContainer(); compositionContainer.ComposeExportedValue<object>("key", myInstance); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(compositionContainer); Assert.AreSame(myInstance, containerAdapter.GetInstance(typeof(object), "key")); }
public void ShouldForwardResolveToInnerContainerWhenKeyIsUsed() { object myInstance = new object(); ContainerConfiguration config = new ContainerConfiguration(); config.WithExport<object>(myInstance, "key"); MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer(); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(); Assert.AreSame(myInstance, containerAdapter.GetInstance(typeof(object), "key")); }
public void ShouldForwardResolveAllToInnerContainer() { object objectOne = new object(); object objectTwo = new object(); CompositionContainer compositionContainer = new CompositionContainer(); compositionContainer.ComposeExportedValue<object>(objectOne); compositionContainer.ComposeExportedValue<object>(objectTwo); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(compositionContainer); IList<object> returnedList = containerAdapter.GetAllInstances(typeof(object)).ToList(); Assert.AreSame(returnedList[0], objectOne); Assert.AreSame(returnedList[1], objectTwo); }
public void ShouldThrowActivationExceptionWhenMoreThanOneInstanceAvailble() { object myInstance = new object(); object myInstance2 = new object(); CompositionContainer compositionContainer = new CompositionContainer(); compositionContainer.ComposeExportedValue<object>(myInstance); compositionContainer.ComposeExportedValue<object>(myInstance2); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(compositionContainer); try { containerAdapter.GetInstance(typeof (object)); Assert.Fail("Expected exception not thrown."); } catch(ActivationException ex) { Assert.AreEqual(typeof(InvalidOperationException), ex.InnerException.GetType()); Assert.IsTrue(ex.InnerException.Message.Contains("Sequence contains more than one element")); } }
public void ShouldThrowActivationExceptionWhenMoreThanOneInstanceAvailble() { object myInstance = new object(); object myInstance2 = new object(); ContainerConfiguration config = new ContainerConfiguration(); config.WithExport<object>(myInstance); config.WithExport<object>(myInstance2); MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer(); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(); Assert.ThrowsException<ActivationException>(() => containerAdapter.GetInstance(typeof(object)), "Sequence contains more than one element"); }