public bool CheckPassword(UserEntity user, PasswordModel passwordModel) { PasswordValidator validator = new PasswordValidator(); var result = validator.Validate(passwordModel); if (!result.IsValid) { UpdatePasswordMessage = ErrorMessageGenerator.ComposeErrorMessage(result); return(false); } if (!passwordModel.OldPassword.Equals(user.UserPassword)) { UpdatePasswordMessage = MessageConstants.IncorrectPasswordMessage; return(false); } if (passwordModel.OldPassword.Equals(passwordModel.NewPassword)) { UpdatePasswordMessage = MessageConstants.NoPasswordChange; return(false); } user.UserPassword = passwordModel.NewPassword; return(true); }
protected ValidationResult unitsAreConsistant(ITableAdapter tableAdapter) { //NOTE: tableAdapter gets rid of the last row for us so we can act like it isn't there if (tableAdapter.GetRowCount() == 1) { //Only one row so it must be true; return(ValidationResult.Empty); } string firstRowUnits = tableAdapter.GetUnitAtRow(0); string secondRowUnits = tableAdapter.GetUnitAtRow(1); //the firstRowUnits must be equal too the secondRowUnits unless secondRowUnits is wildcard if (firstRowUnits != secondRowUnits && secondRowUnits != "?") { return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Inconsistant_Units))); } //start i at 2 int i = 2; while (i < tableAdapter.GetRowCount()) { //All subrows must be in percent if the second row is or match the first and second row but we know they are equal if (secondRowUnits != tableAdapter.GetUnitAtRow(i)) { return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Inconsistant_Units))); } i++; } return(ValidationResult.Empty); }
ValidationResult EquationValidation() { if (isSumOfOneTable()) { //TO DO: Check to make sure all the parts they are adding together are all members of the same table //Assume units are ok since they must be ok for a table to be valid return(ValidationResult.Empty); } else if (OverallSum()) { //All compounds are Overall must check units now if (!CheckSameUnits()) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.More_Than_One_Unit))); } } else { //Everything should be the same compound need to check that if (!CheckSameCompound()) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.More_Than_One_Compound))); } //need to check that all units are correct if (!CheckSameUnits()) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.More_Than_One_Unit))); } } return(ValidationResult.Empty); }
public void ValidateTitle() { string fieldName = "Title"; RuleFor(c => c.CategoryTitle) .NotNull().WithMessage( ErrorMessageGenerator.Generate(fieldName, ValidationErrors.CannotBeNull)); }
public bool CheckAddress(AddressModel addressModel) { AddressValidator validator = new AddressValidator(); var result = validator.Validate(addressModel); if (!result.IsValid) { AddressMessage = ErrorMessageGenerator.ComposeErrorMessage(result); return(false); } return(true); }
public ValidateDataAnnotationsServiceBehavior() { var validators = new List <IObjectValidator> { new NullCheckObjectValidator(), new DataAnnotationsObjectValidator(), new ValidatableObjectValidator() }; var errorMessageGenerator = new ErrorMessageGenerator(); _validatingParameterInspector = new ValidatingParameterInspector(validators, errorMessageGenerator); }
public async Task ReturnAllFailureOnBadResult() { var err = new ErrorMessageGenerator().GenerateError(HttpStatusCode.BadRequest, Error); var expected = new Dictionary<string, Result> { { "1", AzureMachineLearningResult.Build(err) }, { "2", AzureMachineLearningResult.Build(err) }, { "3", AzureMachineLearningResult.Build(err) }, { "4", AzureMachineLearningResult.Build(err) } }; var sut = SentimentAnalysisTestHelper.BuildSut(SentimentAnalysisTestHelper.GetErrorMessage(Error)); var result = await sut.GetBatchSentimentAsync(_input); CollectionAssert.AreEqual(expected, result.ToList()); }
/// <summary> /// Checks to make sure that the flow rate of the overall streams match /// </summary> /// <returns></returns> protected virtual ValidationResult CheckOverallFlowRate() { //variables used to store incoming and outgoing flow rates. StreamComponent incomingFlow = TallyOverallFlowRate(target.IncomingStreams); StreamComponent outogingFlow = TallyOverallFlowRate(target.OutgoingStreams); //if they're equal then we're good, otherwise return an error if (incomingFlow.CompareTo(outogingFlow) == 0) { return(ValidationResult.Empty); } else { string message = ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Overall_Flowrate_Mismatch); return(new ValidationResult(target.OutgoingStreams, message)); } }
public bool CheckRegister(RegisterModel registerModel) { if (registerModel == null) { return(false); } RegisterModelValidator validator = new RegisterModelValidator(); var result = validator.Validate(registerModel); if (!result.IsValid) { InvalidRegisterMessage = ErrorMessageGenerator.ComposeErrorMessage(result); return(false); } return(true); }
public bool CheckUpdatedUser(UserModel userModel, UserProfileEntity userProfileEntity) { userModel.Age = AgeCalculator.GetDifferenceInYears(userModel.Birthday, DateTime.Now); var userHandler = new UserHandler(); var userEntity = userHandler.Get(userProfileEntity.UserId); if (!userEntity.CompletedRequest || userEntity.Entity == null) { return(false); } if (NoChanges(userModel, userProfileEntity, userEntity.Entity)) { InvalidInfoMessage = MessageConstants.NoChangesMade; return(false); } var validator = new UpdatedUserValidator(); ValidationResult result = validator.Validate(userModel); if (!result.IsValid) { InvalidInfoMessage = ErrorMessageGenerator.ComposeErrorMessage(result); return(false); } if (userModel.Email != userEntity.Entity.UserEmail && userHandler.CheckExistingEmail(userModel.Email)) { InvalidInfoMessage = MessageConstants.ExistingEmailMessage; return(false); } if (userModel.UserName != userEntity.Entity.UserUsername && userHandler.CheckExistingUsername(userModel.UserName)) { InvalidInfoMessage = MessageConstants.ExistingUsernameMessage; return(false); } return(true); }
/// <summary> /// Checks to make sure that each compound quantity is conserved /// </summary> /// <returns></returns> protected virtual ValidationResult CheckCompoundFlowRate() { //holds the components that aren't equal List <string> unequalComponents = new List <string>(); foreach (string key in incomingCompounds.Keys) { if (incomingCompounds[key].CompareTo(outgoingCompounds[key]) != 0) { unequalComponents.Add(key); } } //if the number of unequal compounds is anything greater than zero, then we have a //problem if (unequalComponents.Count != 0) { string message = ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Individual_Flowrate_Mismatch); //this should hit both incoming and outgoing streams, so we need to create a new //list that merges the two streams List <AbstractStream> mergedList = new List <AbstractStream>( target.IncomingStreamCount + target.OutgoingStreamCount); foreach (AbstractStream stream in target.IncomingStreams) { mergedList.Add(stream); } foreach (AbstractStream stream in target.OutgoingStreams) { mergedList.Add(stream); } //with the lists merged, we can now return the correct result return(new ValidationResult(mergedList, message)); } //if we've gotten this far, then we must be good to go return(ValidationResult.Empty); }
ValidationResult percentUsage() { int i = 0; while (i < equation.Count) { IEquationToken token = equation[i]; if (token is VariableToken) { ChemicalStreamData data; try { DictionaryOfTableData.TryGetValue(token.Value, out data); if (new UnitsFormatter().ConvertFromIntToString(data.Units) == "%") { if (i + 4 < equation.Count) { if (!(equation[i + 1].Value == "/" && equation[i + 2].Value == "100" && equation[i + 3].Value == "*" && DictionaryOfTableData.ContainsKey(equation[i + 4].Value))) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Incorrect_Use_Of_Percent))); } } else { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Incorrect_Use_Of_Percent))); } } } catch { //it is a number so dont do anything } } i++; } return(ValidationResult.Empty); }
/// <summary> /// This function sets what should be in the feedback window as well as setting the corrosponding object in either the equation textbox or /// </summary> /// <param name="messages"></param> public void updateFeedbackWindow(Dictionary <object, List <string> > messages) { //Set the SelectedFeedback to null since we will removing everything. SelectedFeedback = null; //We need to remove the old feedback stuff since we will add the "new" feedback later foreach (Feedback fb in listOfFeedback) { FeedBackStackPanel.Children.Remove(fb.TextBlock); ApplyFeedback(changeFeedback.RemoveFeedback, fb.Target); } listOfFeedback.Clear(); FeedBackStackPanel.Children.Clear(); if (messages != null && messages.Count != 0) { foreach (object key in messages.Keys) { //sometimes, the key can be a list of objects. In this scenario, we just pass the list AttachFeedbackMessage(key, String.Join("\n", messages[key].ToArray())); } string checkMessage = messages.Values.First <List <string> >()[0]; while (checkMessage[0] != '-') { checkMessage = checkMessage.Remove(0, 1); } checkMessage = checkMessage.Remove(0, 1); if (checkMessage.Trim() == ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Solvable).Trim()) { FeedbackStatusChanged(FeedbackStatus.NoErrors); } else { FeedbackStatusChanged(FeedbackStatus.Errors); } } }
ValidationResult NameValidation() { List <string> invalidNames = new List <string>(); foreach (string s in variableNames) { if (!DictionaryOfTableData.ContainsKey(s)) { //so not in our dictionary and not a number so not valid invalidNames.Add(s); } } if (invalidNames.Count > 0) { return(new ValidationResult(equation, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Equation_Variable_Not_In_Tables, invalidNames.ToArray()))); } else { return(ValidationResult.Empty); } }
/// <summary> /// Checks to make sure that everything leaving a process unit also enters that /// process unit. /// </summary> /// <returns></returns> protected ValidationResult CheckOutgoingCompoundBalance() { //make sure that we have the same amount and types of compounds List <string> missingIncomingCompounds = new List <string>(); //check outgoing list against the incoming list for holes foreach (string key in outgoingCompounds.Keys) { if (!incomingCompounds.ContainsKey(key)) { missingIncomingCompounds.Add(key); } } //if the count is greater than one, then we have a problem if (missingIncomingCompounds.Count > 0) { string message = ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Missing_Outgoing_Compounds, missingIncomingCompounds.ToArray()); return(new ValidationResult(target.OutgoingStreams, message)); } //otherwise, we're in the clear return(ValidationResult.Empty); }
/// <summary> /// This is called when we want to check the tables validity. Then it calls buildFeedbackMessage so that, /// a a new EveryoneDict can be made with the new data. /// </summary> /// <param name="tables">This is a list of PropertiesWindow to be checked typically all of them</param> private void CheckChemicalStreamPropertiesWindowFeedback(IEnumerable <IPfdElement> tables) { IRule rule = new TableRule(); List <string> nonUniqueNames = new List <string>(); List <IPropertiesWindow> listOfTables = new List <IPropertiesWindow>(); foreach (IPropertiesWindow table in tables) { rule.Target = table; rule.CheckRule(); // TODO: fix (eventually) throw new NotImplementedException("Rule manager is broken"); ITableAdapter tableAdapter = null; //ITableAdapter tableAdapter = TableAdapterFactory.CreateTableAdapter(table); int i = 0; int items = tableAdapter.GetRowCount(); TableType tableType; string label, units, quantity, compound, temp; while (i < items) { tableType = tableAdapter.GetTableType(); label = tableAdapter.GetLabelAtRow(i); units = tableAdapter.GetUnitAtRow(i); quantity = tableAdapter.GetQuantityAtRow(i); compound = tableAdapter.GetCompoundAtRow(i); if (currentDifficultySetting == OptionDifficultySetting.MaterialAndEnergyBalance) { temp = tableAdapter.GetTemperature(); } else { //we dont need temp to just zero it out temp = "0"; } if (!tableDict.Keys.Contains(label)) { tableDict.Add(label, new GenericTableData(table, tableType, label, units, quantity, compound, temp)); } else { if (!nonUniqueNames.Contains(label)) { nonUniqueNames.Add(label); } listOfTables.Add(table); } i++; } foreach (ValidationResult vr in rule.ValidationResults) { if (!EveryoneDict.ContainsKey(vr.Target)) { EveryoneDict.Add(vr.Target, new List <string>()); } EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n"); ruleNumber++; } } if (nonUniqueNames.Count > 0) { ValidationResult vr = (new ValidationResult(listOfTables, ErrorMessageGenerator.GenerateMesssage(Validation.ErrorMessages.NonUniqueNames, nonUniqueNames.ToArray()))); if (!EveryoneDict.ContainsKey(vr.Target)) { EveryoneDict.Add(vr.Target, new List <string>()); } EveryoneDict[vr.Target].Add("[" + ruleNumber + "]\n-" + vr.Message + "\n"); ruleNumber++; } }
private void Start() { WindowList = new List <MessengerWindow>(); generator = new ErrorMessageGenerator(pathToErrorMessages); }
protected ValidationResult sumOfPartsEqualsTotalQuantity(ITableAdapter tableAdapter) { float overalQuantity; if (tableAdapter.GetRowCount() == 1) { //Only one row so it must be true; return(ValidationResult.Empty); } //? is wildcard for percent here cheating a little if (tableAdapter.GetUnitAtRow(0) == "?") { //using percents so the sum must at up to 100 (100%) overalQuantity = 100; } else { try { overalQuantity = float.Parse(tableAdapter.GetQuantityAtRow(0)); } catch { //Not a number and the only thing the table accepts that isn't a number is ? //since we do not know the total we cannot see if the sum equals the total so assume true return(ValidationResult.Empty); } //So didn't return so overalQuantity must be equal to the overal Quantity } //at this point overalQuantity could equal 100 or the overal Quantity but we dont care the sume of the parts must //equal whatever number it is. bool gotQuestionMark = false; float sumPartsQuantity = 0; int i = 1; //the adapter gets rid of the extra row while (i < tableAdapter.GetRowCount()) { try { sumPartsQuantity += float.Parse(tableAdapter.GetQuantityAtRow(i)); } catch { //the only thing that would make the parse fail is a questionMark gotQuestionMark = true; } i++; } //Fails if either the sum is gerater than the overal or if sum does not equal overal and questionMark was not found if ((sumPartsQuantity > overalQuantity) || (gotQuestionMark == false && sumPartsQuantity != overalQuantity)) { return(new ValidationResult(table, ErrorMessageGenerator.GenerateMesssage(ErrorMessages.Sum_Does_Not_Equal_Total_Quantity))); } return(ValidationResult.Empty); }
public void Setup() { _errorMessageGenerator = new ErrorMessageGenerator(); }