本文整理汇总了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);
}
示例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>()));
}
示例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);
}
示例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);
}
示例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]);
}
示例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");
}
示例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);
}
示例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);
}
示例9: RegisterChildViewModel_Null
public void RegisterChildViewModel_Null()
{
var viewModel = new TestViewModel();
ExceptionTester.CallMethodAndExpectException<ArgumentNullException>(() => ((IRelationalViewModel)viewModel).RegisterChildViewModel(null));
}
示例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);
}
示例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);
}
示例12: ViewModelWithViewModelToModelMappings_ValidateModelsOnInitialization
public void ViewModelWithViewModelToModelMappings_ValidateModelsOnInitialization()
{
var person = new PersonWithDataAnnotations();
var viewModel = new TestViewModel(person, true);
Assert.AreNotEqual(0, viewModel.ValidationContext.GetValidationCount());
}
示例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());
}
示例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);
}
示例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);
}