Пример #1
0
        public async Task DisposablesWillDisposeIDisposable()
        {
            var disposed    = false;
            var disposables = new DisposablesFeature();

            var disposable = new TestDisposableClass(() =>
            {
                disposed = true;
            });

            disposables.RegisterForDispose(disposable);
            await disposables.DisposeAsync();

            Assert.True(disposed);
        }
Пример #2
0
        public async Task DisposeDisposablesWillClearRegisteredDisposables()
        {
            var disposedCount = 0;
            var disposables   = new DisposablesFeature();

            var disposable = new TestDisposableClass(() =>
            {
                disposedCount++;
            });

            disposables.RegisterForDispose(disposable);

            // call two times.
            await disposables.DisposeAsync();

            await disposables.DisposeAsync();

            Assert.Equal(1, disposedCount);
        }