Represents a managed view model. A managed view model is watched for property changes. As soon as a change occurs in one of the managed view models, all other interested view models are notified of the changes.
Exemplo n.º 1
0
        public void AddViewModelInstance_NewInstance()
        {
            ViewModelManager.ClearAll();

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

            var viewModel = new ManagedViewModel(typeof (InterestingViewModel));
            viewModel.RemoveViewModelInstance(new InterestingViewModel());
        }
Exemplo n.º 3
0
        public void RemoveViewModelInstance_Null()
        {
            ViewModelManager.ClearAll();

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

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => viewModel.RemoveViewModelInstance(null));
        }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the managed view model for a specific view model type.
        /// </summary>
        /// <param name="viewModelType">Type of the view model.</param>
        /// <returns>The <see cref="ManagedViewModel"/> of the specified type.</returns>
        private ManagedViewModel GetManagedViewModel(Type viewModelType)
        {
            return(_managedViewModelsLock.PerformUpgradableRead(() =>
            {
                if (_managedViewModels.TryGetValue(viewModelType, out var result))
                {
                    return result;
                }

                result = new ManagedViewModel(viewModelType);

                _managedViewModelsLock.PerformWrite(() =>
                {
                    _managedViewModels.Add(viewModelType, result);
                });

                return result;
            }));
        }
Exemplo n.º 6
0
 public void Constructor()
 {
     var viewModel = new ManagedViewModel(typeof (InterestingViewModel));
     Assert.AreEqual(typeof (InterestingViewModel), viewModel.ViewModelType);
 }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }