Пример #1
0
 public static void AreNotEqual(double notExpected, double actual, double delta, string message, params object[] parameters)
 {
     if (Math.Abs(notExpected - actual) > delta)
     {
         return;
     }
     Assert.HandleFail("Assert.AreNotEqual", (string)FrameworkMessages.AreNotEqualDeltaFailMsg(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message), (object)notExpected.ToString((IFormatProvider)CultureInfo.CurrentCulture.NumberFormat), (object)actual.ToString((IFormatProvider)CultureInfo.CurrentCulture.NumberFormat), (object)delta.ToString((IFormatProvider)CultureInfo.CurrentCulture.NumberFormat)), parameters);
 }
Пример #2
0
 internal static void CheckParameterNotNull(object param, string assertionName, string parameterName, string message, params object[] parameters)
 {
     if (param != null)
     {
         return;
     }
     Assert.HandleFail(assertionName, (string)FrameworkMessages.NullParameterToAssert((object)parameterName, (object)message), parameters);
 }
Пример #3
0
 public static void AreNotEqual <T>(T notExpected, T actual, string message, params object[] parameters)
 {
     if (!object.Equals((object)notExpected, (object)actual))
     {
         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);
 }
Пример #4
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);
 }
Пример #5
0
        public static void Inconclusive(string message, params object[] parameters)
        {
            string str = string.Empty;

            if (!string.IsNullOrEmpty(message))
            {
                str = parameters != null?string.Format((IFormatProvider)CultureInfo.CurrentCulture, Assert.ReplaceNulls((object)message), parameters) : Assert.ReplaceNulls((object)message);
            }
            throw new AssertInconclusiveException(FrameworkMessages.AssertionFailed((object)"Assert.Inconclusive", (object)str));
        }
 /// <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 (0 > value.IndexOf(substring, StringComparison.Ordinal))
     {
         string finalMessage = 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);
     }
 }
        /// <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 = FrameworkMessages.IsNotMatchFail(value, pattern, message);
                Assert.HandleFail("StringAssert.DoesNotMatch", finalMessage, parameters);
            }
        }
Пример #9
0
 public static void IsNotInstanceOfType(object value, Type wrongType, string message, params object[] parameters)
 {
     if (wrongType == (Type)null)
     {
         Assert.HandleFail("Assert.IsNotInstanceOfType", message, parameters);
     }
     if (value == null || !wrongType.IsInstanceOfType(value))
     {
         return;
     }
     Assert.HandleFail("Assert.IsNotInstanceOfType", (string)FrameworkMessages.IsNotInstanceOfFailMsg(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message), (object)wrongType.ToString(), (object)value.GetType().ToString()), parameters);
 }
Пример #10
0
        private T GetProperty <T>(string name) where T : class
        {
            object obj = this.Properties[(object)name];

            if (obj != null && !(obj is T))
            {
                throw new InvalidCastException((string)FrameworkMessages.InvalidPropertyType((object)name, (object)obj.GetType(), (object)typeof(T)));
            }
            else
            {
                return((T)obj);
            }
        }
Пример #11
0
        internal static void HandleFail(string assertionName, string message, params object[] parameters)
        {
            string str = string.Empty;

            if (!string.IsNullOrEmpty(message))
            {
                str = parameters != null?string.Format((IFormatProvider)CultureInfo.CurrentCulture, Assert.ReplaceNulls((object)message), parameters) : Assert.ReplaceNulls((object)message);
            }
            if (Assert.AssertionFailure != null)
            {
                Assert.AssertionFailure((object)null, EventArgs.Empty);
            }
            throw new AssertFailedException(FrameworkMessages.AssertionFailed((object)assertionName, (object)str));
        }
Пример #12
0
        public static void AreSame(object expected, object actual, string message, params object[] parameters)
        {
            if (object.ReferenceEquals(expected, actual))
            {
                return;
            }
            string message1 = message;

            if (expected is ValueType && actual is ValueType)
            {
                message1 = (string)FrameworkMessages.AreSameGivenValues(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message));
            }
            Assert.HandleFail("Assert.AreSame", message1, parameters);
        }
Пример #13
0
 public static void AreEqual <T>(T expected, T actual, string message, params object[] parameters)
 {
     if (object.Equals((object)expected, (object)actual))
     {
         return;
     }
     Assert.HandleFail("Assert.AreEqual", (object)actual == null || (object)expected == null || actual.GetType().Equals(expected.GetType()) ? (string)FrameworkMessages.AreEqualFailMsg(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message), (object)Assert.ReplaceNulls((object)expected), (object)Assert.ReplaceNulls((object)actual)) : (string)FrameworkMessages.AreEqualDifferentTypesFailMsg(message == null ? (object)string.Empty : (object)Assert.ReplaceNulls((object)message), (object)Assert.ReplaceNulls((object)expected), (object)expected.GetType().FullName, (object)Assert.ReplaceNulls((object)actual), (object)actual.GetType().FullName), parameters);
 }