コード例 #1
0
 public void ContainsExistingWithKey()
 {
     using (var singleton = SingletonsContainer.Get <MyDisposable>("foo"))
     {
         Assert.IsTrue(SingletonsContainer.Contains <MyDisposable>("foo"));
     }
 }
コード例 #2
0
 public void ContainsWithDifferentKey()
 {
     using (var singleton = SingletonsContainer.Get <MyDisposable>("foo"))
     {
         Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>("bar"));
     }
 }
コード例 #3
0
 public void RetrieveNonExistingSingleton()
 {
     using (var singleton = new MyDisposable())
     {
         SingletonsContainer.Add(singleton);
         Assert.IsNull(SingletonsContainer.Item("bla"));
     }
 }
コード例 #4
0
 public void RetrieveSingleton()
 {
     using (var singleton = new MyDisposable())
     {
         SingletonsContainer.Add(singleton);
         Assert.AreSame(singleton, SingletonsContainer.Item(typeof(MyDisposable).FullName));
     }
 }
コード例 #5
0
 public void AddingTwiceThrowsException()
 {
     using (var singleton = new MyDisposable())
     {
         SingletonsContainer.Add(singleton);
         Assert.Throws(typeof(ArgumentException), () => SingletonsContainer.Add(singleton));
     }
 }
コード例 #6
0
 public void RemoveNonExistingSingleton()
 {
     using (var singleton = new MyDisposable())
     {
         SingletonsContainer.Add("foo", singleton);
         Assert.IsFalse(SingletonsContainer.Remove("bar"));
         Assert.AreSame(singleton, SingletonsContainer.Item("foo"));
     }
 }
コード例 #7
0
 public void GetExistingWithKey()
 {
     using (var existingSingleton = new MyDisposable())
     {
         SingletonsContainer.Add("foo", existingSingleton);
         var singleton = SingletonsContainer.Get <MyDisposable>("foo");
         Assert.AreSame(existingSingleton, singleton);
     }
 }
コード例 #8
0
 public void GetExistingWrongKey()
 {
     using (var existingSingleton = new Control())
     {
         SingletonsContainer.Add("foo", existingSingleton);
         Assert.Throws(typeof(InvalidCastException),
                       () => SingletonsContainer.Get <MyDisposable>("foo"));
     }
 }
コード例 #9
0
 public void GetExistingWithCreateFunc()
 {
     using (var existingSingleton = new MyDisposable())
     {
         SingletonsContainer.Add("foo", existingSingleton);
         var singleton = SingletonsContainer.Get("foo", () => new MyDisposable());
         Assert.AreSame(existingSingleton, singleton);
     }
 }
コード例 #10
0
 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"));
     }
 }
コード例 #11
0
 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"));
         }
     }
 }
コード例 #12
0
        public void SingletonProperlyDisposedAutoKey()
        {
            using (var singleton = new MyDisposable())
            {
                SingletonsContainer.Add(singleton);

                Assert.IsFalse(singleton.DisposeCalled);

                // Simulate application exit
                SingletonsContainer.Release();
                Assert.IsTrue(singleton.DisposeCalled);
            }
        }
コード例 #13
0
        /// <summary>
        /// Releases the current activation context
        /// </summary>
        public static void DestroyActivationContext()
        {
#if !__MonoCS__
            SingletonsContainer.Get <ManifestHelperImpl>().DestroyContext();
#endif
        }
コード例 #14
0
 public void ContainsNonExistingWithKey()
 {
     Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>("foo"));
 }
コード例 #15
0
 public void ContainsNonExisting()
 {
     Assert.IsFalse(SingletonsContainer.Contains <MyDisposable>());
 }
コード例 #16
0
        public void GetNonExistingWithCreateFunc()
        {
            var singleton = SingletonsContainer.Get("foo", () => new MyDisposable());

            Assert.IsNotNull(singleton);
        }
コード例 #17
0
        public void GetNonExistingWithKey()
        {
            var singleton = SingletonsContainer.Get <MyDisposable>("foo");

            Assert.IsNotNull(singleton);
        }
コード例 #18
0
 public void Teardown()
 {
     SingletonsContainer.Release();
 }