public void IsDefinedInEnumTest()
        {
            string argumentName = string.Empty;
            Type   enumType     = typeof(DayOfWeek);
            object value        = DayOfWeek.Friday;

            try
            {
                ArgumentAssert.IsDefinedInEnum(enumType, value, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect
            value = 128;
            try
            {
                ArgumentAssert.IsDefinedInEnum(enumType, value, argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (InvalidEnumArgumentException)
            {
                // test passed
            }
        }
 public BinaryFormatterFactory(BinaryFormatType formatType, Encoding encoding)
 {
     ArgumentAssert.IsDefinedInEnum(typeof(BinaryFormatType), formatType, "formatType");
     ArgumentAssert.IsNotNull(encoding, "encoding");
     _formatType = formatType;
     _encoding   = encoding;
 }
 /// <summary>
 /// Validate all command parameters.
 /// </summary>
 protected override void ValidateParameters()
 {
     ArgumentAssert.IsNotEmpty <string>(Documents, "Documents");
     ArgumentAssert.IsNotEmpty <string>(Keywords, "Keywords");
     ArgumentAssert.IsNotEmpty(Index, "Index");
     ArgumentAssert.IsNotNull(BeforeMatch, "BeforeMatch");
     ArgumentAssert.IsNotNull(AfterMatch, "AfterMatch");
     ArgumentAssert.IsNotNull(SnippetsDelimiter, "SnippetsDelimiter");
     ArgumentAssert.IsGreaterThan(SnippetSizeLimit, 0, "SnippetSizeLimit");
     ArgumentAssert.IsGreaterOrEqual(SnippetsCountLimit, 0, "SnippetsCountLimit");
     ArgumentAssert.IsGreaterOrEqual(WordsAroundKeyword, 0, "WordsAroundKeyword");
     ArgumentAssert.IsGreaterOrEqual(WordsCountLimit, 0, "WordsCountLimit");
     ArgumentAssert.IsDefinedInEnum(typeof(HtmlStripMode), HtmlStripMode, "HtmlStripMode");
     ArgumentAssert.IsDefinedInEnum(typeof(PassageBoundary), PassageBoundary, "PassageBoundary");
     ArgumentAssert.IsDefinedInEnum(typeof(BuildExcerptsOptions), Options, "Options");
 }
Example #4
0
        /// <summary>
        /// Validate parameters
        /// </summary>
        internal void ValidateParameters()
        {
            ArgumentAssert.IsNotNull(Query, "Query");
            ArgumentAssert.IsInRange(Offset, 0, int.MaxValue, "Offset");
            ArgumentAssert.IsInRange(Limit, 1, int.MaxValue, "Limit");
            ArgumentAssert.IsInRange(MaxMatches, 1, int.MaxValue, "MaxMatches");
            ArgumentAssert.IsInRange(Cutoff, 0, int.MaxValue, "Cutoff");
            ArgumentAssert.IsDefinedInEnum(typeof(MatchMode), MatchMode, "MatchMode");
            ArgumentAssert.IsDefinedInEnum(typeof(ResultsSortMode), SortMode, "SortMode");
            ArgumentAssert.IsDefinedInEnum(typeof(MatchRankMode), RankingMode, "RankingMode");
            ArgumentAssert.IsNotNull(SortBy, "SortBy");
            ArgumentAssert.IsInRange(MaxQueryTime, 0, int.MaxValue, "MaxQueryTime");
            ArgumentAssert.IsInRange(RetryCount, 0, int.MaxValue, "RetryCount");
            ArgumentAssert.IsInRange(RetryDelay, 0, int.MaxValue, "RetryDelay");
            if (!String.IsNullOrEmpty(Comment))
            {
                ArgumentAssert.IsLessOrEqual(Comment, MAX_COMMENT_LENGTH, "Comment");
            }

            if (RankingMode == MatchRankMode.Expression && String.IsNullOrEmpty(RankingExpression))
            {
                throw new ArgumentException(String.Format(Messages.Exception_ArgumentRankingExpressionIsEmpty));
            }
            if (SortMode != ResultsSortMode.Relevance && String.IsNullOrEmpty(SortBy))
            {
                throw new ArgumentException(String.Format(Messages.Exception_ArgumentResultsSortModeNotValid, Enum.GetName(typeof(ResultsSortMode), SortMode)));
            }
            if (IdSize == IdSize.Int32)
            {
                ArgumentAssert.IsLessOrEqual(MinDocumentId, int.MaxValue, "MinDocumentId");
                ArgumentAssert.IsLessOrEqual(MaxDocumentId, int.MaxValue, "MaxDocumentId");
            }
            if (MinDocumentId > MaxDocumentId)
            {
                throw new ArgumentException(Messages.Exception_ArgumentMinIdGreaterThanMaxId);
            }
        }