Пример #1
0
        public void DisposalScope_ThrowExceptionDuringCleanUp()
        {
            var disposalScope     = new DisposalScope();
            var disposableService = new DisposableService();
            var eventFired        = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService, disposed => { throw new Exception(); });

            Assert.ThrowsAny <AggregateException>(() => disposalScope.Dispose());
        }
Пример #2
0
        public void BasicDisposalTest()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService);

            disposalScope.Dispose();

            Assert.True(eventFired);
        }
Пример #3
0
        public void DisposalScope_DisposeCalledTest()
        {
            var disposalScope     = new DisposalScope();
            var disposableService = new DisposableService();
            var eventFired        = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService);

            disposalScope.Dispose();

            Assert.True(eventFired);
        }
Пример #4
0
        public void CleanUpDelegateTest()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;
            bool cleanUpCalled = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService,
                disposed =>
                {
                    Assert.True(ReferenceEquals(disposableService, disposed));

                    cleanUpCalled = true;
                });

            disposalScope.Dispose();

            Assert.True(eventFired);
            Assert.True(cleanUpCalled);
        }
Пример #5
0
        public void CleanUpDelegateTest()
        {
            var disposalScope     = new DisposalScope();
            var disposableService = new DisposableService();
            var eventFired        = false;
            var cleanUpCalled     = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService,
                                        disposed =>
            {
                Assert.True(ReferenceEquals(disposableService, disposed));

                cleanUpCalled = true;
            });

            disposalScope.Dispose();

            Assert.True(eventFired);
            Assert.True(cleanUpCalled);
        }
Пример #6
0
        public void ThrowExceptionDuringCleanUp()
        {
            DisposalScope disposalScope = new DisposalScope();
            DisposableService disposableService = new DisposableService();
            bool eventFired = false;

            disposableService.Disposing += (sender, args) => eventFired = true;

            disposalScope.AddDisposable(disposableService, disposed => { throw new Exception(); });

            disposalScope.Dispose();

            Assert.True(eventFired);
        }