Exemple #1
0
        public void DisposeCollectionWorks()
        {
            var a    = 0;
            var b    = 0;
            var ad   = DisposableEx.AlwaysAction(() => a++);
            var bd   = DisposableEx.AlwaysAction(() => b++);
            var arr  = new[] { ad, bd };
            var list = new List <IDisposable> {
                ad
            };

            list.AddAction(() => b++);
            DisposableEx.Dispose(arr);
            Assert.Equal(2, arr.Length);
            Assert.Equal(1, a);
            Assert.Equal(1, b);
            DisposableEx.Dispose((IEnumerable <IDisposable>)list);
            Assert.Equal(2, list.Count);
            Assert.Equal(2, a);
            Assert.Equal(2, b);
            DisposableEx.Dispose(list);
            Assert.Equal(0, list.Count);
            Assert.Equal(3, a);
            Assert.Equal(2, b);
        }
Exemple #2
0
        public void AlwaysActionWorks()
        {
            var         a = 1;
            IDisposable disposable;

            using (disposable = DisposableEx.AlwaysAction(() => a = 3))
            {
                a = 2;
            }
            Assert.Equal(3, a);
            a = 5;
            disposable.Dispose();
            Assert.Equal(3, a);
        }