当前位置: 首页>>代码示例>>C#>>正文


C# ValidationResult类代码示例

本文整理汇总了C#中ValidationResult的典型用法代码示例。如果您正苦于以下问题:C# ValidationResult类的具体用法?C# ValidationResult怎么用?C# ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ValidationResult类属于命名空间,在下文中一共展示了ValidationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShipFit

        internal IValidationResult ShipFit(ShipFit shipFit)
        {
            IValidationResult validationResult = new ValidationResult();

            // Check that the ship fit has a valid account id.
            if (shipFit.AccountId < 0 || shipFit.AccountId > int.MaxValue)
            {
                validationResult.AddError("AccountId.Range_" + shipFit.ShipFitId.ToString(), "AccountId can not be less than or equal to 0. Also, the upper limit cannot exceed the max value of the int data type.");
            }

            // Null checks.
            if (shipFit.Notes == null)
            {
                validationResult.AddError("Notes.Null", "Notes cannot be null.");
            }

            if (shipFit.Name == null)
            {
                validationResult.AddError("Name.Null", "Name cannot be null.");
            }

            if (shipFit.Role == null)
            {
                validationResult.AddError("Role.Null", "Role cannot be null.");
            }

            return validationResult;
        }
开发者ID:BraveNewbies,项目名称:doctrine-contracts,代码行数:28,代码来源:ShipFitCheck.cs

示例2: When_passed_multiple_errors_Should_aggregate_the_error_messages

 public void When_passed_multiple_errors_Should_aggregate_the_error_messages()
 {
     var result = new ValidationResult();
     result.AddError<object>(o => o.GetType(), "foo");
     result.AddError<object>(o => o.GetType(), "bar");
     result.GetAllErrors().Count.ShouldEqual(1);
 }
开发者ID:shawnewallace,项目名称:Griz,代码行数:7,代码来源:ValidationResultTester.cs

示例3: Passing_filled_broken_rules_should_create_invalid_instance

        public void Passing_filled_broken_rules_should_create_invalid_instance()
        {
            var result = new ValidationResult(new List<BrokenRule> { new BrokenRule(null, null, "", "", null) });

            Assert.That(result.IsValid, Is.False);
            Assert.That(result.BrokenRules.Count, Is.EqualTo(1));
        }
开发者ID:modulexcite,项目名称:nValid,代码行数:7,代码来源:ValidationResultTests.cs

示例4: ApiKey

        internal IValidationResult ApiKey(IEveDataApiKey apiKeyInfo)
        {
            IValidationResult validationResult = new ValidationResult();

            // Define the bitwise masks for both character and corporation api keys.
            const int charContractMask = 67108864;
            const int corpContractMask = 8388608;
            int checkResult = 0;

            // Perform a bitwise AND to determine if contract access is available on the api key.
            if (apiKeyInfo.Type == EveDataApiKeyType.Character || apiKeyInfo.Type == EveDataApiKeyType.Account)
            {
                checkResult = apiKeyInfo.AccessMask & charContractMask;

                if (checkResult == 0)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A character api key must have 'Contracts' access enabled.");
                }
            }
            else if (apiKeyInfo.Type == EveDataApiKeyType.Corporation)
            {
                checkResult = apiKeyInfo.AccessMask & corpContractMask;

                if (checkResult == 0)
                {
                    validationResult.AddError("ApiKey.AccessMask", "A corporation api key must have 'Contracts' access enabled.");
                }
            }

            return validationResult;
        }
开发者ID:jameswlong,项目名称:doctrineships,代码行数:31,代码来源:SalesAgentCheck.cs

示例5: Interpret

 public static ValidationResult Interpret(
     this IEnumerable<IInterpreter> interpreters,
     string validationGroup,
     Exception exception
     )
 {
     if (null == interpreters)
         return null;
     if (null == exception)
         throw new ArgumentNullException("exception");
     var r = new ValidationResult()
     {
         Exception = exception,
         Message = exception.Message,
         ValidationGroup = validationGroup
     };
     foreach (var i in interpreters)
     {
         if (null == i)
             continue;
         XElement furtherInformation = null;
         string updatedMessage = String.Empty;
         if (
             i.Interpret(exception, out furtherInformation, ref updatedMessage) == InterpretationStatus.Interpreted
             )
         {
             r.FurtherInformation = furtherInformation;
             if(false == String.IsNullOrWhiteSpace(updatedMessage))
                 r.Message = updatedMessage;
             return r;
         }
     }
     return r;
 }
开发者ID:BarbaraHarris,项目名称:xcricap-validator,代码行数:34,代码来源:IEnumerableInterpreterExtensionMethods.cs

示例6: Evaluate

        /// <summary>
        /// Evaluates the rule for the given request.  The <b>RegexRule</b> applies its
        /// regular expression pattern to its specified field in the given request.
        /// </summary>
        /// <param name="request">The <b>MvcRequest</b> to evaluate the rule for.</param>
        /// <returns>A <b>ValidationResult</b> indicating the result of evaluating the
        ///			rule and any validation errors that occurred.</returns>
        public override ValidationResult Evaluate(
            MvcRequest request)
        {
            ValidationResult result = new ValidationResult {
                Passed = false
            };

            string fieldVal = request[Field.EvaluatePropertyValue()];
            // TODO: what if fieldVal is null??  is it valid or not??

            //  if the field value is null and the check is not explicitly for null,
            //  add the error
            if (fieldVal == null) {
                if (this.Pattern == NULL_PATTERN) {
                    result.Passed = true;
                } else {
                    result.AddError(Field, ErrorId);
                }
            } else {
                bool passed = Regex.IsMatch(fieldVal, this.Pattern);

                if (passed) {
                    result.Passed = true;
                } else {
                    result.AddError(Field, ErrorId);
                }
            }

            return result;
        }
开发者ID:rogue-bit,项目名称:Triton-Framework,代码行数:37,代码来源:RegexRule.cs

示例7: ConvertToContractRequiresFix

 public ConvertToContractRequiresFix(ValidationResult currentStatement, ValidatedContractBlock validatedContractBlock)
     : base(currentStatement, validatedContractBlock)
 {
     // TODO: refactoring required!! Not clear logic
     _precondition =
         ContractsEx.Assertions.ContractStatementFactory.TryCreatePrecondition(currentStatement.Statement);
 }
开发者ID:remyblok,项目名称:ReSharperContractExtensions,代码行数:7,代码来源:MalformedContractFix.cs

示例8: Validate

        public IValidationResult[] Validate()
        {
            ValidationResult result = new ValidationResult("inlineBinaryContent");

            result.Passed = true;
            if (iCalendar != null)
            {                
                foreach (UniqueComponent uc in iCalendar.UniqueComponents)
                {
                    if (uc.Attach != null)
                    {
                        foreach (Binary b in uc.Attach)
                        {
                            // Inline binary content (i.e. BASE64-encoded attachments) are not
                            // recommended, and should only be used when absolutely necessary.
                            if (string.Equals(b.Encoding, "BASE64", StringComparison.InvariantCultureIgnoreCase))
                            {
                                result.Passed = false;
                                result.Errors = new IValidationError[]
                                { 
                                    new ValidationErrorWithLookup("inlineBinaryContentError", ValidationErrorType.Warning, false)
                                };
                            }
                        }

                        if (result.Passed != null)
                            break;
                    }                    
                }
            }

            return new IValidationResult[] { result };
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:33,代码来源:InlineBinaryContentValidator.cs

示例9: Can_construct_get_and_set_ErrorMessage

 public static void Can_construct_get_and_set_ErrorMessage()
 {
     var validationResult = new ValidationResult("SomeErrorMessage");
     Assert.Equal("SomeErrorMessage", validationResult.ErrorMessage);
     validationResult.ErrorMessage = "SomeOtherErrorMessage";
     Assert.Equal("SomeOtherErrorMessage", validationResult.ErrorMessage);
 }
开发者ID:geoffkizer,项目名称:corefx,代码行数:7,代码来源:ValidationResultTests.cs

示例10: Run

        public IValidationResult Run(MappingSet set)
        {
            IValidationResult result = new ValidationResult(this);

            DatabaseProcessor proc = new DatabaseProcessor();
            var mergeResults = proc.MergeDatabases(_realDatabase, set.Database);

            if (mergeResults.AnyChanges)
            {
                foreach (TableAdditionOperation tableOp in mergeResults.TableOperations.OfType<TableAdditionOperation>())
                {
                    // Additions show things that are in the generated database schema and not in the real one.
                    result.Issues.Add(new ValidationIssue("Table exists in your NHibernate mapping files but not in your database",
                                                          tableOp.Object, ValidationErrorLevel.Warning));
                }

                foreach (ColumnAdditionOperation columnOp in mergeResults.ColumnOperations.OfType<ColumnAdditionOperation>())
                {
                    result.Issues.Add(new ValidationIssue("Column exists in your NHibernate mapping files but not in your database",
                                                          columnOp.Object, ValidationErrorLevel.Warning));
                }
            }

            return result;
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:25,代码来源:CheckSchemaAgainstRealDatabaseRule.cs

示例11: ValidationResult_HasValid_Defaults

        public void ValidationResult_HasValid_Defaults()
        {
            var result = new ValidationResult();

            Assert.IsTrue(result.IsSuccessful);
            Assert.IsNotNull(result.Failures);
        }
开发者ID:bashwork,项目名称:common,代码行数:7,代码来源:ValidationResultTests.cs

示例12: ValidationResult_Ctors

        public void ValidationResult_Ctors() {
            ValidationResult result = new ValidationResult(null);
            Assert.IsNull(result.ErrorMessage);
            Assert.IsTrue(!result.MemberNames.Any());

            result = new ValidationResult(string.Empty);
            Assert.AreEqual(string.Empty, result.ErrorMessage);
            Assert.IsTrue(!result.MemberNames.Any());

            result = new ValidationResult("stuff");
            Assert.AreEqual("stuff", result.ErrorMessage);
            Assert.IsTrue(!result.MemberNames.Any());

            result = new ValidationResult("stuff", new string[] { "m1", "m2" });
            Assert.AreEqual("stuff", result.ErrorMessage);
            IEnumerable<string> memberNames = result.MemberNames;
            Assert.AreEqual(2, memberNames.Count());
            Assert.IsTrue(memberNames.Contains("m1"));
            Assert.IsTrue(memberNames.Contains("m2"));

#if !SILVERLIGHT
            ValidationResult original = new ValidationResult("error", new string[] { "a", "b" });
            result = new DerivedValidationResult(original);
            Assert.AreEqual("error", result.ErrorMessage);
            CollectionAssert.AreEquivalent(new string[] { "a", "b" }, result.MemberNames.ToList());

            ExceptionHelper.ExpectArgumentNullException(delegate() {
                new DerivedValidationResult(null);
            }, "validationResult");
#endif
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:31,代码来源:ValidationResultTest.cs

示例13: ContainsEqualValidationResult

        /// <summary>
        /// Determines whether the collection contains an equivalent ValidationResult
        /// </summary>
        /// <param name="collection">ValidationResults to search through</param>
        /// <param name="target">ValidationResult to search for</param>
        /// <returns></returns>
        public static bool ContainsEqualValidationResult(this ICollection<ValidationResult> collection, ValidationResult target)
        {
            foreach (ValidationResult oldValidationResult in collection)
            {
                if (oldValidationResult.ErrorMessage == target.ErrorMessage)
                {
                    bool movedOld = true;
                    bool movedTarget = true;
                    IEnumerator<string> oldEnumerator = oldValidationResult.MemberNames.GetEnumerator();
                    IEnumerator<string> targetEnumerator = target.MemberNames.GetEnumerator();
                    while (movedOld && movedTarget)
                    {
                        movedOld = oldEnumerator.MoveNext();
                        movedTarget = targetEnumerator.MoveNext();

                        if (!movedOld && !movedTarget)
                        {
                            return true;
                        }
                        if (movedOld != movedTarget || oldEnumerator.Current != targetEnumerator.Current)
                        {
                            break;
                        }
                    }
                }
            }
            return false;
        }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:34,代码来源:ValidationUtil.cs

示例14: AddIfNew

 /// <summary>
 /// Adds a new ValidationResult to the collection if an equivalent does not exist.
 /// </summary>
 /// <param name="collection">ValidationResults to search through</param>
 /// <param name="value">ValidationResult to add</param>
 public static void AddIfNew(this ICollection<ValidationResult> collection, ValidationResult value)
 {
     if (!collection.ContainsEqualValidationResult(value))
     {
         collection.Add(value);
     }
 }
开发者ID:kvervo,项目名称:HorizontalLoopingSelector,代码行数:12,代码来源:ValidationUtil.cs

示例15: ShowResult

        public void ShowResult(IValidationResult Result)
        {
            if (Result == null)
                Result = new ValidationResult();

            int c = 0;

            c = Result.Count(r => r.FromRule is IcDphValidator); SetCount(lblpIcDph, c);
            c = Result.Count(r => r.FromRule is KvKindValidator); SetCount(lblpDruh, c);
            c = Result.Count(r => r.FromRule is PeriodValidator || r.FromRule is YearValidator); SetCount(lblpObdobie, c);
            c = Result.Count(r => r.FromRule is NameValidator); SetCount(lblpNazov, c);
            c = Result.Count(r => r.FromRule is StateValidator); SetCount(lblpStat, c);
            c = Result.Count(r => r.FromRule is CityValidator); SetCount(lblpObec, c);
            c = Result.Count(r => r.FromRule is BlackListValidator); SetCount(lblpBlacklist, c);
            c = Result.Count(r => r.FromRule is TaxPayerValidator); SetCount(lblpTaxpayers, c);
            c = Result.Count(r => r.FromRule is CorrectionValidator); SetCount(lblpKodopravy, c);
            c = Result.Count(r => r.FromRule is GoodsValidator); SetCount(lblpTovary, c);
            c = Result.Count(r => r.FromRule is TaxRateValidator || r.FromRule is ItemTaxValidator); SetCount(lblpTaxes, c);
            c = Result.Count(r => r.ProblemObject is A1); SetCount(lblpA1, c);
            c = Result.Count(r => r.ProblemObject is A2); SetCount(lblpA2, c);
            c = Result.Count(r => r.ProblemObject is B1); SetCount(lblpB1, c);
            c = Result.Count(r => r.ProblemObject is B2); SetCount(lblpB2, c);
            c = Result.Count(r => r.ProblemObject is B3); SetCount(lblpB3, c);
            c = Result.Count(r => r.ProblemObject is C1); SetCount(lblpC1, c);
            c = Result.Count(r => r.ProblemObject is C2); SetCount(lblpC2, c);
            c = Result.Count(r => r.ProblemObject is D1); SetCount(lblpD1, c);
            c = Result.Count(r => r.ProblemObject is D2); SetCount(lblpD2, c);
        }
开发者ID:mkoscak,项目名称:kv-validator,代码行数:28,代码来源:CtrlValidationResult.cs


注:本文中的ValidationResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。