Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void RemoveViewModelInstance_NotRegisteredViewModel()
        {
            ViewModelManager.ClearAll();

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

            viewModel.RemoveViewModelInstance(new InterestingViewModel());
        }
Ejemplo n.º 3
0
        public void RemoveViewModelInstance_Null()
        {
            ViewModelManager.ClearAll();

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

            ExceptionTester.CallMethodAndExpectException <ArgumentNullException>(() => viewModel.RemoveViewModelInstance(null));
        }
Ejemplo n.º 4
0
        public void AddViewModelInstance_NewInstance()
        {
            ViewModelManager.ClearAll();

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

            viewModel.AddViewModelInstance(new InterestingViewModel());
        }
Ejemplo n.º 5
0
        public void RemoveViewModelInstance_RegisteredViewModel()
        {
            ViewModelManager.ClearAll();

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

            var interestingViewModel = new TestViewModel();

            viewModel.AddViewModelInstance(interestingViewModel);
            viewModel.RemoveViewModelInstance(interestingViewModel);
        }
Ejemplo n.º 6
0
        public void InterestingViewModel_Event_Closed()
        {
            ViewModelManager.ClearAll();

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

            interestingViewModel.CloseViewModel(null);

            Assert.AreEqual(1, interestedViewModel.ViewModelEvents.Count);
            Assert.AreEqual(ViewModelEvent.Closed, interestedViewModel.ViewModelEvents[0]);

            interestingViewModel.CloseViewModel(false);
            interestedViewModel.CloseViewModel(false);
        }
Ejemplo n.º 7
0
        public void InterestingViewModel_Event_CancelingAndCanceled()
        {
            ViewModelManager.ClearAll();

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

            interestingViewModel.CancelViewModel();

            Assert.AreEqual(2, interestedViewModel.ViewModelEvents.Count);
            Assert.AreEqual(ViewModelEvent.Canceling, interestedViewModel.ViewModelEvents[0]);
            Assert.AreEqual(ViewModelEvent.Canceled, interestedViewModel.ViewModelEvents[1]);

            interestingViewModel.CloseViewModel(false);
            interestedViewModel.CloseViewModel(false);
        }
Ejemplo n.º 8
0
        public async Task InterestingViewModel_Event_SavingAndSaved()
        {
            ViewModelManager.ClearAll();

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

            await interestingViewModel.SaveViewModel();

            Assert.AreEqual(2, interestedViewModel.ViewModelEvents.Count);
            Assert.AreEqual(ViewModelEvent.Saving, interestedViewModel.ViewModelEvents[0]);
            Assert.AreEqual(ViewModelEvent.Saved, interestedViewModel.ViewModelEvents[1]);

            await interestingViewModel.CloseViewModel(false);

            await interestedViewModel.CloseViewModel(false);
        }
Ejemplo n.º 9
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));
            }
        }
Ejemplo n.º 10
0
        public void 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);

            interestingViewModel.CloseViewModel(false);
            interestedViewModel.CloseViewModel(false);
        }
Ejemplo n.º 11
0
        public void 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);

            interestingViewModel.CloseViewModel(false);
            interestedViewModel.CloseViewModel(false);
        }
Ejemplo n.º 12
0
        public async Task InterestingViewModelCommandExecuted()
        {
            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(null);

            Assert.AreEqual(true, interestedViewModel.CommandHasBeenExecuted);
            Assert.AreEqual(false, interestedViewModel.CommandHasBeenExecutedWithParameter);

            await interestingViewModel.CloseViewModelAsync(false);

            await interestedViewModel.CloseViewModelAsync(false);
        }