public void Disposed() { var container = new ComponentContainer(); container.Register <ITestComponent>().To <TestComponent>(); container.Dispose(); container.Dispose(); // Get that one extra return if you dispose twice... Assert.Throws <ObjectDisposedException>(() => container.Compose <ITestComponent>()); Assert.Throws <ObjectDisposedException>(() => container.Compose(typeof(ITestComponent))); Assert.Throws <ObjectDisposedException>(() => container.Register <ITestComponent>().To <TestComponent>()); Assert.Throws <ObjectDisposedException>(() => container.Unregister <ITestComponent>()); Assert.Throws <ObjectDisposedException>(() => container.ReplaceRegisteredComponent <ITestComponent>(null)); Assert.Throws <ObjectDisposedException>(() => container.GetRegisteredComponent <ITestComponent>()); }
/// <summary> /// When code is build in the 'debug' configuration CLR doesn't collect the object till exiting a visibility scope, /// even if it is not referenced, in contrast with 'release' configuration when object is collected as soon /// as it is not referenced by any root. /// This method is need To eliminate this difference and make the test stable by isolating variable /// 'target' visibility scope. /// </summary> private static void RunAndShutdownApplication() { // --arrange var target = new ComponentContainer(); target.CreateMainViewModel(); // --act target.Dispose(); }
public void Disposing_Of_Container_Calls_Dispose_On_Singleton_Obects() { ComponentContainer container = new ComponentContainer(); container.Bind<DisposableObject>().ToSelf().AsSingleton(); DisposableObject obj = container.Resolve<DisposableObject>(); container.Dispose(); Assert.IsTrue(obj.WasDisposed); }
public void ShutdownTest() { // --arrange var target = new ComponentContainer(); target.CreateMainViewModel(); // --act target.Dispose(); // --assert dotMemory.Check(memory => { var allMyObjects = memory .GetObjects(where => @where.Type.IsNot <ComponentContainer>()) .GetObjects(where => @where.Namespace.Like("GameOfLife.*")); Assert.That(allMyObjects.ObjectsCount, Is.EqualTo(1)); // var allowedObject = allMyObjects. }); dotMemoryApi.SaveCollectedData(); }
public void Cleanup() { ComponentContainer.Dispose(); }
public void Bind_ToStrategy_Strategy_Is_Disposed_With_Container() { var strategy = new TestBindingStrategy<Bar1>(() => new Bar1()); ComponentContainer container = new ComponentContainer(); container.Bind<IBar>().ToStrategy(strategy); container.Dispose(); Assert.IsTrue(strategy.DisposeWasCalled); }