public void ContainsExistingWithKey() { using (var singleton = SingletonsContainer.Get <MyDisposable>("foo")) { Assert.IsTrue(SingletonsContainer.Contains <MyDisposable>("foo")); } }
public void ContainsWithDifferentKey() { using (var singleton = SingletonsContainer.Get <MyDisposable>("foo")) { Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>("bar")); } }
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 RemoveNonExistingSingleton() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add("foo", singleton); Assert.IsFalse(SingletonsContainer.Remove("bar")); Assert.AreSame(singleton, SingletonsContainer.Item("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 GetExistingWrongKey() { using (var existingSingleton = new Control()) { SingletonsContainer.Add("foo", existingSingleton); Assert.Throws(typeof(InvalidCastException), () => SingletonsContainer.Get <MyDisposable>("foo")); } }
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 SingletonProperlyDisposedAutoKey() { using (var singleton = new MyDisposable()) { SingletonsContainer.Add(singleton); Assert.IsFalse(singleton.DisposeCalled); // Simulate application exit SingletonsContainer.Release(); Assert.IsTrue(singleton.DisposeCalled); } }
/// <summary> /// Releases the current activation context /// </summary> public static void DestroyActivationContext() { #if !__MonoCS__ SingletonsContainer.Get <ManifestHelperImpl>().DestroyContext(); #endif }
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 GetNonExistingWithKey() { var singleton = SingletonsContainer.Get <MyDisposable>("foo"); Assert.IsNotNull(singleton); }
public void Teardown() { SingletonsContainer.Release(); }