Ejemplo n.º 1
0
 public static void AreNotEqual(string notExpected, string actual, bool ignoreCase, CultureInfo culture, string message, params object[] parameters)
 {
     Assert.CheckParameterNotNull((object)culture, "Assert.AreNotEqual", "culture", string.Empty, new object[0]);
     if (string.Compare(notExpected, actual, ignoreCase, culture) != 0)
     {
         return;
     }
     Assert.HandleFail("Assert.AreNotEqual", (string)FrameworkMessages.AreNotEqualFailMsg(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message), (object)Assert.ReplaceNulls((object)notExpected), (object)Assert.ReplaceNulls((object)actual)), parameters);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Tests whether the specified string ends with the specified substring
 /// and throws an exception if the test string does not end with the
 /// substring.
 /// </summary>
 /// <param name="value">
 /// The string that is expected to end with <paramref name="substring"/>.
 /// </param>
 /// <param name="substring">
 /// The string expected to be a suffix of <paramref name="value"/>.
 /// </param>
 /// <param name="message">
 /// The message to include in the exception when <paramref name="value"/>
 /// does not end with <paramref name="substring"/>. The message is
 /// shown in test results.
 /// </param>
 /// <param name="comparisonType">
 /// The comparison method to compare strings <paramref name="comparisonType"/>.
 /// </param>
 /// <param name="parameters">
 /// An array of parameters to use when formatting <paramref name="message"/>.
 /// </param>
 /// <exception cref="AssertFailedException">
 /// Thrown if <paramref name="value"/> does not end with
 /// <paramref name="substring"/>.
 /// </exception>
 public static void EndsWith(string value, string substring, string message, StringComparison comparisonType, params object[] parameters)
 {
     Assert.CheckParameterNotNull(value, "StringAssert.EndsWith", "value", string.Empty);
     Assert.CheckParameterNotNull(substring, "StringAssert.EndsWith", "substring", string.Empty);
     if (!value.EndsWith(substring, comparisonType))
     {
         string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.EndsWithFail, value, substring, message);
         Assert.HandleFail("StringAssert.EndsWith", finalMessage, parameters);
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Tests whether the specified string contains the specified substring
 /// and throws an exception if the substring does not occur within the
 /// test string.
 /// </summary>
 /// <param name="value">
 /// The string that is expected to contain <paramref name="substring"/>.
 /// </param>
 /// <param name="substring">
 /// The string expected to occur within <paramref name="value"/>.
 /// </param>
 /// <param name="message">
 /// The message to include in the exception when <paramref name="substring"/>
 /// is not in <paramref name="value"/>. The message is shown in
 /// test results.
 /// </param>
 /// <param name="parameters">
 /// An array of parameters to use when formatting <paramref name="message"/>.
 /// </param>
 /// <exception cref="AssertFailedException">
 /// Thrown if <paramref name="substring"/> is not found in
 /// <paramref name="value"/>.
 /// </exception>
 public static void Contains(string value, string substring, string message, params object[] parameters)
 {
     Assert.CheckParameterNotNull(value, "StringAssert.Contains", "value", string.Empty);
     Assert.CheckParameterNotNull(substring, "StringAssert.Contains", "substring", string.Empty);
     if (value.IndexOf(substring, StringComparison.Ordinal) < 0)
     {
         string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.ContainsFail, value, substring, message);
         Assert.HandleFail("StringAssert.Contains", finalMessage, parameters);
     }
 }
 /// <summary>
 /// Tests whether the specified string ends with the specified substring
 /// and throws an exception if the test string does not end with the
 /// substring.
 /// </summary>
 /// <param name="value">
 /// The string that is expected to end with <paramref name="substring"/>.
 /// </param>
 /// <param name="substring">
 /// The string expected to be a suffix of <paramref name="value"/>.
 /// </param>
 /// <param name="message">
 /// The message to include in the exception when <paramref name="value"/>
 /// does not end with <paramref name="substring"/>. The message is
 /// shown in test results.
 /// </param>
 /// <param name="parameters">
 /// An array of parameters to use when formatting <paramref name="message"/>.
 /// </param>
 /// <exception cref="AssertFailedException">
 /// Thrown if <paramref name="value"/> does not end with
 /// <paramref name="substring"/>.
 /// </exception>
 public static void EndsWith(string value, string substring, string message, params object[] parameters)
 {
     Assert.CheckParameterNotNull(value, "StringAssert.EndsWith", "value", string.Empty);
     Assert.CheckParameterNotNull(substring, "StringAssert.EndsWith", "substring", string.Empty);
     if (!value.EndsWith(substring, StringComparison.Ordinal))
     {
         string finalMessage = FrameworkMessages.EndsWithFail(value, substring, message);
         Assert.HandleFail("StringAssert.EndsWith", finalMessage, parameters);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Tests whether the specified string does not match a regular expression
        /// and throws an exception if the string matches the expression.
        /// </summary>
        /// <param name="value">
        /// The string that is expected not to match <paramref name="pattern"/>.
        /// </param>
        /// <param name="pattern">
        /// The regular expression that <paramref name="value"/> is
        /// expected to not match.
        /// </param>
        /// <param name="message">
        /// The message to include in the exception when <paramref name="value"/>
        /// matches <paramref name="pattern"/>. The message is shown in test
        /// results.
        /// </param>
        /// <param name="parameters">
        /// An array of parameters to use when formatting <paramref name="message"/>.
        /// </param>
        /// <exception cref="AssertFailedException">
        /// Thrown if <paramref name="value"/> matches <paramref name="pattern"/>.
        /// </exception>
        public static void DoesNotMatch(string value, Regex pattern, string message, params object[] parameters)
        {
            Assert.CheckParameterNotNull(value, "StringAssert.DoesNotMatch", "value", string.Empty);
            Assert.CheckParameterNotNull(pattern, "StringAssert.DoesNotMatch", "pattern", string.Empty);

            if (pattern.IsMatch(value))
            {
                string finalMessage = string.Format(CultureInfo.CurrentCulture, FrameworkMessages.IsNotMatchFail, value, pattern, message);
                Assert.HandleFail("StringAssert.DoesNotMatch", finalMessage, parameters);
            }
        }
        /// <summary>
        /// Tests whether the specified string matches a regular expression and
        /// throws an exception if the string does not match the expression.
        /// </summary>
        /// <param name="value">
        /// The string that is expected to match <paramref name="pattern"/>.
        /// </param>
        /// <param name="pattern">
        /// The regular expression that <paramref name="value"/> is
        /// expected to match.
        /// </param>
        /// <param name="message">
        /// The message to include in the exception when <paramref name="value"/>
        /// does not match <paramref name="pattern"/>. The message is shown in
        /// test results.
        /// </param>
        /// <param name="parameters">
        /// An array of parameters to use when formatting <paramref name="message"/>.
        /// </param>
        /// <exception cref="AssertFailedException">
        /// Thrown if <paramref name="value"/> does not match
        /// <paramref name="pattern"/>.
        /// </exception>
        public static void Matches(string value, Regex pattern, string message, params object[] parameters)
        {
            Assert.CheckParameterNotNull(value, "StringAssert.Matches", "value", string.Empty);
            Assert.CheckParameterNotNull(pattern, "StringAssert.Matches", "pattern", string.Empty);

            if (!pattern.IsMatch(value))
            {
                string finalMessage = FrameworkMessages.IsMatchFail(value, pattern, message);
                Assert.HandleFail("StringAssert.Matches", finalMessage, parameters);
            }
        }