Beispiel #1
0
        /// <summary>
        /// Read requested bytes from response stream. The implementation will block until all requested bytes readed from source stream, or <see cref="TimeoutException"/> will be thrown.
        /// </summary>
        /// <param name="buffer">An array of type Byte that is the location in memory to store data read from the NetworkStream.</param>
        /// <param name="length">Number of bytes to be read from the source stream.</param>
        /// <exception cref="TimeoutException">Thrown when the time allotted for data read operation has expired.</exception>
        public override int ReadBytes(byte[] buffer, int length)
        {
            ArgumentAssert.IsNotNull(buffer, "buffer");
            ArgumentAssert.IsGreaterThan(length, 0, "length");

            NetworkReadState state = new NetworkReadState();

            state.DataStream = Stream;
            state.BytesLeft  = length;
            _resetEvent      = new ManualResetEvent(false);

            while (state.BytesLeft > 0)
            {
                _resetEvent.Reset();
                Stream.BeginRead(buffer, length - state.BytesLeft, state.BytesLeft, ReadDataCallback, state);

                WaitForNetworkData();

                if (state.Exception != null)
                {
                    throw state.Exception;
                }
            }
            return(length);
        }
        public void IsGreaterThanTestDouble()
        {
            string argumentName = string.Empty;
            // correct
            double value = 1;

            try
            {
                ArgumentAssert.IsGreaterThan(value, 0, argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect
            value = 2;
            try
            {
                ArgumentAssert.IsGreaterThan(value, 3, argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }
        public void IsGreaterThanTestDateTime()
        {
            string argumentName = string.Empty;
            // correct
            DateTime value = new DateTime(2000, 1, 1);

            try
            {
                ArgumentAssert.IsGreaterThan(value, new DateTime(1999, 1, 1), argumentName);
            }
            catch (Exception ex)
            {
                Assert.Fail("Assert method must throw no exceptions.\n" + ex.Message);
            }
            // incorrect
            value = new DateTime(2000, 1, 1);
            try
            {
                ArgumentAssert.IsGreaterThan(value, new DateTime(2001, 1, 1), argumentName);
                Assert.Fail("Assert method must throw ArgumentOutOfRangeException exception.");
            }
            catch (ArgumentOutOfRangeException)
            {
                // test passed
            }
        }
 /// <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");
 }