コード例 #1
0
        public void It_Clears_Disposables_When_Disposed()
        {
            var viewModel = new ViewModelBase();

            viewModel.AddDisposable(new TestDisposable());
            viewModel.AddDisposable(new TestDisposable());

            viewModel.Dispose();

            viewModel.Disposables.Should().BeEmpty();
        }
コード例 #2
0
        public void It_Disposes_Disposable_When_Disposed()
        {
            var firstDisposed  = false;
            var secondDisposed = false;

            var viewModel = new ViewModelBase();

            viewModel.AddDisposable(new TestDisposable(() => firstDisposed  = true));
            viewModel.AddDisposable(new TestDisposable(() => secondDisposed = true));

            viewModel.Dispose();

            firstDisposed.Should().BeTrue();
            secondDisposed.Should().BeTrue();
        }
コード例 #3
0
        public void It_Gets_Disposable_If_Added()
        {
            var viewModel  = new ViewModelBase();
            var disposable = new TestDisposable();

            viewModel.AddDisposable(DefaultDisposableKey, disposable);

            var disposableFound = viewModel.TryGetDisposable(DefaultDisposableKey, out var storedDisposable);

            disposableFound.Should().BeTrue();
            storedDisposable.Should().NotBeNull();
        }
コード例 #4
0
        public void It_Adds_Disposable()
        {
            var viewModel  = new ViewModelBase();
            var disposable = new TestDisposable();

            viewModel.AddDisposable(DefaultDisposableKey, disposable);

            var storedDisposable = viewModel.Disposables.SingleOrDefault(s => s.Key == DefaultDisposableKey);

            storedDisposable.Key.Should().NotBeNull();
            storedDisposable.Value.Should().NotBeNull();
        }
コード例 #5
0
        public void It_Disposes_Disposable_When_Disposed_And_Exception()
        {
            var isDisposed = false;

            var viewModel = new ViewModelBase();

            viewModel.AddDisposable(new TestDisposable(() => throw new Exception()));
            viewModel.AddDisposable(new TestDisposable(() => isDisposed = true));

            viewModel.Dispose();

            isDisposed.Should().BeTrue();
        }