public void IsTrueWithMesssage() { Assert.Throws <ArgumentException>(() => AssertUtils.IsTrue(false, "foo"), "foo"); }
/// <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))); }
/// <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)); }
public void ArgumentNotNull() { AssertUtils.ArgumentNotNull(null, "foo"); }
public void ArgumentHasTextWithValidTextAndMessage() { AssertUtils.ArgumentHasText("... and no-one's getting fat 'cept Mama Cas!", "foo", "Bang!"); }
public void IsTrueWithMessageValidExpression() { AssertUtils.IsTrue(true, "foo"); }
public void IsTrueValidExpression() { AssertUtils.IsTrue(true); }
public void ArgumentHasTextWithMessage() { AssertUtils.ArgumentHasText(null, "foo", "Bang!"); }
public void ArgumentHasLengthArgumentIsNull() { AssertUtils.ArgumentHasLength(null, "foo"); }
public void ArgumentHasText() { Assert.Throws <ArgumentNullException>(() => AssertUtils.ArgumentHasText(null, "foo")); }
public void ArgumentHasText() { AssertUtils.ArgumentHasText(null, "foo"); }
public void ArgumentNotNullWithMessage() { Assert.Throws <ArgumentNullException>(() => AssertUtils.ArgumentNotNull(null, "foo", "Bang!")); }
public void StateTrue() { Assert.Throws <InvalidOperationException>(() => AssertUtils.State(false, "foo")); }
public void IsTrue() { Assert.Throws <ArgumentException>(() => AssertUtils.IsTrue(false), "[Assertion failed] - this expression must be true"); }
public void ArgumentHasElementsArgumentContainsNonNullsOnly() { AssertUtils.ArgumentHasElements(new object[] { new object(), new object(), new object() }, "foo"); }
public void ArgumentHasLengthArgumentIsNullWithMessage() { AssertUtils.ArgumentHasLength(null, "foo", "Bang!"); }
public void IsTrueWithMesssage() { AssertUtils.IsTrue(false, "foo"); }
public void ArgumentHasLengthArgumentIsEmpty() { AssertUtils.ArgumentHasLength(new byte[0], "foo"); }
public void IsTrue() { AssertUtils.IsTrue(false); }
public void ArgumentHasLengthArgumentIsEmptyWithMessage() { AssertUtils.ArgumentHasLength(new byte[0], "foo", "Bang!"); }
public void StateTrue() { AssertUtils.State(false, "foo"); }
public void ArgumentHasLengthArgumentHasElements() { AssertUtils.ArgumentHasLength(new byte[1], "foo"); }
public void ArgumentNotNullWithMessage() { AssertUtils.ArgumentNotNull(null, "foo", "Bang!"); }
public void ArgumentHasLengthArgumentHasElementsWithMessage() { AssertUtils.ArgumentHasLength(new byte[1], "foo", "Bang!"); }
/// <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; }
public void ArgumentHasElementsArgumentIsNull() { AssertUtils.ArgumentHasElements(null, "foo"); }
/// <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)); }
public void ArgumentHasElementsArgumentIsEmpty() { AssertUtils.ArgumentHasElements(new object[0], "foo"); }
/// <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); }
public void ArgumentHasElementsArgumentContainsNull() { Assert.Throws <ArgumentException>(() => AssertUtils.ArgumentHasElements(new object[] { new object(), null, new object() }, "foo")); }