示例#1
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)));
        }