Ejemplo n.º 1
0
            public void MustExistsForRegisteredViewModels()
            {
                var firstvm   = new TestViewModel();
                var secondvm  = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(firstvm);
                vmManager.RegisterViewModelInstance(secondvm);

                var vmList = vmManager.ActiveViewModels.ToList();

                Assert.IsTrue(vmList.Any(vm => TagHelper.AreTagsEqual(vm.UniqueIdentifier, firstvm.UniqueIdentifier)));
                Assert.IsTrue(vmList.Any(vm => TagHelper.AreTagsEqual(vm.UniqueIdentifier, secondvm.UniqueIdentifier)));
            }
Ejemplo n.º 2
0
            public void ReturnsViewModelForMultiRegisteredViewModel()
            {
                var firstvm = new TestViewModel()
                {
                    FirstName = "Rajiv", LastName = "Mounguengue"
                };
                var secondvm  = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(firstvm);
                vmManager.RegisterViewModelInstance(secondvm);
                var foundvm = vmManager.GetFirstOrDefaultInstance <TestViewModel>();

                Assert.AreEqual(firstvm, foundvm);
            }
Ejemplo n.º 3
0
            public void ReturnsChildViewModelsUsingParentInstance()
            {
                var parentViewModel  = new TestViewModel() as IRelationalViewModel;
                var childViewModel   = new TestViewModel() as IRelationalViewModel;
                var viewModelManager = new ViewModelManager();

                parentViewModel.RegisterChildViewModel(childViewModel as IViewModel);
                childViewModel.SetParentViewModel(parentViewModel as IViewModel);

                viewModelManager.RegisterViewModelInstance(parentViewModel as IViewModel);
                viewModelManager.RegisterViewModelInstance(childViewModel as IViewModel);

                var foundViewModels = viewModelManager.GetChildViewModels(parentViewModel as IViewModel);

                Assert.IsNotNull(foundViewModels);
                Assert.IsTrue(foundViewModels.Contains(childViewModel));
            }
Ejemplo n.º 4
0
        public void UnregisterViewModelInstance_ExistingViewModel()
        {
            var manager   = new ViewModelManager();
            var viewModel = new InterestingViewModel();

            manager.RegisterViewModelInstance(viewModel);
            manager.UnregisterViewModelInstance(viewModel);
        }
Ejemplo n.º 5
0
            public void ReturnsViewModelForRegisteredViewModel()
            {
                var vm        = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                var foundvm = vmManager.GetViewModel(vm.UniqueIdentifier);

                Assert.AreEqual(vm, foundvm);
            }
Ejemplo n.º 6
0
            public void ReturnsViewModelForRegisteredViewModel()
            {
                var vm        = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                var foundvm = vmManager.GetFirstOrDefaultInstance <TestViewModel>();

                Assert.AreEqual(vm, foundvm);
            }
Ejemplo n.º 7
0
        public void AddInterestedViewModelInstance_ViewModelForExistingInterestedInViewModel()
        {
            var manager = new ViewModelManager();

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

            manager.RegisterViewModelInstance(interestingViewModel);
            manager.AddInterestedViewModelInstance(typeof(InterestingViewModel), interestedViewModel);
        }
Ejemplo n.º 8
0
            public void RegistersModelForViewModel()
            {
                var model     = new Person();
                var vm        = new TestViewModel(model);
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                vmManager.RegisterModel(vm, model);

                var foundVm = vmManager.GetViewModelsOfModel(model).First();

                Assert.AreEqual(vm, foundVm);
            }
Ejemplo n.º 9
0
            public void RegistersModelForViewModel()
            {
                var model = new Person();
                var vm = new TestViewModel(model);
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                vmManager.RegisterModel(vm, model);

                var foundVm = vmManager.GetViewModelsOfModel(model).First();

                Assert.AreEqual(vm, foundVm);
            }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (CatelEnvironment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ViewModelManager.RegisterViewModelInstance(this);
        }
Ejemplo n.º 11
0
            public void UnregistersAllModelForViewModel()
            {
                var model     = new Person();
                var vm        = new TestViewModel(model);
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                vmManager.RegisterModel(vm, model);

                var foundVm = vmManager.GetViewModelsOfModel(model).First();

                Assert.AreEqual(vm, foundVm);

                vmManager.UnregisterAllModels(vm);

                foundVm = vmManager.GetViewModelsOfModel(model).FirstOrDefault();

                Assert.IsNull(foundVm);
            }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes the view model.
        /// </summary>
        protected ViewModelBase()
        {
            if (Catel.Environment.IsInDesignMode)
            {
                return;
            }

            UniqueIdentifier          = UniqueIdentifierHelper.GetUniqueIdentifier(GetType());
            ViewModelConstructionTime = DateTime.Now;

            AuditingHelper.RegisterViewModel(this);

            _viewModelCommandManager = ViewModelCommandManager.Create(this);
            _viewModelCommandManager.AddHandler((viewModel, propertyName, command, commandParameter) =>
                                                _catelCommandExecuted.SafeInvoke(this, new CommandExecutedEventArgs((ICatelCommand)command, commandParameter, propertyName)));

            ServiceLocator     = IoCConfiguration.DefaultServiceLocator;
            DependencyResolver = ServiceLocator.ResolveType <IDependencyResolver>();
            RegisterViewModelServices(ServiceLocator);

            ViewModelManager.RegisterViewModelInstance(this);
        }
Ejemplo n.º 13
0
            public void ReturnsViewModelForRegisteredViewModel()
            {
                var vm = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                var foundvm = vmManager.GetViewModel(vm.UniqueIdentifier);

                Assert.AreEqual(vm, foundvm);
            }
Ejemplo n.º 14
0
            public void ReturnsViewModelForRegisteredViewModel()
            {
                var vm = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                var foundvm = vmManager.GetFirstOrDefaultInstance<TestViewModel>();

                Assert.AreEqual(vm, foundvm);
            }
Ejemplo n.º 15
0
            public void ReturnsChildViewModelsUsingParentInstance()
            {
                var parentViewModel = new TestViewModel() as IRelationalViewModel;
                var childViewModel = new TestViewModel() as IRelationalViewModel;
                var viewModelManager = new ViewModelManager();

                parentViewModel.RegisterChildViewModel(childViewModel as IViewModel);
                childViewModel.SetParentViewModel(parentViewModel as IViewModel);

                viewModelManager.RegisterViewModelInstance(parentViewModel as IViewModel);
                viewModelManager.RegisterViewModelInstance(childViewModel as IViewModel);

                var foundViewModels = viewModelManager.GetChildViewModels(parentViewModel as IViewModel);

                Assert.IsNotNull(foundViewModels);
                Assert.IsTrue(foundViewModels.Contains(childViewModel));
            }
Ejemplo n.º 16
0
        public void RegisterViewModelInstance_Null()
        {
            var manager = new ViewModelManager();

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => manager.RegisterViewModelInstance(null));
        }
Ejemplo n.º 17
0
        public void RegisterViewModelInstance_ViewModel()
        {
            var manager = new ViewModelManager();

            manager.RegisterViewModelInstance(new InterestingViewModel());
        }
Ejemplo n.º 18
0
            public void MustExistsForRegisteredViewModels()
            {
                var firstvm = new TestViewModel();
                var secondvm = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(firstvm);
                vmManager.RegisterViewModelInstance(secondvm);

                var vmList = vmManager.ActiveViewModels.ToList();

                Assert.IsTrue(vmList.Any(vm => TagHelper.AreTagsEqual(vm.UniqueIdentifier, firstvm.UniqueIdentifier)));
                Assert.IsTrue(vmList.Any(vm => TagHelper.AreTagsEqual(vm.UniqueIdentifier, secondvm.UniqueIdentifier)));
            }
Ejemplo n.º 19
0
            public void ReturnsViewModelForMultiRegisteredViewModel()
            {
                var firstvm = new TestViewModel(){FirstName = "Rajiv", LastName = "Mounguengue"};
                var secondvm = new TestViewModel();
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(firstvm);
                vmManager.RegisterViewModelInstance(secondvm);
                var foundvm = vmManager.GetFirstOrDefaultInstance<TestViewModel>();

                Assert.AreEqual(firstvm, foundvm);
            }
Ejemplo n.º 20
0
        public void RegisterViewModelInstance_Null()
        {
            var manager = new ViewModelManager();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => manager.RegisterViewModelInstance(null));
        }
Ejemplo n.º 21
0
 public void RegisterViewModelInstance_ViewModel()
 {
     var manager = new ViewModelManager();
     manager.RegisterViewModelInstance(new InterestingViewModel());
 }
Ejemplo n.º 22
0
        public void UnregisterViewModelInstance_ExistingViewModel()
        {
            var manager = new ViewModelManager();
            var viewModel = new InterestingViewModel();

            manager.RegisterViewModelInstance(viewModel);
            manager.UnregisterViewModelInstance(viewModel);
        }
Ejemplo n.º 23
0
            public void UnregistersAllModelForViewModel()
            {
                var model = new Person();
                var vm = new TestViewModel(model);
                var vmManager = new ViewModelManager();

                vmManager.RegisterViewModelInstance(vm);
                vmManager.RegisterModel(vm, model);
                
                var foundVm = vmManager.GetViewModelsOfModel(model).First();

                Assert.AreEqual(vm, foundVm);

                vmManager.UnregisterAllModels(vm);

                foundVm = vmManager.GetViewModelsOfModel(model).FirstOrDefault();

                Assert.IsNull(foundVm);
            }
Ejemplo n.º 24
0
        public void RemoveInterestedViewModelInstance_ViewModelForExistingInterestedInViewModel()
        {
            var manager = new ViewModelManager();

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

            manager.RegisterViewModelInstance(interestingViewModel);
            manager.AddInterestedViewModelInstance(typeof(InterestingViewModel), interestedViewModel);
            manager.RemoveInterestedViewModelInstance(typeof(InterestingViewModel), interestedViewModel);
        }