Пример #1
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);
            }
        }
        public void IsLessOrEqualTestDateTime()
        {
            string argumentName = string.Empty;
            // equal
            DateTime value = new DateTime(2012, 12, 12, 12, 12, 12);

            try
            {
                ArgumentAssert.IsLessOrEqual(value, new DateTime(2012, 12, 12, 12, 12, 12), argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // Less
            value = new DateTime(2011, 11, 11, 11, 11, 11);
            try
            {
                ArgumentAssert.IsLessOrEqual(value, new DateTime(2012, 12, 12, 12, 12, 12), argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect
            value = new DateTime(2011, 1, 1, 0, 0, 0);
            try
            {
                ArgumentAssert.IsLessOrEqual(value, new DateTime(2010, 1, 1, 0, 0, 0), argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }
        public void IsLessOrEqualTestDouble()
        {
            string argumentName = string.Empty;
            // equal
            double value = 0;

            try
            {
                ArgumentAssert.IsLessOrEqual(value, 0, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // Less
            value = 1;
            try
            {
                ArgumentAssert.IsLessOrEqual(value, 2, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect
            value = 2;
            try
            {
                ArgumentAssert.IsLessOrEqual(value, 1, argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }