public void TestRule() { ViewModelWithValidation vm = new ViewModelWithValidation { StringValue = "123456", IntValue = 0, ObjectValue = new object() }; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); vm.ObjectValue = null; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error an other null error"); vm.ObjectValue = "derfgtyhjuikl"; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); vm.IntValue = -10; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error a greather than error"); vm.IntValue = -5; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); vm.IntValue = 10; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error a less than error"); vm.IntValue = 5; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must still have error a less than error"); vm.IntValue = 0; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); vm.StringValue = null; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error a min len error"); vm.StringValue = "aze"; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must still have error a min len error"); vm.StringValue = "azert"; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); vm.StringValue = "azertazertazert"; Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error a max len error"); vm.StringValue = "azertazert"; Assert.That(string.IsNullOrEmpty(vm.Error), "Must not have error"); }
internal ValidationContainer BuildContainer( EventHandler <DataErrorsChangedEventArgs> errorsChanged, ViewModelWithValidation viewModel) { var propertyValidations = _validationConfiguration.BuildPropertyValidations(); var result = new ValidationContainer(propertyValidations, errorsChanged, viewModel); return(result); }
public void TestRule() { ViewModelWithValidation vm = new ViewModelWithValidation(); //PropertyPublic and PropertyWithProtectedGet are null Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error"); vm.PropertyPublic = "ahahah"; //PropertyWithProtectedGet is null Assert.That(!string.IsNullOrEmpty(vm.Error), "Must still have error"); vm.PropertyWithProtectedGet = "bbbb"; //Ok Assert.That(string.IsNullOrEmpty(vm.Error), "Must have not error"); vm.PropertyWithNoRule = "bbbb"; //No change for rules Assert.That(string.IsNullOrEmpty(vm.Error), "Must still have not error"); vm.PropertyPublic = ""; //PropertyPublic is empty Assert.That(!string.IsNullOrEmpty(vm.Error), "Must have error again"); }
public void CreateChild() { Child = new ViewModelWithValidation(); }