Assertion utility methods that simplify things such as argument checks.

Not intended to be used directly by applications.

Ejemplo n.º 1
0
 public void IsTrueWithMesssage()
 {
     Assert.Throws <ArgumentException>(() => AssertUtils.IsTrue(false, "foo"), "foo");
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Tokenize the given <see cref="System.String"/> into a
        /// <see cref="System.String"/> array.
        /// </summary>
        /// <remarks>
        /// <p>
        /// If <paramref name="s"/> is <see langword="null"/>, returns an empty
        /// <see cref="System.String"/> array.
        /// </p>
        /// <p>
        /// If <paramref name="delimiters"/> is <see langword="null"/> or the empty
        /// <see cref="System.String"/>, returns a <see cref="System.String"/> array with one
        /// element: <paramref name="s"/> itself.
        /// </p>
        /// </remarks>
        /// <param name="s">The <see cref="System.String"/> to tokenize.</param>
        /// <param name="delimiters">
        /// The delimiter characters, assembled as a <see cref="System.String"/>.
        /// </param>
        /// <param name="trimTokens">
        /// Trim the tokens via <see cref="System.String.Trim()"/>.
        /// </param>
        /// <param name="ignoreEmptyTokens">
        /// Omit empty tokens from the result array.
        /// </param>
        /// <param name="quoteChars">
        /// Pairs of quote characters. <paramref name="delimiters"/> within a pair of quotes are ignored
        /// </param>
        /// <returns>An array of the tokens.</returns>
        public static string[] Split(
            string s, string delimiters, bool trimTokens, bool ignoreEmptyTokens, string quoteChars)
        {
            if (s == null)
            {
                return(new string[0]);
            }
            if (delimiters == null || delimiters.Length == 0)
            {
                return(new string[] { s });
            }
            if (quoteChars == null)
            {
                quoteChars = string.Empty;
            }
            AssertUtils.IsTrue(quoteChars.Length % 2 == 0, "the number of quote characters must be even");

            char[] delimiterChars = delimiters.ToCharArray();

            // scan separator positions
            int[] delimiterPositions = new int[s.Length];
            int   count = MakeDelimiterPositionList(s, delimiterChars, quoteChars, delimiterPositions);

            ArrayList tokens     = new ArrayList(count + 1);
            int       startIndex = 0;

            for (int ixSep = 0; ixSep < count; ixSep++)
            {
                string token = s.Substring(startIndex, delimiterPositions[ixSep] - startIndex);
                if (trimTokens)
                {
                    token = token.Trim();
                }
                if (!(ignoreEmptyTokens && token.Length == 0))
                {
                    tokens.Add(token);
                }
                startIndex = delimiterPositions[ixSep] + 1;
            }
            // add remainder
            if (startIndex < s.Length)
            {
                string token = s.Substring(startIndex);
                if (trimTokens)
                {
                    token = token.Trim();
                }
                if (!(ignoreEmptyTokens && token.Length == 0))
                {
                    tokens.Add(token);
                }
            }
            else if (startIndex == s.Length)
            {
                if (!(ignoreEmptyTokens))
                {
                    tokens.Add(string.Empty);
                }
            }

            return((string[])tokens.ToArray(typeof(string)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Returns the element at the specified index using the supplied
 /// <paramref name="enumerable"/>.
 /// </summary>
 /// <param name="enumerable">
 /// The <see cref="System.Collections.IEnumerable"/> to use to enumerate
 /// elements until the supplied <paramref name="index"/> is reached.
 /// </param>
 /// <param name="index">
 /// The index of the element in the enumeration to return.
 /// </param>
 /// <returns>
 /// The element at the specified index using the supplied
 /// <paramref name="enumerable"/>.
 /// </returns>
 /// <exception cref="System.ArgumentOutOfRangeException">
 /// If the supplied <paramref name="index"/> was less than zero, or the
 /// supplied <paramref name="enumerable"/> did not contain enough elements
 /// to be able to reach the supplied <paramref name="index"/>.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="enumerable"/> is <see langword="null"/>.
 /// </exception>
 public static object EnumerateElementAtIndex(IEnumerable enumerable, int index)
 {
     AssertUtils.ArgumentNotNull(enumerable, "enumerable");
     return(EnumerateElementAtIndex(enumerable.GetEnumerator(), index));
 }
Ejemplo n.º 4
0
 public void ArgumentNotNull()
 {
     AssertUtils.ArgumentNotNull(null, "foo");
 }
Ejemplo n.º 5
0
 public void ArgumentHasTextWithValidTextAndMessage()
 {
     AssertUtils.ArgumentHasText("... and no-one's getting fat 'cept Mama Cas!", "foo", "Bang!");
 }
Ejemplo n.º 6
0
 public void IsTrueWithMessageValidExpression()
 {
     AssertUtils.IsTrue(true, "foo");
 }
Ejemplo n.º 7
0
 public void IsTrueValidExpression()
 {
     AssertUtils.IsTrue(true);
 }
Ejemplo n.º 8
0
 public void ArgumentHasTextWithMessage()
 {
     AssertUtils.ArgumentHasText(null, "foo", "Bang!");
 }
Ejemplo n.º 9
0
 public void ArgumentHasLengthArgumentIsNull()
 {
     AssertUtils.ArgumentHasLength(null, "foo");
 }
Ejemplo n.º 10
0
 public void ArgumentHasText()
 {
     Assert.Throws <ArgumentNullException>(() => AssertUtils.ArgumentHasText(null, "foo"));
 }
Ejemplo n.º 11
0
 public void ArgumentHasText()
 {
     AssertUtils.ArgumentHasText(null, "foo");
 }
Ejemplo n.º 12
0
 public void ArgumentNotNullWithMessage()
 {
     Assert.Throws <ArgumentNullException>(() => AssertUtils.ArgumentNotNull(null, "foo", "Bang!"));
 }
Ejemplo n.º 13
0
 public void StateTrue()
 {
     Assert.Throws <InvalidOperationException>(() => AssertUtils.State(false, "foo"));
 }
Ejemplo n.º 14
0
 public void IsTrue()
 {
     Assert.Throws <ArgumentException>(() => AssertUtils.IsTrue(false), "[Assertion failed] - this expression must be true");
 }
Ejemplo n.º 15
0
 public void ArgumentHasElementsArgumentContainsNonNullsOnly()
 {
     AssertUtils.ArgumentHasElements(new object[] { new object(), new object(), new object() }, "foo");
 }
Ejemplo n.º 16
0
 public void ArgumentHasLengthArgumentIsNullWithMessage()
 {
     AssertUtils.ArgumentHasLength(null, "foo", "Bang!");
 }
Ejemplo n.º 17
0
 public void IsTrueWithMesssage()
 {
     AssertUtils.IsTrue(false, "foo");
 }
Ejemplo n.º 18
0
 public void ArgumentHasLengthArgumentIsEmpty()
 {
     AssertUtils.ArgumentHasLength(new byte[0], "foo");
 }
Ejemplo n.º 19
0
 public void IsTrue()
 {
     AssertUtils.IsTrue(false);
 }
Ejemplo n.º 20
0
 public void ArgumentHasLengthArgumentIsEmptyWithMessage()
 {
     AssertUtils.ArgumentHasLength(new byte[0], "foo", "Bang!");
 }
Ejemplo n.º 21
0
 public void StateTrue()
 {
     AssertUtils.State(false, "foo");
 }
Ejemplo n.º 22
0
 public void ArgumentHasLengthArgumentHasElements()
 {
     AssertUtils.ArgumentHasLength(new byte[1], "foo");
 }
Ejemplo n.º 23
0
 public void ArgumentNotNullWithMessage()
 {
     AssertUtils.ArgumentNotNull(null, "foo", "Bang!");
 }
Ejemplo n.º 24
0
 public void ArgumentHasLengthArgumentHasElementsWithMessage()
 {
     AssertUtils.ArgumentHasLength(new byte[1], "foo", "Bang!");
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initialize a new instance of <see cref="UniqueKey"/> from its string representation.
 /// See <see cref="GetInstanceScoped"/> and See <see cref="GetTypeScoped"/> for details.
 /// </summary>
 /// <param name="key">The string representation of the new <see cref="UniqueKey"/> instance.</param>
 internal UniqueKey(string key)
 {
     AssertUtils.ArgumentNotNull(key, "key");
     _generatedKey = key;
 }
Ejemplo n.º 26
0
 public void ArgumentHasElementsArgumentIsNull()
 {
     AssertUtils.ArgumentHasElements(null, "foo");
 }
Ejemplo n.º 27
0
 /// <summary>
 /// Returns the first element in the supplied <paramref name="enumerable"/>.
 /// </summary>
 /// <param name="enumerable">
 /// The <see cref="System.Collections.IEnumerable"/> to use to enumerate
 /// elements.
 /// </param>
 /// <returns>
 /// The first element in the supplied <paramref name="enumerable"/>.
 /// </returns>
 /// <exception cref="System.IndexOutOfRangeException">
 /// If the supplied <paramref name="enumerable"/> did not have any elements.
 /// </exception>
 /// <exception cref="System.ArgumentNullException">
 /// If the supplied <paramref name="enumerable"/> is <see langword="null"/>.
 /// </exception>
 public static object EnumerateFirstElement(IEnumerable enumerable)
 {
     AssertUtils.ArgumentNotNull(enumerable, "enumerable");
     return(ObjectUtils.EnumerateElementAtIndex(enumerable.GetEnumerator(), 0));
 }
Ejemplo n.º 28
0
 public void ArgumentHasElementsArgumentIsEmpty()
 {
     AssertUtils.ArgumentHasElements(new object[0], "foo");
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Gets the qualified name of the given method, consisting of
 /// fully qualified interface/class name + "." method name.
 /// </summary>
 /// <param name="method">The method.</param>
 /// <returns>qualified name of the method.</returns>
 public static string GetQualifiedMethodName(MethodInfo method)
 {
     AssertUtils.ArgumentNotNull(method, "method", "MethodInfo must not be null");
     return(method.DeclaringType.FullName + "." + method.Name);
 }
Ejemplo n.º 30
0
 public void ArgumentHasElementsArgumentContainsNull()
 {
     Assert.Throws <ArgumentException>(() => AssertUtils.ArgumentHasElements(new object[] { new object(), null, new object() }, "foo"));
 }