public void AddTo()
 {
     var collection = new DisposableCollection();
     var disposable = new Component();
     disposable.AddTo(collection);
     Assert.AreEqual(1, collection.Count);
     Assert.IsTrue(collection.Contains(disposable));
 }
Example #2
0
        public void TestObjectDisposedException()
        {
            var c = new DisposableCollection();

            c.Dispose();
            c.Dispose(); // second call should have no effect

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Add(new MockDisposable()));

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Clear());

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Contains(new MockDisposable()));

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.GetEnumerator());

            Assert.ThrowsException <ObjectDisposedException>(() =>
                                                             c.Remove(new MockDisposable()));
        }
		public void Add_Contains()
		{
			var collection = new DisposableCollection();

			var disposable = new Mock<IDisposable>(MockBehavior.Strict);
			disposable.Setup(_ => _.Dispose());
			collection.Add(disposable.Object);

			var contains = collection.Contains(disposable.Object);
			Assert.IsTrue(contains);
			Assert.AreEqual(1, collection.Count);
		}