public void ContainsExistingWithKey() { using (SingletonsContainer.Get <MyDisposable>("foo")) { Assert.IsTrue(SingletonsContainer.Contains <MyDisposable>("foo")); } }
public void ContainsWithDifferentType() { using (SingletonsContainer.Get <MyDisposable>("foo")) { Assert.IsFalse(SingletonsContainer.Contains <DummyDisposable>("foo")); } }
public void RetrieveNonExistingSingleton() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton); Assert.IsNull(SingletonsContainer.Item("bla")); } }
public void RetrieveSingleton() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton); Assert.AreSame(singleton, SingletonsContainer.Item(typeof(MyDisposable).FullName)); } }
public void AddingTwiceThrowsException() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton); Assert.Throws(typeof(ArgumentException), () => SingletonsContainer.Add(singleton)); } }
public void DisposeSingletons_NullSingleton_DoesNotCrash() { SingletonsContainer.Add(typeof(MyDisposable).FullName, null); Assert.That(() => SingletonsContainer.Release(), Throws.Nothing); Assert.That(SingletonsContainer.Contains <MyDisposable>(), Is.False); }
public void RemoveNonExistingSingleton() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add("foo", singleton); Assert.IsFalse(SingletonsContainer.Remove("bar")); Assert.AreSame(singleton, SingletonsContainer.Item("foo")); } }
public void GetExistingWrongKey() { using (var existingSingleton = new DummyDisposable()) { SingletonsContainer.Add("foo", existingSingleton); Assert.Throws(typeof(InvalidCastException), () => SingletonsContainer.Get <MyDisposable>("foo")); } }
public void GetExistingWithKey() { using (var existingSingleton = new MyDisposable()) { SingletonsContainer.Add("foo", existingSingleton); var singleton = SingletonsContainer.Get <MyDisposable>("foo"); Assert.AreSame(existingSingleton, singleton); } }
public void GetExistingWithCreateFunc() { using (var existingSingleton = new MyDisposable()) { SingletonsContainer.Add("foo", existingSingleton); var singleton = SingletonsContainer.Get("foo", () => new MyDisposable()); Assert.AreSame(existingSingleton, singleton); } }
public void RemoveSingleton() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add("foo", singleton); Assert.IsTrue(SingletonsContainer.Remove("foo")); Assert.IsFalse(singleton.DisposeCalled); Assert.IsNull(SingletonsContainer.Item("foo")); } }
public void GetExistingReturnsCorrectOne() { using (var singleton1 = SingletonsContainer.Get <MyDisposable>()) { using (var singleton2 = SingletonsContainer.Get <MyDisposable>("foo")) { Assert.AreNotSame(singleton1, singleton2); Assert.AreSame(singleton1, SingletonsContainer.Get <MyDisposable>()); Assert.AreSame(singleton2, SingletonsContainer.Get <MyDisposable>("foo")); } } }
public void SingletonProperlyDisposed() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton.GetType().FullName, singleton); Assert.IsFalse(singleton.DisposeCalled); // Simulate application exit SingletonsContainer.Release(); Assert.IsTrue(singleton.DisposeCalled); } }
public void DisposeSingletons_ProperlyDisposedAutoKey() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton); Assert.IsFalse(singleton.DisposeCalled); // Simulate application exit SingletonsContainer.Release(); Assert.IsTrue(singleton.DisposeCalled); } }
public void ContainsNullSingleton() { SingletonsContainer.Add(typeof(MyDisposable).FullName, null); Assert.That(SingletonsContainer.Contains <MyDisposable>(), Is.True); }
public void ContainsNonExistingWithKey() { Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>("foo")); }
public void ContainsNonExisting() { Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>()); }
public void GetNonExistingWithCreateFunc() { var singleton = SingletonsContainer.Get("foo", () => new MyDisposable()); Assert.IsNotNull(singleton); }
public void Teardown() { SingletonsContainer.Release(); }
public void GetNonExistingWithKey() { var singleton = SingletonsContainer.Get <MyDisposable>("foo"); Assert.IsNotNull(singleton); }