Exemplo n.º 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());
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }