當前位置: 首頁>>代碼示例>>C#>>正文


C# TestClasses.TestViewModel類代碼示例

本文整理匯總了C#中TestClasses.TestViewModel的典型用法代碼示例。如果您正苦於以下問題:C# TestViewModel類的具體用法?C# TestViewModel怎麽用?C# TestViewModel使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TestViewModel類屬於TestClasses命名空間,在下文中一共展示了TestViewModel類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: IsModelRegistered_ExistingModel

            public void IsModelRegistered_ExistingModel()
            {
                var person = new Person();
                person.FirstName = "first name";
                person.LastName = "last name";

                var viewModel = new TestViewModel(person);

                Assert.IsFalse(viewModel.HasDirtyModel);

                person.FirstName = "new first name";

                Assert.IsTrue(viewModel.HasDirtyModel);
            }            
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:14,代碼來源:ViewModelBaseTest.cs

示例2: Constructor_InjectedServiceLocator

        public void Constructor_InjectedServiceLocator()
        {
            var serviceLocator = new ServiceLocator();
            var messageService = new MessageService();
            serviceLocator.RegisterInstance<IMessageService>(messageService);

            var navigationService = new NavigationService();
            serviceLocator.RegisterInstance<INavigationService>(navigationService);

            var viewModel = new TestViewModel(serviceLocator);
            Assert.AreEqual(messageService, viewModel.GetService<IMessageService>());
            Assert.IsTrue(ReferenceEquals(messageService, viewModel.GetService<IMessageService>()));
            Assert.AreEqual(navigationService, viewModel.GetService<INavigationService>());
            Assert.IsTrue(ReferenceEquals(navigationService, viewModel.GetService<INavigationService>()));
        }
開發者ID:pars87,項目名稱:Catel,代碼行數:15,代碼來源:ViewModelBaseTest.cs

示例3: ViewModelWithViewModelToModelMappings_PropertyChanges

        public void ViewModelWithViewModelToModelMappings_PropertyChanges()
        {
            const string FirstName = "first name";
            const string LastName = "last name";
            const uint Age1 = 1;
            const uint Age2 = 2;

            var person = new Person();
            var viewModel = new TestViewModel(person);

            Assert.AreEqual(string.Empty, person.FirstName);
            Assert.AreEqual(string.Empty, viewModel.FirstName);
            Assert.AreEqual(string.Empty, person.LastName);
            Assert.AreEqual(string.Empty, viewModel.LastName);

            Assert.AreEqual(string.Empty, viewModel.FullName);

            Assert.AreEqual(0, person.Age);
            Assert.AreEqual("0", viewModel.Age);

            // Model to view model mapping
            person.FirstName = FirstName;
            Assert.AreEqual(FirstName, person.FirstName);
            Assert.AreEqual(FirstName, viewModel.FirstName);
            Assert.AreEqual(FirstName, viewModel.FullName);

            // View model to model mapping
            viewModel.LastName = LastName;
            Assert.AreEqual(LastName, person.LastName);
            Assert.AreEqual(LastName, viewModel.LastName);
            Assert.AreEqual(FirstName + " " + LastName, viewModel.FullName);
            Assert.AreEqual(FirstName + ";" + LastName, viewModel.FullNameWithCustomSeparator);

            person.Age = Age1;
            Assert.AreEqual(Age1, person.Age);
            Assert.AreEqual(Age1.ToString(), viewModel.Age);

            viewModel.Age = Age2.ToString();
            Assert.AreEqual(Age2, person.Age);
            Assert.AreEqual(Age2.ToString(), viewModel.Age);
        }
開發者ID:justdude,項目名稱:DbExport,代碼行數:41,代碼來源:ViewModelBaseTest.cs

示例4: ViewModelWithViewModelToModelMappings_PropertyChanges

        public void ViewModelWithViewModelToModelMappings_PropertyChanges()
        {
            const string FirstName = "first name";
            const string LastName = "last name";

            var person = new Person();
            var viewModel = new TestViewModel(person);

            Assert.AreEqual(string.Empty, person.FirstName);
            Assert.AreEqual(string.Empty, viewModel.FirstName);
            Assert.AreEqual(string.Empty, person.LastName);
            Assert.AreEqual(string.Empty, viewModel.LastName);

            // Model to view model mapping
            person.FirstName = FirstName;
            Assert.AreEqual(FirstName, person.FirstName);
            Assert.AreEqual(FirstName, viewModel.FirstName);

            // View model to model mapping
            viewModel.LastName = LastName;
            Assert.AreEqual(LastName, person.LastName);
            Assert.AreEqual(LastName, viewModel.LastName);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:23,代碼來源:ViewModelBaseTest.cs

示例5: GetAllModels

        public void GetAllModels()
        {
            Person person = new Person();
            person.FirstName = "first name";
            person.LastName = "last name";

            var viewModel = new TestViewModel(person);

            object[] models = viewModel.GetAllModelsForTest();
            Assert.AreEqual(2, models.Length);
            Assert.AreEqual(person, models[0]);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:12,代碼來源:ViewModelBaseTest.cs

示例6: RegisterChildViewModel_RemovedViaUnregisterChildViewModel

        public void RegisterChildViewModel_RemovedViaUnregisterChildViewModel()
        {
            bool validationTriggered = false;
            ManualResetEvent validatedEvent = new ManualResetEvent(false);

            Person person = new Person();
            person.FirstName = "first name";
            person.LastName = "last name";

            var viewModel = new TestViewModel();
            var childViewModel = new TestViewModel(person);

            Assert.IsFalse(childViewModel.HasErrors);

            ((IRelationalViewModel)viewModel).RegisterChildViewModel(childViewModel);
            viewModel.Validating += delegate
            {
                validationTriggered = true;
                validatedEvent.Set();
            };

            childViewModel.FirstName = string.Empty;

#if NET
            validatedEvent.WaitOne(2000, false);
#else
            validatedEvent.WaitOne(2000);
#endif
            Assert.IsTrue(validationTriggered, "Validating event is not triggered");

            ((IRelationalViewModel)viewModel).UnregisterChildViewModel(childViewModel);

            validationTriggered = false;
            validatedEvent.Reset();

#if NET
            validatedEvent.WaitOne(2000, false);
#else
            validatedEvent.WaitOne(2000);
#endif
            Assert.IsFalse(validationTriggered, "Validating event should not be triggered because child view model is removed");
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:42,代碼來源:ViewModelBaseTest.cs

示例7: ChildViewModelUpdatesValidation

        public void ChildViewModelUpdatesValidation()
        {
            Person person = new Person();
            person.LastName = "last name";

            var viewModel = new TestViewModel();
            var childViewModel = new TestViewModel(person);

            ((IRelationalViewModel)viewModel).RegisterChildViewModel(childViewModel);

            Assert.IsTrue(viewModel.HasErrors);
            Assert.IsTrue(childViewModel.HasErrors);

            person.FirstName = "first name";

            Assert.IsFalse(viewModel.HasErrors);
            Assert.IsFalse(childViewModel.HasErrors);

            person.FirstName = string.Empty;

            Assert.IsTrue(viewModel.HasErrors);
            Assert.IsTrue(childViewModel.HasErrors);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:23,代碼來源:ViewModelBaseTest.cs

示例8: ModelValidation_NotifyDataWarningInfo_FieldWarnings

        public void ModelValidation_NotifyDataWarningInfo_FieldWarnings()
        {
            var testViewModel = new TestViewModel();
            var validation = testViewModel as IModelValidation;

            Assert.IsFalse(validation.HasWarnings);

            testViewModel.SpecialValidationModel = new SpecialValidationModel();

            Assert.IsFalse(validation.HasWarnings);

            testViewModel.SpecialValidationModel.FieldWarningWhenEmpty = string.Empty;

            Assert.IsTrue(validation.HasWarnings);
            Assert.AreNotEqual(string.Empty, ((IDataWarningInfo)testViewModel)["FieldWarningWhenEmpty"]);

            testViewModel.SpecialValidationModel.FieldWarningWhenEmpty = "no warning";

            Assert.IsFalse(validation.HasWarnings);
        }
開發者ID:justdude,項目名稱:DbExport,代碼行數:20,代碼來源:ViewModelBaseTest.cs

示例9: RegisterChildViewModel_Null

        public void RegisterChildViewModel_Null()
        {
            var viewModel = new TestViewModel();

            ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => ((IRelationalViewModel)viewModel).RegisterChildViewModel(null));
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:6,代碼來源:ViewModelBaseTest.cs

示例10: InvalidateCommands_AutomaticByPropertyChange

        public void InvalidateCommands_AutomaticByPropertyChange()
        {
            bool canExecuteChangedTriggered = false;
            var canExecuteChangedEvent = new ManualResetEvent(false);

            var viewModel = new TestViewModel();
            viewModel.SetInvalidateCommandsOnPropertyChanged(true);

            ICatelCommand command = viewModel.GenerateData;
            command.CanExecuteChanged += delegate
            {
                canExecuteChangedTriggered = true;
                canExecuteChangedEvent.Set();
            };

            // By default, command can be executed
            Assert.IsTrue(viewModel.GenerateData.CanExecute(null));

            viewModel.FirstName = "first name";

            Assert.IsFalse(viewModel.GenerateData.CanExecute(null));
#if NET
            canExecuteChangedEvent.WaitOne(1000, false);
#else
            canExecuteChangedEvent.WaitOne(1000);
#endif
            Assert.IsTrue(canExecuteChangedTriggered);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:28,代碼來源:ViewModelBaseTest.cs

示例11: ModelValidation_NotifyDataWarningInfo_BusinessWarnings

        public void ModelValidation_NotifyDataWarningInfo_BusinessWarnings()
        {
            var testViewModel = new TestViewModel();

            Assert.IsFalse(testViewModel.HasWarnings);

            testViewModel.SpecialValidationModel = new SpecialValidationModel();

            Assert.IsFalse(testViewModel.HasWarnings);

            testViewModel.SpecialValidationModel.BusinessRuleWarningWhenEmpty = string.Empty;

            Assert.IsTrue(testViewModel.HasWarnings);
            Assert.AreNotEqual(string.Empty, ((IDataWarningInfo)testViewModel).Warning);

            testViewModel.SpecialValidationModel.BusinessRuleWarningWhenEmpty = "no warning";

            Assert.IsFalse(testViewModel.HasWarnings);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:19,代碼來源:ViewModelBaseTest.cs

示例12: ViewModelWithViewModelToModelMappings_ValidateModelsOnInitialization

        public void ViewModelWithViewModelToModelMappings_ValidateModelsOnInitialization()
        {
            var person = new PersonWithDataAnnotations();
            var viewModel = new TestViewModel(person, true);

            Assert.AreNotEqual(0, viewModel.ValidationContext.GetValidationCount());
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:7,代碼來源:ViewModelBaseTest.cs

示例13: ViewModelWithViewModelToModelMappings_DoNotValidateModelsOnInitialization_UpdateViaModel

        public void ViewModelWithViewModelToModelMappings_DoNotValidateModelsOnInitialization_UpdateViaModel()
        {
            var person = new PersonWithDataAnnotations();
            var viewModel = new TestViewModel(person, false);

            Assert.AreEqual(0, person.ValidationContext.GetValidationCount());
            Assert.AreEqual(0, viewModel.ValidationContext.GetValidationCount());

            person.FirstName = null;

            Assert.AreNotEqual(0, person.ValidationContext.GetValidationCount());
            Assert.AreNotEqual(0, viewModel.ValidationContext.GetValidationCount());
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:13,代碼來源:ViewModelBaseTest.cs

示例14: ViewModelWithViewModelToModelMappings_BusinessErrors

        public void ViewModelWithViewModelToModelMappings_BusinessErrors()
        {
            var person = new Person();
            var viewModel = new TestViewModel(person);

            var personAsError = (IDataErrorInfo)person;
            var viewModelAsError = (IDataErrorInfo)viewModel;

            person.FirstName = "first name";
            person.LastName = "last name";

            Assert.AreEqual(string.Empty, personAsError.Error);
            Assert.AreEqual(string.Empty, viewModelAsError.Error);

            person.FirstName = string.Empty;

            Assert.AreNotEqual(string.Empty, personAsError.Error);
            Assert.AreNotEqual(string.Empty, viewModelAsError.Error);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:19,代碼來源:ViewModelBaseTest.cs

示例15: ViewModelWithViewModelToModelMappings_BusinessWarnings

        public void ViewModelWithViewModelToModelMappings_BusinessWarnings()
        {
            var person = new Person();
            var viewModel = new TestViewModel(person);

            var personAsWarning = (IDataWarningInfo)person;
            var viewModelAsWarning = (IDataWarningInfo)viewModel;

            person.FirstName = "first name";
            person.LastName = "last name";

            Assert.AreNotEqual(string.Empty, personAsWarning.Warning);
            Assert.AreNotEqual(string.Empty, viewModelAsWarning.Warning);

            person.MiddleName = "middle name";

            Assert.AreEqual(string.Empty, personAsWarning.Warning);
            Assert.AreEqual(string.Empty, viewModelAsWarning.Warning);
        }
開發者ID:JaysonJG,項目名稱:Catel,代碼行數:19,代碼來源:ViewModelBaseTest.cs


注:本文中的TestClasses.TestViewModel類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。