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();
        }
        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();
        }
        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();
        }
        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();
        }
        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();
        }