예제 #1
0
 protected override void ValidateParameters()
 {
     ArgumentAssert.IsNotEmpty <SearchQuery>(QueryList, "QueryList");
     if (MaxQueries > 0)
     {
         ArgumentAssert.IsInRange(QueryList, 1, MaxQueries, "QueryList");
     }
     QueryList.ValidateParameters();
 }
        protected override void WriteBody(IBinaryWriter writer, int maxCount)
        {
            ArgumentAssert.IsInRange(Values.Count, 0, maxCount, "Values.Count");

            writer.Write(Values.Count);
            foreach (T value in Values)
            {
                writer.Write(ConvertToInt64(value));
            }
        }
예제 #3
0
        /// <summary>
        /// Serialize object to stream using specified binary writer.
        /// </summary>
        /// <param name="writer">Binary writer (output formatter) object</param>
        internal void Serialize(IBinaryWriter writer)
        {
            ArgumentAssert.IsInRange(Count, 0, _maxFiltersCount, "Count");

            // filters count
            writer.Write(Count);
            // serialize all filters
            foreach (AttributeFilterBase filter in this)
            {
                filter.Serialize(writer, _maxValuesCount);
            }
        }
        public void Open()
        {
            ArgumentAssert.IsNotEmpty(Host, "Host");
            ArgumentAssert.IsInRange(Port, 1, UInt16.MaxValue, "Port");

            if (Connected)
            {
                Close();
            }
            if (Socket == null)
            {
                Socket = CreateSocket();
            }
            Socket.Connect(Host, Port);
        }
예제 #5
0
        /// <summary>
        /// Reads specified count of bytes from the stream as the byte array and advances the current position by count bytes.
        /// </summary>
        /// <param name="count">The number of bytes to read.</param>
        /// <returns>Array of bytes being read from stream.</returns>
        /// <exception cref="ObjectDisposedException">The stream is closed.</exception>
        /// <exception cref="IOException">An I/O error occurs.</exception>
        /// <exception cref="EndOfStreamException">Could not read specified count of bytes from stream (reading is attempted past the end of a stream).</exception>
        /// <exception cref="ArgumentOutOfRangeException">Count is out of range.</exception>
        public override byte[] ReadBytes(int count)
        {
            ArgumentAssert.IsInRange(count, 0, MAX_LENGTH, "count");
            if (InputStream == null)
            {
                throw new ObjectDisposedException(null, Messages.Exception_IOStreamDisposed);
            }
            byte[] data         = new byte[count];
            int    actuallyRead = InputStream.ReadBytes(data, count);

            if (actuallyRead != count)
            {
                throw new EndOfStreamException(String.Format(Messages.Exception_CouldNotReadFromStream, count, data.Length));
            }
            return(data);
        }
        public void IsInRangeTestDouble()
        {
            string argumentName = string.Empty;
            // close range
            double value = 0;

            try
            {
                ArgumentAssert.IsInRange(value, 0, 0, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // correct range
            value = 1;
            try
            {
                ArgumentAssert.IsInRange(value, 0, 2, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect range
            value = -1;
            try
            {
                ArgumentAssert.IsInRange(value, 0, -1, argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test range
            }
            // out of range
            value = 0;
            try
            {
                ArgumentAssert.IsInRange(value, 1, 2, argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }
        public void IsInRangeTestDateTime()
        {
            string argumentName = string.Empty;
            // close range
            DateTime value = new DateTime(1960, 12, 12, 0, 0, 0);

            try
            {
                ArgumentAssert.IsInRange(value, new DateTime(1960, 12, 12, 0, 0, 0), new DateTime(1960, 12, 12, 0, 0, 0), argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // correct range
            value = new DateTime(2007, 11, 19, 11, 22, 33);
            try
            {
                ArgumentAssert.IsInRange(value, new DateTime(2007, 11, 19, 11, 22, 32), new DateTime(2007, 11, 19, 11, 22, 34), argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect range
            value = new DateTime(2009, 05, 20, 1, 2, 3);
            try
            {
                ArgumentAssert.IsInRange(value, new DateTime(1970, 12, 12, 0, 0, 0), new DateTime(1960, 12, 12, 0, 0, 0), argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test range
            }
            // out of range
            value = new DateTime(2003, 04, 24, 3, 2, 1);
            try
            {
                ArgumentAssert.IsInRange(value, new DateTime(1960, 12, 12, 0, 0, 0), new DateTime(1970, 12, 12, 0, 0, 0), argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }
예제 #8
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);
            }
        }