public void SingletonComponentRegisteredWithFactoryMethod_IsDisposed() { var disposed = false; var cat = new ComponentCatalog(); cat.RegisterComponent <ISampleComponent>(() => new DisposableComponent { Handler = () => disposed = true }, ActivationType.Singleton); Assert.IsFalse(disposed); var instance = cat.GetComponent <ISampleComponent>(); AssertEx.IsInstanceOf <DisposableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }
public void SingletonComponentRegisteredWithComponentType_IsCleanedUp() { var disposed = false; var cat = new ComponentCatalog(); cat.RegisterComponent <ISampleComponent, ReleasableComponent>( ActivationType.Singleton, v => ((ReleasableComponent)v).Release()); Assert.IsFalse(disposed); var instance = cat.GetComponent <ISampleComponent>(); AssertEx.IsInstanceOf <ReleasableComponent>(instance); instance.Handler = () => disposed = true; var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }
public void IObjectSourceFromMefContainer_IsRegisteredAsIs() { using (var cat = new ComponentCatalog()) { cat.RegisterComponents(MefContainer); // get component registration var reg = cat.GetRegistration("UniqueName_MefSample11"); Assert.IsNotNull(reg); // get component instance var obj = cat.GetComponent("UniqueName_MefSample11") as IObjectSource; Assert.IsNotNull(obj); AssertEx.IsInstanceOf <MefSample11>(obj); Assert.AreEqual(1, MefSample11.InstanceCount); // clean up component instance cat.CleanUpComponentInstance(reg, obj); Assert.AreEqual(0, MefSample11.InstanceCount); } }
public void NamedZyanInterfaceFromMefCatalog_IsRegistered() { using (var cat = new ComponentCatalog()) { cat.RegisterComponents(MefCatalog); // get component registration var reg = cat.GetRegistration("UniqueName_MefSample8"); Assert.IsNotNull(reg); // get component instance var obj = cat.GetComponent("UniqueName_MefSample8") as IMefSample8; Assert.IsNotNull(obj); AssertEx.IsInstanceOf <MefSample8>(obj); Assert.AreEqual(1, MefSample8.InstanceCount); // clean up component instance cat.CleanUpComponentInstance(reg, obj); Assert.AreEqual(0, MefSample8.InstanceCount); } }
public void ZyanInterfaceFromFromMefContainer_IsRegistered() { using (var cat = new ComponentCatalog()) { cat.RegisterComponents(MefContainer); // get component registration var reg = cat.GetRegistration(typeof(IMefSample7)); Assert.IsNotNull(reg); // get component instance var obj = cat.GetComponent <IMefSample7>(); Assert.IsNotNull(obj); AssertEx.IsInstanceOf <MefSample7>(obj); Assert.AreEqual(1, MefSample7.InstanceCount); // clean up component instance cat.CleanUpComponentInstance(reg, obj); Assert.AreEqual(0, MefSample7.InstanceCount); } }
public void ZyanComponentFromMefContainer_IsRegisteredAsSingleCall() { using (var cat = new ComponentCatalog()) { cat.RegisterComponents(MefContainer); // get component registration var reg = cat.GetRegistration(typeof(IMefSample)); Assert.IsNotNull(reg); Assert.AreEqual(ActivationType.SingleCall, reg.ActivationType); // get component instance var obj = cat.GetComponent <IMefSample>(); Assert.IsNotNull(obj); AssertEx.IsInstanceOf <MefSample1>(obj); Assert.AreEqual(1, MefSample1.InstanceCount); // clean up component instance cat.CleanUpComponentInstance(reg, obj); Assert.AreEqual(0, MefSample1.InstanceCount); } }
public void InheritedExportFromFromMefContainer_IsRegistered() { var cat = new ComponentCatalog(); cat.RegisterComponents(MefContainer); // get component registration var reg = cat.GetRegistration("UniqueName_MefSample5"); Assert.IsNotNull(reg); // get component instance var obj = cat.GetComponent("UniqueName_MefSample5") as IMefSample5; Assert.IsNotNull(obj); AssertEx.IsInstanceOf <MefSample5>(obj); Assert.AreEqual(1, MefSample5.InstanceCount); // clean up component instance cat.CleanUpComponentInstance(reg, obj); Assert.AreEqual(0, MefSample5.InstanceCount); }
public void SingletonComponentRegisteredWithComponentInstance_IsCleanedUp() { // this component instance is created outside, but the ownership // is transferred to the ComponentCatalog via cleanup delegate var disposed = false; var mortalServer = new ReleasableComponent { Handler = () => disposed = true }; var cat = new ComponentCatalog(); cat.RegisterComponent <ISampleComponent, ReleasableComponent>(mortalServer, v => ((ReleasableComponent)v).Release()); Assert.IsFalse(disposed); var instance = cat.GetComponent <ISampleComponent>(); AssertEx.IsInstanceOf <ReleasableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }
public void SingletonComponentRegisteredWithComponentInstance_IsNotDisposed() { // this component instance is externally-owned var disposed = false; using (var immortalServer = new DisposableComponent { Handler = () => disposed = true }) using (var cat = new ComponentCatalog()) { cat.RegisterComponent <ISampleComponent, DisposableComponent>(immortalServer); Assert.IsFalse(disposed); var instance = cat.GetComponent <ISampleComponent>(); AssertEx.IsInstanceOf <DisposableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsFalse(disposed); immortalServer.Dispose(); Assert.IsTrue(disposed); } }
public void SingletonComponentRegisteredWithFactoryMethod_IsDisposed() { var disposed = false; var cat = new ComponentCatalog(); cat.RegisterComponent<ISampleComponent>(() => new DisposableComponent { Handler = () => disposed = true }, ActivationType.Singleton); Assert.IsFalse(disposed); var instance = cat.GetComponent<ISampleComponent>(); AssertEx.IsInstanceOf<DisposableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }
public void SingletonComponentRegisteredWithComponentType_IsCleanedUp() { var disposed = false; var cat = new ComponentCatalog(); cat.RegisterComponent<ISampleComponent, ReleasableComponent>( ActivationType.Singleton, v => ((ReleasableComponent)v).Release()); Assert.IsFalse(disposed); var instance = cat.GetComponent<ISampleComponent>(); AssertEx.IsInstanceOf<ReleasableComponent>(instance); instance.Handler = () => disposed = true; var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }
public void SingletonComponentRegisteredWithComponentInstance_IsNotDisposed() { // this component instance is externally-owned var disposed = false; using (var immortalServer = new DisposableComponent { Handler = () => disposed = true }) using (var cat = new ComponentCatalog()) { cat.RegisterComponent<ISampleComponent, DisposableComponent>(immortalServer); Assert.IsFalse(disposed); var instance = cat.GetComponent<ISampleComponent>(); AssertEx.IsInstanceOf<DisposableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsFalse(disposed); immortalServer.Dispose(); Assert.IsTrue(disposed); } }
public void SingletonComponentRegisteredWithComponentInstance_IsCleanedUp() { // this component instance is created outside, but the ownership // is transferred to the ComponentCatalog via cleanup delegate var disposed = false; var mortalServer = new ReleasableComponent { Handler = () => disposed = true }; var cat = new ComponentCatalog(); cat.RegisterComponent<ISampleComponent, ReleasableComponent>(mortalServer, v => ((ReleasableComponent)v).Release()); Assert.IsFalse(disposed); var instance = cat.GetComponent<ISampleComponent>(); AssertEx.IsInstanceOf<ReleasableComponent>(instance); var reg = cat.GetRegistration(typeof(ISampleComponent)); cat.CleanUpComponentInstance(reg, instance); Assert.IsTrue(disposed); }