Esempio n. 1
0
        public void WhenCreatingInstance_ThenHasNoErrors()
        {
            var validation = new ErrorsContainer <string>(pn => { });

            Assert.IsFalse(validation.HasErrors);
            Assert.IsFalse(validation.GetErrors("property1").Any());
        }
Esempio n. 2
0
        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);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        public void WhenCreatingInstance_ThenHasNoErrors()
        {
            var validation = new ErrorsContainer<ValidationResult>(pn => { });

            Assert.IsFalse(validation.HasErrors);
            Assert.IsFalse(validation.GetErrors("property1").Any());
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs a validatable bindable base class
 /// </summary>
 public ValidatableBindableBase()
 {
     ErrorsContainer = new ErrorsContainer <ValidationResult>(propertyName =>
     {
         ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
         RaisePropertyChanged(nameof(HasErrors));
     });
 }
Esempio n. 5
0
 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);
 }
Esempio n. 6
0
        public void ValidateObject()
        {
            ErrorsContainer.ClearErrors("");
            var validationResults = new List <ValidationResult>();

            Validator.TryValidateObject(this, new ValidationContext(this, null, null), validationResults);
            ErrorsContainer.SetErrors("", validationResults);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        protected ValidatableViewModel(IMessenger messenger, ArrayFormat errorFormat = ArrayFormat.First)
            : base(messenger)
        {
            ErrorsContainer = new ErrorsContainer();
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer, errorFormat, ObjectErrorPropertyName);
        }
Esempio n. 9
0
        private void Initialize()
        {
            ErrorsContainer = new ErrorsContainer();
            ErrorsContainer.ErrorsChanged += OnErrorsChanged;

            dataErrorInfoProvider = new DataErrorInfoProvider(ErrorsContainer);

            validationOnPropertyChangedEnabled = true;
        }
Esempio n. 10
0
 protected virtual void Submit()
 {
     ErrorsContainer.ClearErrors();
     if (string.IsNullOrEmpty(Name))
     {
         ErrorsContainer.SetErrors(nameof(Name), new List <string> {
             "Please Input Username"
         });
     }
 }
Esempio n. 11
0
 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") });
 }
Esempio n. 12
0
        public void Create(string property)
        {
            var container = new ErrorsContainer <int>(s => { });

            container.HasErrors
            .Should().BeFalse();

            container.GetErrors(property)
            .Should().BeEmpty();
        }
Esempio n. 13
0
        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));
         }
     });
 }
Esempio n. 15
0
        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;
        }
Esempio n. 16
0
        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());
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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());
        }
Esempio n. 20
0
        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());
        }
Esempio n. 21
0
        public MainWindowViewModel()
        {
            container = new ErrorsContainer <string>((propertyName) =>
            {
                ErrorsChanged(this, new DataErrorsChangedEventArgs(propertyName));
            });

            OkCommand = new DelegateCommand(() =>
            {
                MessageBox.Show("登録できました");
            }, () => { return(!HasErrors); }
                                            );
        }
Esempio n. 22
0
        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());
        }
Esempio n. 23
0
        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);
        }
Esempio n. 24
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);
        }
Esempio n. 25
0
        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);
        }
Esempio n. 26
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);
        }
Esempio n. 27
0
        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"));
        }
Esempio n. 28
0
        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());
        }
Esempio n. 29
0
        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());
        }
Esempio n. 30
0
        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);
        }
Esempio n. 32
0
        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);
        }
Esempio n. 33
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);
     }
 }
Esempio n. 34
0
        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 });
        }
Esempio n. 35
0
        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);
        }
Esempio n. 36
0
        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);
        }
Esempio n. 38
0
        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);
        }
Esempio n. 39
0
 // 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);
 }
Esempio n. 40
0
        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);
        }
Esempio n. 41
0
 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);
 }
Esempio n. 42
0
        public void TestErrorsContainer()
        {
            var customer = new Customer();
            var errorsContainer = new ErrorsContainer<string>(customer);

            Assert.IsNotNull(errorsContainer);
            Assert.IsFalse(errorsContainer.All.Any());
        }
Esempio n. 43
0
 protected ValidationObject()
 {
     errorsContainer = new ErrorsContainer<string>(RaiseErrorsChanged);
 }
Esempio n. 44
0
 public MockValidatingViewModel()
 {
     _errorsContainer = new ErrorsContainer<string>(OnErrorsChanged);
 }
Esempio n. 45
0
        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);
 }