public void WhenCreatingInstance_ThenHasNoErrors() { var validation = new ErrorsContainer <string>(pn => { }); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); }
void Validate() { if (Validator != null) { lock (lockObj) { ValidationResult results = Validator.Validate(); if (results != null) { // reset error container ErrorsContainer.ClearAllErrors(); List <string> errorPropertyNames = results.Errors.Select(x => x.PropertyName).ToList(); if ((errorPropertyNames != null) && (errorPropertyNames.Count > 0)) { foreach (var propertyName in errorPropertyNames) { List <string> errorMessages = results.Errors.Where(pn => pn.PropertyName.ToLower() == propertyName.ToLower()).Select(x => x.ErrorMessage).ToList(); ErrorsContainer.SetErrors(propertyName, errorMessages); OnErrorsChanged(propertyName); } } } } } }
public void WhenCreatingInstance_ThenHasNoErrors() { var validation = new ErrorsContainer<ValidationResult>(pn => { }); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); }
/// <summary> /// Constructs a validatable bindable base class /// </summary> public ValidatableBindableBase() { ErrorsContainer = new ErrorsContainer <ValidationResult>(propertyName => { ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName)); RaisePropertyChanged(nameof(HasErrors)); }); }
public static void SetErrors <T>(this ErrorsContainer <T> errorsContainer, string propertyName, params T[] errors) { if (errorsContainer == null) { throw new ArgumentNullException(nameof(errorsContainer)); } errorsContainer.SetErrors(propertyName, (IEnumerable <T>)errors); }
public void ValidateObject() { ErrorsContainer.ClearErrors(""); var validationResults = new List <ValidationResult>(); Validator.TryValidateObject(this, new ValidationContext(this, null, null), validationResults); ErrorsContainer.SetErrors("", validationResults); }
private string GetErrorsFor <T>(Expression <Func <T> > propertyExpression) { var errors = ErrorsContainer.GetErrors(PropertySupport.ExtractPropertyName(propertyExpression)); var errStrs = errors.Where(r => !r.IsValid).Select(r => r.ErrorContent.ToString()); var errStr = string.Join(Environment.NewLine, errStrs); return(errStr); }
protected ValidatableViewModel(IMessenger messenger, ArrayFormat errorFormat = ArrayFormat.First) : base(messenger) { ErrorsContainer = new ErrorsContainer(); ErrorsContainer.ErrorsChanged += OnErrorsChanged; dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer, errorFormat, ObjectErrorPropertyName); }
private void Initialize() { ErrorsContainer = new ErrorsContainer(); ErrorsContainer.ErrorsChanged += OnErrorsChanged; dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer); validationOnPropertyChangedEnabled = true; }
protected virtual void Submit() { ErrorsContainer.ClearErrors(); if (string.IsNullOrEmpty(Name)) { ErrorsContainer.SetErrors(nameof(Name), new List <string> { "Please Input Username" }); } }
public EditWaypointViewModelDesign() : base(null) { WaypointModel = new WaypointModel() { Identifier = "IDENT", Latitude = 6.66, Longitude = 12.89 }; ErrorsContainer.SetErrors(() => Identifier, new[] { new ValidationResult(false, "Identifier error") }); ErrorsContainer.SetErrors(() => Longitude, new [] { new ValidationResult(false, "Longitude error") }); ErrorsContainer.SetErrors(() => Latitude, new[] { new ValidationResult(false, "Latitude error") }); }
public void Create(string property) { var container = new ErrorsContainer <int>(s => { }); container.HasErrors .Should().BeFalse(); container.GetErrors(property) .Should().BeEmpty(); }
public void WhenClearingErrorsWithNullPropertyName_ThenHasErrors() { List <string> validatedProperties = new(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validation.ClearErrors(null); Assert.True(validation.HasErrors); Assert.True(validation.GetErrors("property1").Any()); }
public EmployeeViewModel() { this.validationErrors = new ErrorsContainer<string>(property => { var handler = this.ErrorsChanged; if (handler != null) { handler(this, new System.ComponentModel.DataErrorsChangedEventArgs(property)); } }); }
private void ValidateProperty(object value, [CallerMemberName] string propertyName = null) { var res = new List <ValidationResult>(); var validationresult = Validator.TryValidateProperty(value, new ValidationContext(this, null, null) { MemberName = propertyName }, res); ErrorsContainer.SetErrors(propertyName, res); HasErrors = validationresult; }
public void WhenGettingErrorsWithPropertyName_ThenErrorsReturned() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); var errors = validation.GetErrors("property1"); Assert.True(errors.Any()); }
public void WhenSettingErrorsForPropertyWithNoErrors_ThenNotifiesChangesAndHasErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message"}); Assert.True(validation.HasErrors); Assert.True(validation.GetErrors("property1").Contains("message")); Assert.Equal(new[] { "property1" }, validatedProperties); }
public void WhenSettingErrorsForPropertyWithNoErrors_ThenNotifiesChangesAndHasErrors() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); Assert.IsTrue(validation.HasErrors); Assert.IsTrue(validation.GetErrors("property1").Contains("message")); CollectionAssert.AreEqual(new[] { "property1" }, validatedProperties); }
public void WhenSettingNoErrorsForPropertyWithNoErrors_ThenDoesNotNotifyChangesAndHasNoErrors() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new string[0]); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); Assert.IsFalse(validatedProperties.Any()); }
public void WhenSettingNoErrorsForPropertyWithNoErrors_ThenDoesNotNotifyChangesAndHasNoErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<ValidationResult>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new ValidationResult[0]); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); Assert.IsFalse(validatedProperties.Any()); }
public MainWindowViewModel() { container = new ErrorsContainer <string>((propertyName) => { ErrorsChanged(this, new DataErrorsChangedEventArgs(propertyName)); }); OkCommand = new DelegateCommand(() => { MessageBox.Show("登録できました"); }, () => { return(!HasErrors); } ); }
public void WhenClearingErrorsWithNullPropertyname_ThenHasErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validation.ClearErrors(null); Assert.IsTrue(validation.HasErrors); Assert.IsTrue(validation.GetErrors("property1").Any()); }
public void WhenGettingErrorsWithNullPropertyName_ThenNoErrorsReturned() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); var errors = validation.GetErrors(null); Assert.IsTrue(validation.HasErrors); Assert.IsTrue(errors.Count() == 0); }
public void WhenSettingErrorsForPropertyWithNoErrors_ThenNotifiesChangesAndHasErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<ValidationResult>(pn => validatedProperties.Add(pn)); var validationError = new ValidationResult("message", new[] { "property1" }); validation.SetErrors("property1", new[] { validationError }); Assert.IsTrue(validation.HasErrors); Assert.IsTrue(validation.GetErrors("property1").Contains(validationError)); CollectionAssert.AreEqual(new[] { "property1" }, validatedProperties); }
public void WhenGettingErrorsWithNullPropertyName_ThenNoErrorsReturned() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); var errors = validation.GetErrors(null); Assert.True(validation.HasErrors); Assert.True(errors.Count() == 0); }
/// <summary> /// Validates <paramref name="value"/> as the value for the property specified by /// <paramref name="validationContext"/> using data annotations validation attributes. /// </summary> /// <param name="validationContext">The context for the validation.</param> /// <param name="value">The value for the property.</param> protected virtual void ValidateProperty(ValidationContext validationContext, object value) { if (validationContext == null) { throw new ArgumentNullException("validationContext"); } var validationResults = new List <ValidationResult>(); Validator.TryValidateProperty(value, validationContext, validationResults); ErrorsContainer.SetErrors(validationContext.MemberName, validationResults); }
public void WhenGettingErrors_ThenErrorsPerPropertyReturned() { List <string> validatedProperties = new(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validation.SetErrors("property2", new[] { "message" }); var errors = validation.GetErrors(); Assert.True(errors.Any()); Assert.True(errors.Count == 2); Assert.Contains(errors, e => e.Key.Equals("property1")); Assert.Contains(errors, e => e.Key.Equals("property2")); }
public void WhenClearingErrorsForPropertyWithErrors_ThenPropertyHasNoErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validation.SetErrors("property2", new[] { "message2" }); validation.ClearErrors("property1"); Assert.IsTrue(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); Assert.IsTrue(validation.GetErrors("property2").Any()); }
public void WhenClearingErrorsForPropertyWithErrors_ThenPropertyHasNoErrors() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validation.SetErrors("property2", new[] { "message2" }); validation.ClearErrors("property1"); Assert.True(validation.HasErrors); Assert.False(validation.GetErrors("property1").Any()); Assert.True(validation.GetErrors("property2").Any()); }
public void WhenSettingNoErrorsForPropertyWithErrors_ThenNotifiesChangesAndHasNoErrors() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validatedProperties.Clear(); validation.SetErrors("property1", new string[0]); Assert.False(validation.HasErrors); Assert.False(validation.GetErrors("property1").Any()); Assert.Equal(new[] { "property1" }, validatedProperties); }
public void WhenSettingNoErrorsForPropertyWithErrors_ThenNotifiesChangesAndHasNoErrors() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); validatedProperties.Clear(); validation.SetErrors("property1", new string[0]); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); CollectionAssert.AreEqual(new[] { "property1" }, validatedProperties); }
public void InsertNull(string property) { var called = 0; var container = new ErrorsContainer <int>(_ => called++); container.SetErrors(property, null); container.HasErrors .Should().BeFalse(); container.GetErrors(property) .Should().BeEmpty(); called .Should().Be(0); }
private void DoValidate(string propertyName = null) { if (string.IsNullOrWhiteSpace(propertyName)) { foreach (var prop in _propertyNames) { IEnumerable <string> errors = ValidateProperty(prop); ErrorsContainer.SetErrors(prop, errors); } } else { IEnumerable <string> errors = ValidateProperty(propertyName); ErrorsContainer.SetErrors(propertyName, errors); } }
public void InsertSame(string property) { var called = 0; var container = new ErrorsContainer <int>(_ => called++); container.SetErrors(property, new[] { 1, 2, 4 }); container.SetErrors(property, new[] { 1, 2, 4 }); called .Should().Be(2); container.HasErrors .Should().BeTrue(); container.GetErrors(property) .Should().BeEquivalentTo(new[] { 1, 2, 4 }); }
public void WhenSettingNoErrorsForPropertyWithErrors_ThenNotifiesChangesAndHasNoErrors() { List <string> validatedProperties = new List <string>(); var validation = new ErrorsContainer <ValidationResult>(pn => validatedProperties.Add(pn)); var validationError = new ValidationResult("message", new[] { "property1" }); validation.SetErrors("property1", new[] { validationError }); validatedProperties.Clear(); validation.SetErrors("property1", new ValidationResult[0]); Assert.IsFalse(validation.HasErrors); Assert.IsFalse(validation.GetErrors("property1").Any()); CollectionAssert.AreEqual(new[] { "property1" }, validatedProperties); }
public void InsertSingleAndClear(string property) { var called = 0; var container = new ErrorsContainer <int>(_ => called++); container.SetErrors(property, new[] { 1 }); container.ClearErrors(property); called .Should().Be(2); container.HasErrors .Should().BeFalse(); container.GetErrors(property) .Should().BeEmpty(); }
public override bool ValidateProperties() { base.ValidateProperties(); //Aggregate Invariants var results = new List <ValidationResult>(); var context = new ValidationContext(this); var propertyErrors = new List <string>(); Validator.TryValidateObject(this, context, results); if (results.Any()) { propertyErrors.AddRange(results.Select(c => c.ErrorMessage)); } ErrorsContainer.SetErrors(nameof(Details), propertyErrors); return(ErrorsContainer.HasErrors); }
private bool ValidateLatitude(string val) { var valid = _latConverter.ValidateString(val); if (valid) { ErrorsContainer.ClearErrors(() => Latitude); } else { ErrorsContainer.ClearErrors(() => Latitude); ErrorsContainer.SetErrors(() => Latitude, new[] { new ValidationResult(false, "Please use the N23°45.6 or S2345.6 format."), }); } RaiseErrorsChanged(() => Latitude); _saveCommand?.RaiseCanExecuteChanged(); OnPropertyChanged(() => LatitudeErrors); return(valid); }
// statusChangedAction : IsWorking, Status public LoginViewModel(WikiSiteViewModel siteVm, Action <bool> closeViewAction, Action <bool, string> statusChangedAction) { if (siteVm == null) { throw new ArgumentNullException(nameof(siteVm)); } if (closeViewAction == null) { throw new ArgumentNullException(nameof(closeViewAction)); } if (statusChangedAction == null) { throw new ArgumentNullException(nameof(statusChangedAction)); } WikiSite = siteVm; _CloseViewAction = closeViewAction; _StatusChangedAction = statusChangedAction; errors = new ErrorsContainer <string>(OnErrorsChanged); }
public bool Compile(string inputText, Stream outStream) { errorsContainer = new ErrorsContainer(); if (!outStream.CanWrite) { return false; } // parse var parser = new Parser(); parser.ErrorDispatcher.Error += this.OnErrorOccurred; if (!parser.Parse(inputText)) { return false; } var rootNode = parser.GetRootNode(); // check code paths var codePathChecker = new CodePathChecker(); codePathChecker.ErrorDispatcher.Error += this.OnErrorOccurred; if (!codePathChecker.Check(rootNode)) { return false; } // fill types && semantic checks var typeEval = new TypeEvaluator(); typeEval.ErrorDispatcher.Error += this.OnErrorOccurred; if (!typeEval.Evaluate(rootNode)) { return false; } // generate code var generator = new LLVMCodeGenerator(); generator.SetSymbolTable(typeEval.GetSymbolTable()); generator.ErrorDispatcher.Error += this.OnErrorOccurred; return generator.Generate(rootNode, outStream); }
public MapViewModel(IRegionManager regionManager, IEventAggregator eventAggregator, ILoggerFacade loggerFacade, IConfiguration configuration) { _container = new ErrorsContainer<string>(OnErrorsChanged); this.regionManager = regionManager; mapDataEvent = eventAggregator.GetEvent<CompositePresentationEvent<MapData>>(); mapLoadedEvent = eventAggregator.GetEvent<CompositePresentationEvent<MapLoaded>>(); mapExtentEvent = eventAggregator.GetEvent<CompositePresentationEvent<MapExtent>>(); this._loggerFacade = loggerFacade; this.configuration = configuration; _notificationErrorInteraction = new InteractionRequest<Notification>(); this.NotificationErrorInteraction.Raised += (o, e) => { // Do some logging _loggerFacade.Log(e.Context.Content as string, Category.Exception, Priority.High); var result = messageBoxCustom.Show(e.Context.Content as string, Silverlight.UI.Esri.JTMap.Resources.Map.ErrorMessage, MessageBoxCustomEnum.MessageBoxButtonCustom.Ok); }; HandleRightClick = new DelegateCommand<object>(this.OnRightMouseClicked, this.CanRightMouseClicked); this.ContextMenuVisibility = Visibility.Collapsed; this.MenuItemCommand = new DelegateCommand<object>( this.OnMenuItemClicked, this.CanMenuItemClicked); string tradeNote = "J&T Software BVBA - Custom Silverlight map editor - Version 1.0"; HelpContents.DisplayHelp(tradeNote, regionManager,false); }
public void TestErrorsContainer() { var customer = new Customer(); var errorsContainer = new ErrorsContainer<string>(customer); Assert.IsNotNull(errorsContainer); Assert.IsFalse(errorsContainer.All.Any()); }
protected ValidationObject() { errorsContainer = new ErrorsContainer<string>(RaiseErrorsChanged); }
public MockValidatingViewModel() { _errorsContainer = new ErrorsContainer<string>(OnErrorsChanged); }
public void WhenGettingErrorsWithPropertyName_ThenErrorsReturned() { List<string> validatedProperties = new List<string>(); var validation = new ErrorsContainer<string>(pn => validatedProperties.Add(pn)); validation.SetErrors("property1", new[] { "message" }); var errors = validation.GetErrors("property1"); Assert.True(errors.Any()); }
protected InteractionRequestValidationObject() { errorsContainer = new ErrorsContainer<string>(RaiseErrorsChanged); }