public void validator_should_call_through_to_validate_method() { theValidator.Validate(new ValidatedClass { IsValid = true }).IsValid().ShouldBeTrue(); theValidator.Validate(new ValidatedClass { IsValid = false }).MessagesFor <ValidatedClass>(x => x.Name) .Single().StringToken.ShouldEqual(ValidationKeys.REQUIRED); }
public void TestValidation_MultipleRules_MultipleControls() { //---------------Set up test pack------------------- ValidationProvider validationProvider = new ValidationProvider(GetControlFactory().CreateErrorProvider()); ITextBox textBox1 = GetControlFactory().CreateTextBox(); ITextBox textBox2 = GetControlFactory().CreateTextBox(); ValidationRule validationRule1 = new ValidationRule(); ValidationRule validationRule2 = new ValidationRule(); validationRule2.DataType = ValidationDataType.Integer; validationRule2.MinimumValue = Convert.ToString(2); validationRule2.MaximumValue = Convert.ToString(10); validationRule1.IsRequired = true; validationProvider.SetValidationRule(textBox1, validationRule1); validationProvider.SetValidationRule(textBox2, validationRule1); validationProvider.SetValidationRule(textBox2, validationRule2); bool result = false; //------------------Test PreConditions------------- Assert.IsFalse(result); //---------------Execute Test ---------------------- textBox1.Text = "Hello"; textBox2.Text = "5"; result = validationProvider.Validate(); //---------------Test Result ----------------------- Assert.IsTrue(result); //---------------Tear down ------------------------- }
public void Update(Role entity) { ValidationProvider.Validate(entity); Uow.RoleRepository.Update(entity); Uow.Commit(); }
public bool ValidateData(EntityDetailWorkingMode WorkingMode) { var user = EntityBindingSource.Current; var passwordLengthRule = new PasswordLengthRule(); Guid userId = Guid.Parse(user.GetType().GetProperty("UserId").GetValue(user, null).ToString()); if (WorkingMode == EntityDetailWorkingMode.Add) { SetValidationRule(PasswordTextEdit, ValidationRules.IsNotBlankRule(ItemForPassword.Text)); SetValidationRule(PasswordTextEdit, passwordLengthRule); SetValidationRule(ConfirmPasswordTextEdit, ValidationRules.IsNotBlankRule(ItemForConfirmPassword.Text)); } if (!string.IsNullOrEmpty(PasswordTextEdit.Text)) { SetValidationRule(PasswordTextEdit, passwordLengthRule); var passwordCompareRule = new CompareAgainstControlValidationRule() { CompareControlOperator = CompareControlOperator.Equals, Control = PasswordTextEdit, ErrorText = Resources.ConfirmPasswordNotMatch, ErrorType = ErrorType.Warning }; SetValidationRule(ConfirmPasswordTextEdit, passwordCompareRule); } return(ValidationProvider.Validate()); }
public override void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!ValidationProvider.Validate()) { return; } base.btnSave_ItemClick(sender, e); firmaSatislarBindingSource.EndEdit(); firmaSatislarKalemBindingSource.EndEdit(); firmaSatislarTableAdapter.Update(firmaSatislarDs); try { foreach (DataRow item in firmaSatislarDs.FirmaSatislarKalem.Rows) { if (item.RowState == DataRowState.Added || item.RowState == DataRowState.Modified) { item["FirmaSatisRef"] = (firmaSatislarBindingSource.Current as DataRowView)["Id"]; } } } catch { } firmaSatislarKalemTableAdapter.Update(firmaSatislarDs.FirmaSatislarKalem); }
private bool ValidateBeforeSave() { bool isValid = true; isValid = ValidationProvider.Validate(); return(isValid); }
public virtual bool ValidateData() { messagePanel.ResetText(); messagePanel.Visible = false; var result = ValidationProvider.Validate(); var invalidControls = ValidationProvider.GetInvalidControls(); var invalidMessage = new StringBuilder(); foreach (var invalidControl in invalidControls) { var message = ValidationProvider.GetValidationRule(invalidControl).ErrorText; invalidMessage.AppendLine(message); } if (invalidMessage.Length > 0) { messagePanel.Visible = true; messagePanel.Text = invalidMessage.ToString(); } var firstInvalideControl = invalidControls.FirstOrDefault(); if (firstInvalideControl != null) { var layoutItem = EntityDataLayoutControl.GetItemByControl(firstInvalideControl); if (layoutItem != null && layoutItem.Parent.ParentTabbedGroup != null) { layoutItem.Parent.ParentTabbedGroup.SelectedTabPage = layoutItem.Parent; } } return(result); }
public VmAccount Login(VmLogin model) { if (string.IsNullOrEmpty(model.Login) && string.IsNullOrEmpty(model.Password)) { return new VmAccount { Name = "Tourist", Login = "******", Id = -1 } } ; ValidationProvider.Validate(model); var repository = UnitOfWork.Repository <Account>(); var entity = repository.Queryable().Include(m => m.Player).Where(m => m.Login == model.Login).FirstOrDefault(); if (entity == null) { throw new DataNotFoundException("User"); } if (entity.Password != ("GG" + model.Password + model.Login).Md5Encrypt()) { throw new LocalizedException("IncorrectPassword"); } return(new VmAccount { Name = entity.Player.Name, Login = entity.Login, Id = entity.Id }); }
private void btnSave_Click(object sender, EventArgs e) { using (new CDS.Client.Desktop.Essential.UTL.WaitCursor()) { if (!ValidationProvider.Validate()) { return; } try { using (TransactionScope transaction = DataContext.GetTransactionScope()) { BL.EntityController.SaveORG_TRX_LostSale((DB.ORG_TRX_LostSale)BindingSource.DataSource, DataContext); DataContext.SaveChangesEntityOrganisationContext(); DataContext.CompleteTransaction(transaction); } DataContext.EntityOrganisationContext.AcceptAllChanges(); this.Close(); } catch (Exception ex) { DataContext.EntityOrganisationContext.RejectChanges(); if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } } }
public void It_should_pass_empty_validator() { var provider = new ValidationProvider(); var textBox = new TextBox(); provider.SetValidationRule(textBox, new ValidationRule()); provider.Validate().Should().Be.True(); }
public Role Create(Role entity) { ValidationProvider.Validate(entity); Uow.RoleRepository.Insert(entity); Uow.Commit(); return(entity); }
public override void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (!ValidationProvider.Validate()) { return; } base.btnSave_ItemClick(sender, e); urunlerBindingSource.EndEdit(); urunlerTableAdapter.Update(urunlerDs); }
private bool ValidateBeforeSave() { try { bool isValid = true; //ValidationProvider needs to checked last isValid = IsSupplierValid() && ValidationProvider.Validate(); return isValid; } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return false; } }
private void btnOk_Click(object sender, EventArgs e) { if (ValidationProvider.Validate() && IsPrinterValid()) { ProcessStatements((long)ddlPeriod.EditValue); } using (new CDS.Client.Desktop.Essential.UTL.WaitCursor()) { itmOk.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never; System.Threading.Thread.Sleep(1000); } UpdateTimer.Start(); }
public void TestResultEmptyWhenNoViolations() { var events = TestsBase.GetEvents(@"Logs\noviolations.xml"); var validationConfiguration = new ValidationConfiguration() { SameUsernameAttemptsPeriodLimit = 1, MultipleUsernameAttemptsPeriodLimit = 1, UserNameAttemptsLimit = 1 }; var validationProvider = new ValidationProvider(validationConfiguration); var validationCollection = validationProvider.Validate(events); Assert.IsEmpty(validationCollection); }
public void PlayerValidator_ShouldWork() { var model = new VmPlayer(); try { ValidationProvider.Validate(model); } catch (LocalizedFormatException ex) { Console.WriteLine(ex.GetErrorMessage()); Assert.AreEqual("Required", ex.Format); Assert.AreEqual("Name", ex.Parameter); } }
public bool ValidateData() { var result = ValidationProvider.Validate(); var invalidControls = ValidationProvider.GetInvalidControls(); var firstInvalideControl = invalidControls.FirstOrDefault(); if (firstInvalideControl != null) { var layoutItem = attributeDetailLayoutControl.GetItemByControl(firstInvalideControl); if (layoutItem != null && layoutItem.Parent.ParentTabbedGroup != null) { layoutItem.Parent.ParentTabbedGroup.SelectedTabPage = layoutItem.Parent; } } return(result); }
public virtual bool ValidateData() { messagePanel.ResetText(); messagePanel.Visible = false; var result = ValidationProvider.Validate(); var invalidControls = ValidationProvider.GetInvalidControls(); var invalidMessage = new StringBuilder(); _validationSort.ToList().ForEach(c => _validationSort[c.Key] = string.Empty); foreach (var invalidControl in invalidControls) { var message = ValidationProvider.GetValidationRule(invalidControl).ErrorText; if (_validationSort.Keys.Contains(invalidControl.Name)) { _validationSort[invalidControl.Name] = message; } else { invalidMessage.AppendLine(message); } } foreach (var validationItem in _validationSort) { if (string.IsNullOrEmpty(validationItem.Value)) { continue; } invalidMessage.AppendLine(validationItem.Value); } if (invalidMessage.Length > 0) { messagePanel.Visible = true; messagePanel.Text = invalidMessage.ToString(); } var firstInvalideControl = invalidControls.FirstOrDefault(); if (firstInvalideControl != null) { var layoutItem = EntityDataLayoutControl.GetItemByControl(firstInvalideControl); if (layoutItem != null && layoutItem.Parent.ParentTabbedGroup != null) { layoutItem.Parent.ParentTabbedGroup.SelectedTabPage = layoutItem.Parent; } } return(result); }
/// <summary> /// Checks that below conditions are valid. /// * Type for control account has been selected /// </summary> /// <returns>Boolean values indicating weather conditions have been met.</returns> /// <remarks>Created: Werner Scheffer 19/03/2014</remarks> private bool ValidateBeforeSave() { try { bool isValid = true; isValid = ValidationProvider.Validate() && IsEntityNameValid(); return(isValid); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } }
public virtual bool ValidateBeforeSave() { try { bool isValid = true; isValid = ValidationProvider.Validate() && HasEntries() && HasValidEntries() && HasValidPeriods() && HasValidContraAccounts() && HasValidReference() && HasValidDescription(); return(isValid); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } return(false); } }
public void TestValidation_RequiredFieldFails() { //---------------Set up test pack------------------- ValidationProvider validationProvider = new ValidationProvider(GetControlFactory().CreateErrorProvider()); ITextBox textBox1 = GetControlFactory().CreateTextBox(); ValidationRule validationRule1 = new ValidationRule(); validationRule1.IsRequired = true; validationProvider.SetValidationRule(textBox1, validationRule1); bool result = true; //-------------------Test PreConditions------------ Assert.IsTrue(result); //---------------Execute Test ---------------------- result = validationProvider.Validate(); //---------------Test Result ----------------------- Assert.IsFalse(result); //---------------Tear down ------------------------- }
public void AddPlayer(VmRegistry model) { ValidationProvider.Validate(model); var repository = base.UnitOfWork.Repository <Player>(); var exist_entity = repository.Queryable().FirstOrDefault(m => m.Account.Login == model.Login || m.Email == model.Email); if (exist_entity != null) { if (exist_entity.Email == model.Email) { throw new DuplicateDataException("Email"); } else { throw new DuplicateDataException("Login"); } } var entity = new Player { Name = model.Name, Birth = DateTime.Parse(model.Birth), Sex = model.Sex, Email = model.Email, ObjectState = ObjectState.Added, Account = new Account { Login = model.Login, Password = ("GG" + model.Password + model.Login).Md5Encrypt(), CreateAt = DateTime.Now, ObjectState = ObjectState.Added, } }; repository.Insert(entity); base.UnitOfWork.SaveChanges(); }
public void TestValidation_RequiredField_Fails_TwoControls_OneControl_IsIncorrect() { //---------------Set up test pack------------------- ValidationProvider validationProvider = new ValidationProvider(GetControlFactory().CreateErrorProvider()); ITextBox textBox1 = GetControlFactory().CreateTextBox(); ITextBox textBox2 = GetControlFactory().CreateTextBox(); ValidationRule validationRule1 = new ValidationRule(); validationRule1.IsRequired = true; validationProvider.SetValidationRule(textBox1, validationRule1); validationProvider.SetValidationRule(textBox2, validationRule1); bool result = true; //-------------------Test PreConditions------------ Assert.IsTrue(result); //---------------Execute Test ---------------------- textBox1.Text = ""; textBox2.Text = "World"; result = validationProvider.Validate(); //---------------Test Result ----------------------- Assert.IsFalse(result); //---------------Tear down ------------------------- }
public void TestValidation_RequiredFieldOnOneControl() { //---------------Set up test pack------------------- ValidationProvider validationProvider = new ValidationProvider(GetControlFactory().CreateErrorProvider()); ITextBox textBox1 = GetControlFactory().CreateTextBox(); ValidationRule validationRule1 = new ValidationRule(); validationRule1.IsRequired = true; validationRule1.DataType = ValidationDataType.Integer; validationRule1.MinimumValue = Convert.ToString(2); validationRule1.MaximumValue = Convert.ToString(10); validationProvider.SetValidationRule(textBox1, validationRule1); bool result = false; //-------------------Test PreConditions------------ Assert.IsFalse(result); //---------------Execute Test ---------------------- textBox1.Text = Convert.ToString(5); result = validationProvider.Validate(); //---------------Test Result ----------------------- Assert.IsTrue(result); //---------------Tear down ------------------------- }
private void btnImport_Click(object sender, EventArgs e) { if (!ValidationProvider.Validate()) { return; } try { bulkentries.Clear(); using (CsvReader csv = new CsvReader(new StreamReader((String)txtFile.EditValue), true, ddlSeperator.Text[0], CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, true)) { while (csv.ReadNextRecord()) { try { DB.VW_Account Account = DataContext.ReadonlyContext.VW_Account .Where(n => n.Archived.Equals(false) && n.CodeSub.Equals(tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : "")).FirstOrDefault(); DB.GLX_Aging aging = DataContext.EntityAccountingContext.GLX_Aging .Where(n => n.Code.Contains(tblFields.Rows[4][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[4][1].ToString()]) : "")).OrderBy(o => o.Id) .FirstOrDefault(); //TODO : Need to make this so that you can choose account on Payment/Receipt screens if (Account == null) { skippedAccounts.Add(tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : ""); continue; } bulkentries.Add(new BulkPaymentEntry() { //PeriodId = DB.SYS_PeriodGetCurrentPeriod().Id, PeriodId = Convert.ToInt64(ddlPeriod.EditValue), Date = tblFields.Rows[0][1].ToString() != "<NOT MAPPED>" ? ParseDate(csv[tblFields.Rows[0][1].ToString()]) : DateTime.Now, AccountId = Account != null ? (Int64?)Account.Id : null, Reference = tblFields.Rows[2][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[2][1].ToString()]) : "", Description = tblFields.Rows[3][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[3][1].ToString()]) : "", AgingId = aging != null ? aging.Id : (Int16)1, Settlement = 0, Amount = tblFields.Rows[5][1].ToString() != "<NOT MAPPED>" ? ParseDecimal(csv[tblFields.Rows[5][1].ToString()]) * (chkReverseAmounts.Checked ? -1 : 1) : 0 }); } catch (Exception) { String [] rowdata = new string[csv.FieldCount]; csv.CopyCurrentRecordTo(rowdata); CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Parsing Error", String.Format("There was a problem reading a value from the row and the import will not continue. The row data provided: \n{0}.", String.Join(ddlSeperator.Text, rowdata)), Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Warning); return; } } } CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter(); DevExpress.XtraFilterEditor.FilterEditorControl filRule = new DevExpress.XtraFilterEditor.FilterEditorControl(); foreach (DB.GLX_BulkEntryRule rule in DataContext.EntityAccountingContext.GLX_BulkEntryRule.Where(n => n.EntityId == (Int64)ddlAccount.EditValue)) { filRule.FilterString = rule.EntryRule; filRule.ApplyFilter(); //http://www.devexpress.com/Support/Center/p/Q357031.aspx var qry = ((IQueryable <BulkPaymentEntry>)bulkentries.AsQueryable().AppendWhere(converter, filRule.FilterCriteria)).ToList(); if (rule.EntryAction == "N") { // Do not import foreach (BulkPaymentEntry row in qry) { bulkentries.Remove(row); } } else if (rule.EntryAction == "Y") { // Import foreach (BulkPaymentEntry row in qry) { row.AccountId = rule.EntityContraId; } } } // Get taxes List <DB.GLX_Tax> taxes = DataContext.EntityAccountingContext.GLX_Tax.ToList(); // Populate periods this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
private void btnImport_Click(object sender, EventArgs e) { if (!ValidationProvider.Validate()) { return; } try { using (CsvReader csv = new CsvReader(new StreamReader((String)txtFile.EditValue), true, ddlSeperator.Text[0], CsvReader.DefaultQuote, CsvReader.DefaultEscape, CsvReader.DefaultComment, true)) { while (csv.ReadNextRecord()) { try { bulkentries.Add(new BulkEntry() { //PeriodId = DB.VW_PeriodGetCurrentPeriod().Id, PeriodId = Convert.ToInt64(ddlPeriod.EditValue), Date = tblFields.Rows[0][1].ToString() != "<NOT MAPPED>" ? ParseDate(csv[tblFields.Rows[0][1].ToString()]) : DateTime.Now, AccountId = null, AgingId = 1, Reference = tblFields.Rows[1][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[1][1].ToString()]) : "", Description = tblFields.Rows[2][1].ToString() != "<NOT MAPPED>" ? ParseString(csv[tblFields.Rows[2][1].ToString()]) : "", TaxId = 1, Exclusive = 0, Inclusive = tblFields.Rows[3][1].ToString() != "<NOT MAPPED>" ? ParseDecimal(csv[tblFields.Rows[3][1].ToString()]) * (chkReverseAmounts.Checked ? -1 : 1) : 0 }); } catch (Exception) { String [] rowdata = new string[csv.FieldCount]; csv.CopyCurrentRecordTo(rowdata); CDS.Client.Desktop.Essential.BaseAlert.ShowAlert("Parsing Error", String.Format("There was a problem reading a value from the row and the import will not continue. The row data provided: \n{0}.", String.Join(ddlSeperator.Text, rowdata)), Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Warning); return; } } } CriteriaToExpressionConverter converter = new CriteriaToExpressionConverter(); DevExpress.XtraFilterEditor.FilterEditorControl filRule = new DevExpress.XtraFilterEditor.FilterEditorControl(); foreach (DB.GLX_BulkEntryRule rule in DataContext.EntityAccountingContext.GLX_BulkEntryRule.Where(n => n.EntityId == (Int64)ddlAccount.EditValue)) { filRule.FilterString = rule.EntryRule; filRule.ApplyFilter(); //http://www.devexpress.com/Support/Center/p/Q357031.aspx var qry = ((IQueryable <BulkEntry>)bulkentries.AsQueryable().AppendWhere(converter, filRule.FilterCriteria)).ToList(); if (rule.EntryAction == "N") { // Do not import foreach (BulkEntry row in qry) { bulkentries.Remove(row); } } else if (rule.EntryAction == "N") { // Import foreach (BulkEntry row in qry) { row.AccountId = rule.EntityContraId; row.TaxId = rule.TaxId; } } } // Get taxes List <DB.GLX_Tax> taxes = DataContext.EntityAccountingContext.GLX_Tax.ToList(); // Populate inclusive/exclusive amounts if (!chkExclusive.Checked) { // Amounts include tax //exclusive = inclusive * 100/114 //exclusive = inclusive * 100/100+percentage // * 1 / 1+percentage foreach (BulkEntry row in bulkentries) { row.Exclusive = Math.Round(row.Inclusive.Value * 1.0m / (1.0m + taxes.FirstOrDefault(n => n.Id == row.TaxId).Percentage), 2, MidpointRounding.AwayFromZero); } } else { // Amounts exclude tax //inclusive = exclusive * 114 //inclusive = exclusive * 100+percentage // * 1+percentage foreach (BulkEntry row in bulkentries) { row.Exclusive = row.Inclusive; row.Inclusive = Math.Round(row.Exclusive.Value * (1.0m + taxes.FirstOrDefault(n => n.Id == row.TaxId).Percentage), 2, MidpointRounding.AwayFromZero); } } // Populate periods this.DialogResult = System.Windows.Forms.DialogResult.OK; this.Close(); } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }