AddViewModelInstance() public method

Adds a view model instance to the list of instances.
The is null. The is not of the right type.
public AddViewModelInstance ( IViewModel viewModel ) : void
viewModel IViewModel The view model instance to add.
return void
Esempio n. 1
0
        public void AddViewModelInstance_NewInstance()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));
            viewModel.AddViewModelInstance(new InterestingViewModel());
        }
Esempio n. 2
0
        public void AddViewModelInstance_Null()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => viewModel.AddViewModelInstance(null));
        }
Esempio n. 3
0
        public void AddViewModelInstance_WrongType()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            try
            {
                viewModel.AddViewModelInstance(new InterestedViewModel());

                Assert.Fail("Expected WrongViewModelTypeException");
            }
            catch (WrongViewModelTypeException ex)
            {
                Assert.AreEqual(ex.ActualType, typeof (InterestedViewModel));
                Assert.AreEqual(ex.ExpectedType, typeof (InterestingViewModel));
            }
        }
Esempio n. 4
0
        public void RemoveViewModelInstance_RegisteredViewModel()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            var interestingViewModel = new InterestingViewModel();
            viewModel.AddViewModelInstance(interestingViewModel);
            viewModel.RemoveViewModelInstance(interestingViewModel);
        }
Esempio n. 5
0
        public async Task InterestedViewModelAutomaticallyBeingRemovedWhenClosed()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            var interestingViewModel = new InterestingViewModel();
            var interestedViewModel = new InterestedViewModel();

            viewModel.AddViewModelInstance(interestingViewModel);
            viewModel.AddInterestedViewModel(interestedViewModel);

            interestingViewModel.InterestingValue = "new value";
            Assert.AreEqual("new value", interestedViewModel.InterestedValue);

            await interestedViewModel.CloseViewModel(null);

            interestingViewModel.InterestingValue = "new value which has changed";
            Assert.AreNotEqual("new value which has changed", interestedViewModel.InterestedValue);
            Assert.AreEqual("new value", interestedViewModel.InterestedValue);

            await interestingViewModel.CloseViewModel(false);
            await interestedViewModel.CloseViewModel(false);
        }
Esempio n. 6
0
        public async Task InterestingViewModelCommandExecutedWithCommandParameter()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            var interestingViewModel = new InterestingViewModel();
            var interestedViewModel = new InterestedViewModel();

            viewModel.AddViewModelInstance(interestingViewModel);
            viewModel.AddInterestedViewModel(interestedViewModel);

            interestingViewModel.TestCommand.Execute("parameter");
            Assert.AreEqual(true, interestedViewModel.CommandHasBeenExecuted);
            Assert.AreEqual(true, interestedViewModel.CommandHasBeenExecutedWithParameter);

            await interestingViewModel.CloseViewModel(false);
            await interestedViewModel.CloseViewModel(false);
        }
Esempio n. 7
0
        public async Task InterestingViewModelPropertyChanged()
        {
            ViewModelManager.ClearAll();

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));

            var interestingViewModel = new InterestingViewModel();
            var interestedViewModel = new InterestedViewModel();

            viewModel.AddViewModelInstance(interestingViewModel);
            viewModel.AddInterestedViewModel(interestedViewModel);

            interestingViewModel.InterestingValue = "new value";
            Assert.AreEqual("new value", interestedViewModel.InterestedValue);

            await interestingViewModel.CloseViewModel(false);
            await interestedViewModel.CloseViewModel(false);
        }