Ejemplo n.º 1
0
        public void TestDisposeAll()
        {
            try
            {
                ListUtils.DisposeAll(null);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentNullException));
                Assert.AreEqual((e as ArgumentException).ParamName, "values");
            }

            try
            {
                ListUtils.DisposeAll(new List <int> {
                    1, 2, 3
                });
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(InvalidCastException));
            }

            var obj  = new DisposableObj();
            var list = new List <IDisposable> {
                obj
            };

            ListUtils.DisposeAll(list);

            Assert.IsTrue(obj.isDisposed);
            Assert.IsFalse(obj.wasDisposedMoreThanOnce);
        }
Ejemplo n.º 2
0
        public void TestEmptyAndDispose()
        {
            try
            {
                ListUtils.EmptyAndDispose(null);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ArgumentNullException));
                Assert.AreEqual((e as ArgumentException).ParamName, "values");
            }

            var intsList = new List <int> {
                1, 2, 3
            };

            ListUtils.EmptyAndDispose(intsList);
            Assert.AreEqual(intsList.Count, 0);

            var disposableObj   = new DisposableObj();
            var disposablesList = new List <IDisposable> {
                disposableObj
            };

            ListUtils.EmptyAndDispose(disposablesList);
            Assert.AreEqual(disposablesList.Count, 0);
            Assert.IsTrue(disposableObj.isDisposed);

            disposableObj = new DisposableObj();
            var mixedList = new ArrayList {
                1, disposableObj, 3
            };

            ListUtils.EmptyAndDispose(mixedList);
            Assert.AreEqual(disposablesList.Count, 0);
            Assert.IsTrue(disposableObj.isDisposed);
        }