public void ShouldThrowActivationExceptionWhenMoreThanOneInstanceAvailble() { const int SEQUENCE_MORE_THAN_ONE_ELEMENT_HRESULT = -2146233079; 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.HResult == SEQUENCE_MORE_THAN_ONE_ELEMENT_HRESULT); } }
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(); CompositionContainer compositionContainer = new CompositionContainer(); compositionContainer.ComposeExportedValue <object>("key", myInstance); IServiceLocator containerAdapter = new MefServiceLocatorAdapter(compositionContainer); Assert.AreSame(myInstance, containerAdapter.GetInstance(typeof(object), "key")); }
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(); 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() { const int SEQUENCE_MORE_THAN_ONE_ELEMENT_HRESULT = -2146233079; 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.HResult == SEQUENCE_MORE_THAN_ONE_ELEMENT_HRESULT); } }