Esempio n. 1
0
        public void Extensions_return_null_when_VM_is_disposed()
        {
            var vm = new MyViewModel(_serviceProvider);

            vm.Titles.Should().NotBeNull();
            vm.RefreshTitles.Should().NotBeNull();

            vm.Dispose();

            vm.Titles.Should().BeNull();
            vm.RefreshTitles.Should().BeNull();
        }
Esempio n. 2
0
        public void A_disposed_VM_returns_default_property_values()
        {
            var viewModel = new MyViewModel(_serviceProvider);

            viewModel.Counter = 1;

            viewModel.Dispose();

            viewModel.Counter.Should().Be(default(int));
            viewModel.Child.Should().Be(null);
            viewModel.IncrementCounter.Should().Be(null);
        }
Esempio n. 3
0
        public async Task It_Completes_Command_When_Disposed()
        {
            var viewModel = new MyViewModel(_serviceProvider);

            var longRunningOperation = viewModel.LongRunningOperation.Execute();

            viewModel.Dispose();

            await longRunningOperation;

            longRunningOperation.Status.Should().Be(TaskStatus.RanToCompletion);
        }
Esempio n. 4
0
        public void A_disposed_VM_cannot_be_mutated()
        {
            var viewModel = new MyViewModel(_serviceProvider);

            viewModel.Dispose();

            // Direct interface members
            Assert.Throws <ObjectDisposedException>(() => viewModel.AddDisposable(new TestDisposable()));
            Assert.Throws <ObjectDisposedException>(() => viewModel.AddDisposable("key", new TestDisposable()));
            Assert.Throws <ObjectDisposedException>(() => viewModel.RemoveDisposable(nameof(MyViewModel.Counter)));
            Assert.Throws <ObjectDisposedException>(() => viewModel.SetErrors(nameof(MyViewModel.Counter), Enumerable.Empty <object>()));
            Assert.Throws <ObjectDisposedException>(() => viewModel.SetErrors(errors: new Dictionary <string, IEnumerable <object> >()));
            Assert.Throws <ObjectDisposedException>(() => viewModel.ClearErrors(nameof(MyViewModel.Counter)));
            Assert.Throws <ObjectDisposedException>(() => viewModel.View = new TestViewModelView());
            Assert.Throws <ObjectDisposedException>(() => viewModel.RaisePropertyChanged(nameof(MyViewModel.Counter)));
        }