public void TestObjectDisposed() { ContainerManagedLifetimeManager manager = new ContainerManagedLifetimeManager(); manager.Dispose(); try { manager.AddInstance(new object()); Assert.Fail(); } catch (ObjectDisposedException) { } try { manager.GetInstance(); Assert.Fail(); } catch (ObjectDisposedException) { } try { manager.RemoveInstance(); Assert.Fail(); } catch (ObjectDisposedException) { } try { manager.Dispose(); Assert.Fail(); } catch (ObjectDisposedException) { } }
public void TestAddRetrieve() { ContainerManagedLifetimeManager manager = new ContainerManagedLifetimeManager(); object o = new object(); manager.AddInstance(o); Assert.AreEqual(o, manager.GetInstance()); }
public void TestRemoveInstance() { ContainerManagedLifetimeManager manager = new ContainerManagedLifetimeManager(); object o = new object(); manager.AddInstance(o); manager.RemoveInstance(); Assert.IsNull(manager.GetInstance()); Mock<IDisposable> disposable = new Mock<IDisposable>(); manager.AddInstance(disposable.Object); manager.RemoveInstance(); disposable.Verify(p => p.Dispose(), Times.Exactly(1)); }