• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# TestClasses.TestViewModel类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中TestClasses.TestViewModel的典型用法代码示例。如果您正苦于以下问题:C# TestViewModel类的具体用法?C# TestViewModel怎么用?C# TestViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TestViewModel类属于TestClasses命名空间,在下文中一共展示了TestViewModel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: ViewModelWithViewModelToModelMappings_FieldWarnings

        public void ViewModelWithViewModelToModelMappings_FieldWarnings()
        {
            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.IsFalse(viewModel.HasErrors);
            Assert.IsTrue(viewModel.HasWarnings);
            Assert.AreNotEqual(string.Empty, personAsWarning[Person.MiddleNameProperty.Name]);
            Assert.AreNotEqual(string.Empty, viewModelAsWarning[TestViewModel.MiddleNameProperty.Name]);

            person.MiddleName = "middle name";

            Assert.IsFalse(viewModel.HasErrors);
            Assert.IsFalse(viewModel.HasWarnings);
            Assert.AreEqual(string.Empty, personAsWarning[Person.MiddleNameProperty.Name]);
            Assert.AreEqual(string.Empty, viewModelAsWarning[TestViewModel.MiddleNameProperty.Name]);
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:23,代码来源:ViewModelBaseTest.cs


示例17: ViewModelWithViewModelToModelMappings_FieldErrors

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

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

            person.FirstName = "first name";

            Assert.AreEqual(string.Empty, personAsError[Person.FirstNameProperty.Name]);
            Assert.AreEqual(string.Empty, viewModelAsError[TestViewModel.FirstNameProperty.Name]);

            person.FirstName = string.Empty;

            Assert.AreNotEqual(string.Empty, personAsError[Person.FirstNameProperty.Name]);
            Assert.AreNotEqual(string.Empty, viewModelAsError[TestViewModel.FirstNameProperty.Name]);
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:18,代码来源:ViewModelBaseTest.cs


示例18: SaveAfterCloseProtection

        public async void SaveAfterCloseProtection()
        {
            var auditor = new TestAuditor();
            AuditingManager.RegisterAuditor(auditor);

            var vm = new TestViewModel();

            Assert.AreEqual(false, auditor.OnViewModelSavedCalled);
            Assert.AreEqual(false, auditor.OnViewModelClosedCalled);

            await vm.SaveAndCloseViewModel();

            Assert.AreEqual(true, auditor.OnViewModelSavedCalled);
            Assert.AreEqual(true, auditor.OnViewModelClosedCalled);

            auditor.OnViewModelSavedCalled = false;
            auditor.OnViewModelClosedCalled = false;

            await vm.SaveAndCloseViewModel();

            Assert.AreEqual(false, auditor.OnViewModelSavedCalled);
            Assert.AreEqual(false, auditor.OnViewModelClosedCalled);
        }
开发者ID:justdude,项目名称:DbExport,代码行数:23,代码来源:ViewModelBaseTest.cs


示例19: ModelsCanceledByCancel

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

            var viewModel = new TestViewModel(person);
            Assert.IsTrue(person.IsInEditSession);

            viewModel.FirstName = "new first name";

            viewModel.CancelAndCloseViewModel();

            Assert.IsFalse(person.IsInEditSession);
            Assert.AreEqual("first name", person.FirstName);            
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:16,代码来源:ViewModelBaseTest.cs


示例20: CloseAfterCloseProtection

        public void CloseAfterCloseProtection()
        {
            var auditor = new TestAuditor();
            AuditingManager.RegisterAuditor(auditor);

            var vm = new TestViewModel();

            Assert.AreEqual(false, auditor.OnViewModelClosedCalled);

            vm.CloseViewModel(null);

            Assert.AreEqual(true, auditor.OnViewModelClosedCalled);

            auditor.OnViewModelClosedCalled = false;

            vm.CloseViewModel(null);

            Assert.AreEqual(false, auditor.OnViewModelClosedCalled);
        }
开发者ID:JaysonJG,项目名称:Catel,代码行数:19,代码来源:ViewModelBaseTest.cs



注:本文中的TestClasses.TestViewModel类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# TestHelper.DiagnosticResult类代码示例发布时间:2022-05-26
下一篇:
C# Test2d.Record类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap