Unit Test (单元测试) - .NET - 源码

创建时间:
2015-12-22 15:15
最近更新:
2018-06-18 11:51

Tony Remark - 关于以下 3 个 Assert 类

截至 2017-07-09,发现:

  • .NET 的 单元测试 的 所有的 "Assert 方法" 仅存在于 Microsoft.VisualStudio.TestTools.UnitTesting 命名空间下的 AssertCollectionAssertStringAssert 3 个类中,它们都是静态类。
  • 上述 3 个类中的所有的 "Assert 方法" 的签名统一为 public static void %(%) 形式,这些方法占了这 3 个类 85%、72%、100% 的代码行。
  • 多数 "Assert 方法" 都有 3 个重载,第 2 个重载比第 1 个多了 string message 参数、第 3 个重载比第 2 个多了 params object[] parameters 参数。这两个参数的示例: AreEqual(expected, actual, "expected is {0}, actual is {1}", expected, actual)
  • 所有 "Assert 方法" 都调用了以下 HandleFail()HandleFailure() (仅 Inconclusive() 例外: 直接 throw new AssertInconclusiveException()),从源码可见所有的 "Assert 方法" 均在不符合预设条件时抛出异常。由此推测 ".NET 单元测试框架 的 原理" 为: 所有 "Assert 方法" 均 对入参进行测试 且 在不符合预设条件时抛出异常,该异常由 .NET 单元测试框架 捕获,用于以各种形式来统计、显示测试结果。与此相关: AssertFailedException 类 文中提及 "每当断言失败时会引发它 (This is thrown whenever an assertion fails)"、使用 Assert 类 文中提及 "只要测试失败,就会引发 AssertFailedException 异常。如果测试超时,引发意外的异常,或包含生成了 Failed 结果的 Assert 语句,则该测试失败。"。
  • Assert 类中,仅 Fail()Inconclusive() 不检查任何条件/不做判断。
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
    public static class Assert、CollectionAssert、StringAssert
    {
        ...
        //Line 403:
        internal static void HandleFail(string assertionName, string message, params object[] parameters)
        {
            string completeMessage = Assert.CreateCompleteMessage(message, parameters);
            Assert.HandleFailure(assertionName, completeMessage);
        }
        ...
        //Line 417:
        internal static void HandleFailure(string assertionName, string message)
        {
            if (Assert.AssertionFailure != null)
                Assert.AssertionFailure((object) null, EventArgs.Empty);
            throw new AssertFailedException(FrameworkMessages.AssertionFailed((object) assertionName, (object) message));
        }
        ...
    }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.Assert from JetBrains dotPeek 1.0 at 2017-07-06

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.Assert
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: D:\Download\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  public static class Assert
  {
    internal static EventHandler<EventArgs> AssertionFailure;

    public static void IsTrue(bool condition)
    {
      Assert.IsTrue(condition, string.Empty, (object[]) null);
    }

    public static void IsTrue(bool condition, string message)
    {
      Assert.IsTrue(condition, message, (object[]) null);
    }

    public static void IsTrue(bool condition, string message, params object[] parameters)
    {
      if (condition)
        return;
      Assert.HandleFail("Assert.IsTrue", message, parameters);
    }

    public static void IsFalse(bool condition)
    {
      Assert.IsFalse(condition, string.Empty, (object[]) null);
    }

    public static void IsFalse(bool condition, string message)
    {
      Assert.IsFalse(condition, message, (object[]) null);
    }

    public static void IsFalse(bool condition, string message, params object[] parameters)
    {
      if (!condition)
        return;
      Assert.HandleFail("Assert.IsFalse", message, parameters);
    }

    public static void IsNull(object value)
    {
      Assert.IsNull(value, string.Empty, (object[]) null);
    }

    public static void IsNull(object value, string message)
    {
      Assert.IsNull(value, message, (object[]) null);
    }

    public static void IsNull(object value, string message, params object[] parameters)
    {
      if (value == null)
        return;
      Assert.HandleFail("Assert.IsNull", message, parameters);
    }

    public static void IsNotNull(object value)
    {
      Assert.IsNotNull(value, string.Empty, (object[]) null);
    }

    public static void IsNotNull(object value, string message)
    {
      Assert.IsNotNull(value, message, (object[]) null);
    }

    public static void IsNotNull(object value, string message, params object[] parameters)
    {
      if (value != null)
        return;
      Assert.HandleFail("Assert.IsNotNull", message, parameters);
    }

    public static void AreSame(object expected, object actual)
    {
      Assert.AreSame(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreSame(object expected, object actual, string message)
    {
      Assert.AreSame(expected, actual, message, (object[]) null);
    }

    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);
    }

    public static void AreNotSame(object notExpected, object actual)
    {
      Assert.AreNotSame(notExpected, actual, string.Empty, (object[]) null);
    }

    public static void AreNotSame(object notExpected, object actual, string message)
    {
      Assert.AreNotSame(notExpected, actual, message, (object[]) null);
    }

    public static void AreNotSame(object notExpected, object actual, string message, params object[] parameters)
    {
      if (!object.ReferenceEquals(notExpected, actual))
        return;
      Assert.HandleFail("Assert.AreNotSame", message, parameters);
    }

    public static void AreEqual<T>(T expected, T actual)
    {
      Assert.AreEqual<T>(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreEqual<T>(T expected, T actual, string message)
    {
      Assert.AreEqual<T>(expected, actual, message, (object[]) null);
    }

    public static void AreEqual<T>(T expected, T actual, string message, params object[] parameters)
    {
      message = Assert.CreateCompleteMessage(message, parameters);
      if (object.Equals((object) expected, (object) actual))
        return;
      Assert.HandleFailure("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));
    }

    public static void AreNotEqual<T>(T notExpected, T actual)
    {
      Assert.AreNotEqual<T>(notExpected, actual, string.Empty, (object[]) null);
    }

    public static void AreNotEqual<T>(T notExpected, T actual, string message)
    {
      Assert.AreNotEqual<T>(notExpected, actual, message, (object[]) null);
    }

    public static void AreNotEqual<T>(T notExpected, T actual, string message, params object[] parameters)
    {
      message = Assert.CreateCompleteMessage(message, parameters);
      if (!object.Equals((object) notExpected, (object) actual))
        return;
      Assert.HandleFailure("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)));
    }

    public static void AreEqual(object expected, object actual)
    {
      Assert.AreEqual(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreEqual(object expected, object actual, string message)
    {
      Assert.AreEqual(expected, actual, message, (object[]) null);
    }

    public static void AreEqual(object expected, object actual, string message, params object[] parameters)
    {
      Assert.AreEqual<object>(expected, actual, message, parameters);
    }

    public static void AreNotEqual(object notExpected, object actual)
    {
      Assert.AreNotEqual(notExpected, actual, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(object notExpected, object actual, string message)
    {
      Assert.AreNotEqual(notExpected, actual, message, (object[]) null);
    }

    public static void AreNotEqual(object notExpected, object actual, string message, params object[] parameters)
    {
      Assert.AreNotEqual<object>(notExpected, actual, message, parameters);
    }

    public static void AreEqual(float expected, float actual, float delta)
    {
      Assert.AreEqual(expected, actual, delta, string.Empty, (object[]) null);
    }

    public static void AreEqual(float expected, float actual, float delta, string message)
    {
      Assert.AreEqual(expected, actual, delta, message, (object[]) null);
    }

    public static void AreEqual(float expected, float actual, float delta, string message, params object[] parameters)
    {
      if (float.IsNaN(expected) || float.IsNaN(actual) || float.IsNaN(delta))
        Assert.HandleFail("Assert.AreEqual", (string) FrameworkMessages.AreEqualDeltaFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expected.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) actual.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) delta.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat)), parameters);
      if ((double) Math.Abs(expected - actual) <= (double) delta)
        return;
      Assert.HandleFail("Assert.AreEqual", (string) FrameworkMessages.AreEqualDeltaFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expected.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) actual.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) delta.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat)), parameters);
    }

    public static void AreNotEqual(float notExpected, float actual, float delta)
    {
      Assert.AreNotEqual(notExpected, actual, delta, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(float notExpected, float actual, float delta, string message)
    {
      Assert.AreNotEqual(notExpected, actual, delta, message, (object[]) null);
    }

    public static void AreNotEqual(float notExpected, float actual, float delta, string message, params object[] parameters)
    {
      if ((double) Math.Abs(notExpected - actual) > (double) 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);
    }

    public static void AreEqual(double expected, double actual, double delta)
    {
      Assert.AreEqual(expected, actual, delta, string.Empty, (object[]) null);
    }

    public static void AreEqual(double expected, double actual, double delta, string message)
    {
      Assert.AreEqual(expected, actual, delta, message, (object[]) null);
    }

    public static void AreEqual(double expected, double actual, double delta, string message, params object[] parameters)
    {
      if (double.IsNaN(expected) || double.IsNaN(actual) || double.IsNaN(delta))
        Assert.HandleFail("Assert.AreEqual", (string) FrameworkMessages.AreEqualDeltaFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expected.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) actual.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) delta.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat)), parameters);
      if (Math.Abs(expected - actual) <= delta)
        return;
      Assert.HandleFail("Assert.AreEqual", (string) FrameworkMessages.AreEqualDeltaFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expected.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) actual.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) delta.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat)), parameters);
    }

    public static void AreNotEqual(double notExpected, double actual, double delta)
    {
      Assert.AreNotEqual(notExpected, actual, delta, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(double notExpected, double actual, double delta, string message)
    {
      Assert.AreNotEqual(notExpected, actual, delta, message, (object[]) null);
    }

    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);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase)
    {
      Assert.AreEqual(expected, actual, ignoreCase, string.Empty, (object[]) null);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase, string message)
    {
      Assert.AreEqual(expected, actual, ignoreCase, message, (object[]) null);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase, string message, params object[] parameters)
    {
      Assert.AreEqual(expected, actual, ignoreCase, CultureInfo.InvariantCulture, message, parameters);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase, CultureInfo culture)
    {
      Assert.AreEqual(expected, actual, ignoreCase, culture, string.Empty, (object[]) null);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase, CultureInfo culture, string message)
    {
      Assert.AreEqual(expected, actual, ignoreCase, culture, message, (object[]) null);
    }

    public static void AreEqual(string expected, string actual, bool ignoreCase, CultureInfo culture, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) culture, "Assert.AreEqual", "culture", string.Empty, new object[0]);
      if (string.Compare(expected, actual, ignoreCase, culture) == 0)
        return;
      Assert.HandleFail("Assert.AreEqual", ignoreCase || string.Compare(expected, actual, true, culture) != 0 ? (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.AreEqualCaseFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) Assert.ReplaceNulls((object) expected), (object) Assert.ReplaceNulls((object) actual)), parameters);
    }

    public static void AreNotEqual(string notExpected, string actual, bool ignoreCase)
    {
      Assert.AreNotEqual(notExpected, actual, ignoreCase, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(string notExpected, string actual, bool ignoreCase, string message)
    {
      Assert.AreNotEqual(notExpected, actual, ignoreCase, message, (object[]) null);
    }

    public static void AreNotEqual(string notExpected, string actual, bool ignoreCase, string message, params object[] parameters)
    {
      Assert.AreNotEqual(notExpected, actual, ignoreCase, CultureInfo.InvariantCulture, message, parameters);
    }

    public static void AreNotEqual(string notExpected, string actual, bool ignoreCase, CultureInfo culture)
    {
      Assert.AreNotEqual(notExpected, actual, ignoreCase, culture, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(string notExpected, string actual, bool ignoreCase, CultureInfo culture, string message)
    {
      Assert.AreNotEqual(notExpected, actual, ignoreCase, culture, message, (object[]) null);
    }

    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);
    }

    public static void IsInstanceOfType(object value, Type expectedType)
    {
      Assert.IsInstanceOfType(value, expectedType, string.Empty, (object[]) null);
    }

    public static void IsInstanceOfType(object value, Type expectedType, string message)
    {
      Assert.IsInstanceOfType(value, expectedType, message, (object[]) null);
    }

    public static void IsInstanceOfType(object value, Type expectedType, string message, params object[] parameters)
    {
      if (expectedType == null)
        Assert.HandleFail("Assert.IsInstanceOfType", message, parameters);
      if (expectedType.IsInstanceOfType(value))
        return;
      Assert.HandleFail("Assert.IsInstanceOfType", (string) FrameworkMessages.IsInstanceOfFailMsg(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expectedType.ToString(), value == null ? (object) (string) FrameworkMessages.Common_NullInMessages : (object) value.GetType().ToString()), parameters);
    }

    public static void IsNotInstanceOfType(object value, Type wrongType)
    {
      Assert.IsNotInstanceOfType(value, wrongType, string.Empty, (object[]) null);
    }

    public static void IsNotInstanceOfType(object value, Type wrongType, string message)
    {
      Assert.IsNotInstanceOfType(value, wrongType, message, (object[]) null);
    }

    public static void IsNotInstanceOfType(object value, Type wrongType, string message, params object[] parameters)
    {
      if (wrongType == 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);
    }

    public static void Fail()
    {
      Assert.Fail(string.Empty, (object[]) null);
    }

    public static void Fail(string message)
    {
      Assert.Fail(message, (object[]) null);
    }

    public static void Fail(string message, params object[] parameters)
    {
      Assert.HandleFail("Assert.Fail", message, parameters);
    }

    public static void Inconclusive()
    {
      Assert.Inconclusive(string.Empty, (object[]) null);
    }

    public static void Inconclusive(string message)
    {
      Assert.Inconclusive(message, (object[]) null);
    }

    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));
    }

    public new static bool Equals(object objA, object objB)
    {
      Assert.Fail((string) FrameworkMessages.DoNotUseAssertEquals);
      return false;
    }

    internal static void HandleFail(string assertionName, string message, params object[] parameters)
    {
      string completeMessage = Assert.CreateCompleteMessage(message, parameters);
      Assert.HandleFailure(assertionName, completeMessage);
    }

    internal static string CreateCompleteMessage(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);
      return str;
    }

    internal static void HandleFailure(string assertionName, string message)
    {
      if (Assert.AssertionFailure != null)
        Assert.AssertionFailure((object) null, EventArgs.Empty);
      throw new AssertFailedException(FrameworkMessages.AssertionFailed((object) assertionName, (object) message));
    }

    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);
    }

    internal static string ReplaceNulls(object input)
    {
      if (input == null)
        return FrameworkMessages.Common_NullInMessages.ToString();
      string input1 = input.ToString();
      if (input1 == null)
        return FrameworkMessages.Common_ObjectString.ToString();
      else
        return Assert.ReplaceNullChars(input1);
    }

    public static string ReplaceNullChars(string input)
    {
      if (string.IsNullOrEmpty(input))
        return input;
      List<int> list = new List<int>();
      for (int index = 0; index < input.Length; ++index)
      {
        if ((int) input[index] == 0)
          list.Add(index);
      }
      if (list.Count <= 0)
        return input;
      StringBuilder stringBuilder = new StringBuilder(input.Length + list.Count);
      int startIndex = 0;
      foreach (int num in list)
      {
        stringBuilder.Append(input.Substring(startIndex, num - startIndex));
        stringBuilder.Append("\\0");
        startIndex = num + 1;
      }
      stringBuilder.Append(input.Substring(startIndex));
      return ((object) stringBuilder).ToString();
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert from JetBrains dotPeek 1.0 at 2017-07-06

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: D:\Download\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  public static class CollectionAssert
  {
    public static void Contains(ICollection collection, object element)
    {
      CollectionAssert.Contains(collection, element, string.Empty, (object[]) null);
    }

    public static void Contains(ICollection collection, object element, string message)
    {
      CollectionAssert.Contains(collection, element, message, (object[]) null);
    }

    public static void Contains(ICollection collection, object element, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) collection, "CollectionAssert.Contains", "collection", string.Empty, new object[0]);
      foreach (object objA in (IEnumerable) collection)
      {
        if (object.Equals(objA, element))
          return;
      }
      Assert.HandleFail("CollectionAssert.Contains", message, parameters);
    }

    public static void DoesNotContain(ICollection collection, object element)
    {
      CollectionAssert.DoesNotContain(collection, element, string.Empty, (object[]) null);
    }

    public static void DoesNotContain(ICollection collection, object element, string message)
    {
      CollectionAssert.DoesNotContain(collection, element, message, (object[]) null);
    }

    public static void DoesNotContain(ICollection collection, object element, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) collection, "CollectionAssert.DoesNotContain", "collection", string.Empty, new object[0]);
      foreach (object objA in (IEnumerable) collection)
      {
        if (object.Equals(objA, element))
          Assert.HandleFail("CollectionAssert.DoesNotContain", message, parameters);
      }
    }

    public static void AllItemsAreNotNull(ICollection collection)
    {
      CollectionAssert.AllItemsAreNotNull(collection, string.Empty, (object[]) null);
    }

    public static void AllItemsAreNotNull(ICollection collection, string message)
    {
      CollectionAssert.AllItemsAreNotNull(collection, message, (object[]) null);
    }

    public static void AllItemsAreNotNull(ICollection collection, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) collection, "CollectionAssert.AllItemsAreNotNull", "collection", string.Empty, new object[0]);
      foreach (object obj in (IEnumerable) collection)
      {
        if (obj == null)
          Assert.HandleFail("CollectionAssert.AllItemsAreNotNull", message, parameters);
      }
    }

    public static void AllItemsAreUnique(ICollection collection)
    {
      CollectionAssert.AllItemsAreUnique(collection, string.Empty, (object[]) null);
    }

    public static void AllItemsAreUnique(ICollection collection, string message)
    {
      CollectionAssert.AllItemsAreUnique(collection, message, (object[]) null);
    }

    public static void AllItemsAreUnique(ICollection collection, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) collection, "CollectionAssert.AllItemsAreUnique", "collection", string.Empty, new object[0]);
      message = Assert.ReplaceNulls((object) message);
      bool flag = false;
      Hashtable hashtable = new Hashtable();
      foreach (object index in (IEnumerable) collection)
      {
        if (index == null)
        {
          if (!flag)
            flag = true;
          else
            Assert.HandleFail("CollectionAssert.AllItemsAreUnique", (string) FrameworkMessages.AllItemsAreUniqueFailMsg(message == null ? (object) string.Empty : (object) message, (object) FrameworkMessages.Common_NullInMessages), parameters);
        }
        else if (hashtable[index] != null)
          Assert.HandleFail("CollectionAssert.AllItemsAreUnique", (string) FrameworkMessages.AllItemsAreUniqueFailMsg(message == null ? (object) string.Empty : (object) message, (object) Assert.ReplaceNulls(index)), parameters);
        else
          hashtable.Add(index, (object) true);
      }
    }

    public static void IsSubsetOf(ICollection subset, ICollection superset)
    {
      CollectionAssert.IsSubsetOf(subset, superset, string.Empty, (object[]) null);
    }

    public static void IsSubsetOf(ICollection subset, ICollection superset, string message)
    {
      CollectionAssert.IsSubsetOf(subset, superset, message, (object[]) null);
    }

    public static void IsSubsetOf(ICollection subset, ICollection superset, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) subset, "CollectionAssert.IsSubsetOf", "subset", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) superset, "CollectionAssert.IsSubsetOf", "superset", string.Empty, new object[0]);
      if (CollectionAssert.IsSubsetOfHelper(subset, superset))
        return;
      Assert.HandleFail("CollectionAssert.IsSubsetOf", message, parameters);
    }

    public static void IsNotSubsetOf(ICollection subset, ICollection superset)
    {
      CollectionAssert.IsNotSubsetOf(subset, superset, string.Empty, (object[]) null);
    }

    public static void IsNotSubsetOf(ICollection subset, ICollection superset, string message)
    {
      CollectionAssert.IsNotSubsetOf(subset, superset, message, (object[]) null);
    }

    public static void IsNotSubsetOf(ICollection subset, ICollection superset, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) subset, "CollectionAssert.IsNotSubsetOf", "subset", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) superset, "CollectionAssert.IsNotSubsetOf", "superset", string.Empty, new object[0]);
      if (!CollectionAssert.IsSubsetOfHelper(subset, superset))
        return;
      Assert.HandleFail("CollectionAssert.IsNotSubsetOf", message, parameters);
    }

    public static void AreEquivalent(ICollection expected, ICollection actual)
    {
      CollectionAssert.AreEquivalent(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreEquivalent(ICollection expected, ICollection actual, string message)
    {
      CollectionAssert.AreEquivalent(expected, actual, message, (object[]) null);
    }

    public static void AreEquivalent(ICollection expected, ICollection actual, string message, params object[] parameters)
    {
      if (expected == null != (actual == null))
        Assert.HandleFail("CollectionAssert.AreEquivalent", message, parameters);
      if (object.ReferenceEquals((object) expected, (object) actual) || expected == null)
        return;
      if (expected.Count != actual.Count)
        Assert.HandleFail("CollectionAssert.AreEquivalent", (string) FrameworkMessages.ElementNumbersDontMatch(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expected.Count, (object) actual.Count), parameters);
      int expectedCount;
      int actualCount;
      object mismatchedElement;
      if (expected.Count == 0 || !CollectionAssert.FindMismatchedElement(expected, actual, out expectedCount, out actualCount, out mismatchedElement))
        return;
      Assert.HandleFail("CollectionAssert.AreEquivalent", (string) FrameworkMessages.ActualHasMismatchedElements(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) expectedCount.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat), (object) Assert.ReplaceNulls(mismatchedElement), (object) actualCount.ToString((IFormatProvider) CultureInfo.CurrentCulture.NumberFormat)), parameters);
    }

    public static void AreNotEquivalent(ICollection expected, ICollection actual)
    {
      CollectionAssert.AreNotEquivalent(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreNotEquivalent(ICollection expected, ICollection actual, string message)
    {
      CollectionAssert.AreNotEquivalent(expected, actual, message, (object[]) null);
    }

    public static void AreNotEquivalent(ICollection expected, ICollection actual, string message, params object[] parameters)
    {
      if (expected == null != (actual == null))
        return;
      if (object.ReferenceEquals((object) expected, (object) actual))
        Assert.HandleFail("CollectionAssert.AreNotEquivalent", (string) FrameworkMessages.BothCollectionsSameReference(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message)), parameters);
      if (expected.Count != actual.Count)
        return;
      if (expected.Count == 0)
        Assert.HandleFail("CollectionAssert.AreNotEquivalent", (string) FrameworkMessages.BothCollectionsEmpty(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message)), parameters);
      int expectedCount;
      int actualCount;
      object mismatchedElement;
      if (CollectionAssert.FindMismatchedElement(expected, actual, out expectedCount, out actualCount, out mismatchedElement))
        return;
      Assert.HandleFail("CollectionAssert.AreNotEquivalent", (string) FrameworkMessages.BothSameElements(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message)), parameters);
    }

    public static void AllItemsAreInstancesOfType(ICollection collection, Type expectedType)
    {
      CollectionAssert.AllItemsAreInstancesOfType(collection, expectedType, string.Empty, (object[]) null);
    }

    public static void AllItemsAreInstancesOfType(ICollection collection, Type expectedType, string message)
    {
      CollectionAssert.AllItemsAreInstancesOfType(collection, expectedType, message, (object[]) null);
    }

    public static void AllItemsAreInstancesOfType(ICollection collection, Type expectedType, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) collection, "CollectionAssert.AllItemsAreInstancesOfType", "collection", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) expectedType, "CollectionAssert.AllItemsAreInstancesOfType", "expectedType", string.Empty, new object[0]);
      int num = 0;
      foreach (object o in (IEnumerable) collection)
      {
        if (!expectedType.IsInstanceOfType(o))
          Assert.HandleFail("CollectionAssert.AllItemsAreInstancesOfType", o == null ? (string) FrameworkMessages.ElementTypesAtIndexDontMatch2(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) num, (object) expectedType.ToString()) : (string) FrameworkMessages.ElementTypesAtIndexDontMatch(message == null ? (object) string.Empty : (object) Assert.ReplaceNulls((object) message), (object) num, (object) expectedType.ToString(), (object) o.GetType().ToString()), parameters);
        ++num;
      }
    }

    public static void AreEqual(ICollection expected, ICollection actual)
    {
      CollectionAssert.AreEqual(expected, actual, string.Empty, (object[]) null);
    }

    public static void AreEqual(ICollection expected, ICollection actual, string message)
    {
      CollectionAssert.AreEqual(expected, actual, message, (object[]) null);
    }

    public static void AreEqual(ICollection expected, ICollection actual, string message, params object[] parameters)
    {
      string reason = string.Empty;
      if (CollectionAssert.AreCollectionsEqual(expected, actual, (IComparer) new CollectionAssert.ObjectComparer(), ref reason))
        return;
      Assert.HandleFail("CollectionAssert.AreEqual", (string) FrameworkMessages.CollectionEqualReason((object) message, (object) reason), parameters);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual)
    {
      CollectionAssert.AreNotEqual(notExpected, actual, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual, string message)
    {
      CollectionAssert.AreNotEqual(notExpected, actual, message, (object[]) null);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual, string message, params object[] parameters)
    {
      string reason = string.Empty;
      if (!CollectionAssert.AreCollectionsEqual(notExpected, actual, (IComparer) new CollectionAssert.ObjectComparer(), ref reason))
        return;
      Assert.HandleFail("CollectionAssert.AreNotEqual", (string) FrameworkMessages.CollectionEqualReason((object) message, (object) reason), parameters);
    }

    public static void AreEqual(ICollection expected, ICollection actual, IComparer comparer)
    {
      CollectionAssert.AreEqual(expected, actual, comparer, string.Empty, (object[]) null);
    }

    public static void AreEqual(ICollection expected, ICollection actual, IComparer comparer, string message)
    {
      CollectionAssert.AreEqual(expected, actual, comparer, message, (object[]) null);
    }

    public static void AreEqual(ICollection expected, ICollection actual, IComparer comparer, string message, params object[] parameters)
    {
      string reason = string.Empty;
      if (CollectionAssert.AreCollectionsEqual(expected, actual, comparer, ref reason))
        return;
      Assert.HandleFail("CollectionAssert.AreEqual", (string) FrameworkMessages.CollectionEqualReason((object) message, (object) reason), parameters);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual, IComparer comparer)
    {
      CollectionAssert.AreNotEqual(notExpected, actual, comparer, string.Empty, (object[]) null);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual, IComparer comparer, string message)
    {
      CollectionAssert.AreNotEqual(notExpected, actual, comparer, message, (object[]) null);
    }

    public static void AreNotEqual(ICollection notExpected, ICollection actual, IComparer comparer, string message, params object[] parameters)
    {
      string reason = string.Empty;
      if (!CollectionAssert.AreCollectionsEqual(notExpected, actual, comparer, ref reason))
        return;
      Assert.HandleFail("CollectionAssert.AreNotEqual", (string) FrameworkMessages.CollectionEqualReason((object) message, (object) reason), parameters);
    }

    private static Dictionary<object, int> GetElementCounts(ICollection collection, out int nullCount)
    {
      Dictionary<object, int> dictionary = new Dictionary<object, int>();
      nullCount = 0;
      foreach (object key in (IEnumerable) collection)
      {
        if (key == null)
        {
          ++nullCount;
        }
        else
        {
          int num;
          dictionary.TryGetValue(key, out num);
          ++num;
          dictionary[key] = num;
        }
      }
      return dictionary;
    }

    internal static bool IsSubsetOfHelper(ICollection subset, ICollection superset)
    {
      int nullCount1;
      Dictionary<object, int> elementCounts1 = CollectionAssert.GetElementCounts(subset, out nullCount1);
      int nullCount2;
      Dictionary<object, int> elementCounts2 = CollectionAssert.GetElementCounts(superset, out nullCount2);
      if (nullCount1 > nullCount2)
        return false;
      foreach (object key in elementCounts1.Keys)
      {
        int num1;
        elementCounts1.TryGetValue(key, out num1);
        int num2;
        elementCounts2.TryGetValue(key, out num2);
        if (num1 > num2)
          return false;
      }
      return true;
    }

    private static bool FindMismatchedElement(ICollection expected, ICollection actual, out int expectedCount, out int actualCount, out object mismatchedElement)
    {
      int nullCount1;
      Dictionary<object, int> elementCounts1 = CollectionAssert.GetElementCounts(expected, out nullCount1);
      int nullCount2;
      Dictionary<object, int> elementCounts2 = CollectionAssert.GetElementCounts(actual, out nullCount2);
      if (nullCount2 != nullCount1)
      {
        expectedCount = nullCount1;
        actualCount = nullCount2;
        mismatchedElement = (object) null;
        return true;
      }
      else
      {
        foreach (object key in elementCounts1.Keys)
        {
          elementCounts1.TryGetValue(key, out expectedCount);
          elementCounts2.TryGetValue(key, out actualCount);
          if (expectedCount != actualCount)
          {
            mismatchedElement = key;
            return true;
          }
        }
        expectedCount = 0;
        actualCount = 0;
        mismatchedElement = (object) null;
        return false;
      }
    }

    private static bool AreCollectionsEqual(ICollection expected, ICollection actual, IComparer comparer, ref string reason)
    {
      Assert.CheckParameterNotNull((object) comparer, "Assert.AreCollectionsEqual", "comparer", string.Empty, new object[0]);
      if (!object.ReferenceEquals((object) expected, (object) actual))
      {
        if (expected == null || actual == null)
          return false;
        if (expected.Count != actual.Count)
        {
          reason = (string) FrameworkMessages.NumberOfElementsDiff;
          return false;
        }
        else
        {
          IEnumerator enumerator1 = expected.GetEnumerator();
          IEnumerator enumerator2 = actual.GetEnumerator();
          int num = 0;
          while (enumerator1.MoveNext() && enumerator2.MoveNext())
          {
            if (0 != comparer.Compare(enumerator1.Current, enumerator2.Current))
            {
              reason = (string) FrameworkMessages.ElementsAtIndexDontMatch((object) num);
              return false;
            }
            else
              ++num;
          }
          reason = (string) FrameworkMessages.BothCollectionsSameElements;
          return true;
        }
      }
      else
      {
        reason = (string) FrameworkMessages.BothCollectionsSameReference((object) string.Empty);
        return true;
      }
    }

    private class ObjectComparer : IComparer
    {
      int IComparer.Compare(object x, object y)
      {
        return !object.Equals(x, y) ? -1 : 0;
      }
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert from JetBrains dotPeek 1.0 at 2017-07-06

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: D:\Download\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;
using System.Text.RegularExpressions;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  public static class StringAssert
  {
    public static void Contains(string value, string substring)
    {
      StringAssert.Contains(value, substring, string.Empty, (object[]) null);
    }

    public static void Contains(string value, string substring, string message)
    {
      StringAssert.Contains(value, substring, message, (object[]) null);
    }

    public static void Contains(string value, string substring, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) value, "StringAssert.Contains", "value", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) substring, "StringAssert.Contains", "substring", string.Empty, new object[0]);
      if (0 <= value.IndexOf(substring, StringComparison.Ordinal))
        return;
      Assert.HandleFail("StringAssert.Contains", (string) FrameworkMessages.ContainsFail((object) value, (object) substring, (object) message), parameters);
    }

    public static void StartsWith(string value, string substring)
    {
      StringAssert.StartsWith(value, substring, string.Empty, (object[]) null);
    }

    public static void StartsWith(string value, string substring, string message)
    {
      StringAssert.StartsWith(value, substring, message, (object[]) null);
    }

    public static void StartsWith(string value, string substring, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) value, "StringAssert.StartsWith", "value", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) substring, "StringAssert.StartsWith", "substring", string.Empty, new object[0]);
      if (value.StartsWith(substring, StringComparison.Ordinal))
        return;
      Assert.HandleFail("StringAssert.StartsWith", (string) FrameworkMessages.StartsWithFail((object) value, (object) substring, (object) message), parameters);
    }

    public static void EndsWith(string value, string substring)
    {
      StringAssert.EndsWith(value, substring, string.Empty, (object[]) null);
    }

    public static void EndsWith(string value, string substring, string message)
    {
      StringAssert.EndsWith(value, substring, message, (object[]) null);
    }

    public static void EndsWith(string value, string substring, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) value, "StringAssert.EndsWith", "value", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) substring, "StringAssert.EndsWith", "substring", string.Empty, new object[0]);
      if (value.EndsWith(substring, StringComparison.Ordinal))
        return;
      Assert.HandleFail("StringAssert.EndsWith", (string) FrameworkMessages.EndsWithFail((object) value, (object) substring, (object) message), parameters);
    }

    public static void Matches(string value, Regex pattern)
    {
      StringAssert.Matches(value, pattern, string.Empty, (object[]) null);
    }

    public static void Matches(string value, Regex pattern, string message)
    {
      StringAssert.Matches(value, pattern, message, (object[]) null);
    }

    public static void Matches(string value, Regex pattern, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) value, "StringAssert.Matches", "value", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) pattern, "StringAssert.Matches", "pattern", string.Empty, new object[0]);
      if (pattern.IsMatch(value))
        return;
      Assert.HandleFail("StringAssert.Matches", (string) FrameworkMessages.IsMatchFail((object) value, (object) pattern, (object) message), parameters);
    }

    public static void DoesNotMatch(string value, Regex pattern)
    {
      StringAssert.DoesNotMatch(value, pattern, string.Empty, (object[]) null);
    }

    public static void DoesNotMatch(string value, Regex pattern, string message)
    {
      StringAssert.DoesNotMatch(value, pattern, message, (object[]) null);
    }

    public static void DoesNotMatch(string value, Regex pattern, string message, params object[] parameters)
    {
      Assert.CheckParameterNotNull((object) value, "StringAssert.DoesNotMatch", "value", string.Empty, new object[0]);
      Assert.CheckParameterNotNull((object) pattern, "StringAssert.DoesNotMatch", "pattern", string.Empty, new object[0]);
      if (!pattern.IsMatch(value))
        return;
      Assert.HandleFail("StringAssert.DoesNotMatch", (string) FrameworkMessages.IsNotMatchFail((object) value, (object) pattern, (object) message), parameters);
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestAssertException from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestAssertException
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using System;
using System.Runtime.Serialization;
using System.Security.Permissions;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [Serializable]
  public abstract class UnitTestAssertException : Exception
  {
    private UtfMessage m_message;

    public override string Message
    {
      get
      {
        if (this.m_message != null)
          return this.m_message.ToString();
        else
          return base.Message;
      }
    }

    protected UnitTestAssertException()
    {
    }

    internal UnitTestAssertException(UtfMessage message)
      : this(message, (Exception) null)
    {
    }

    internal UnitTestAssertException(UtfMessage message, Exception inner)
      : base((string) message, inner)
    {
      this.m_message = message;
    }

    protected UnitTestAssertException(string msg, Exception ex)
      : base(msg, ex)
    {
    }

    protected UnitTestAssertException(string msg)
      : base(msg)
    {
    }

    protected UnitTestAssertException(SerializationInfo info, StreamingContext context)
      : base(info, context)
    {
      this.m_message = (UtfMessage) info.GetValue("m_message", typeof (UtfMessage));
    }

    [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)]
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
      base.GetObjectData(info, context);
      info.AddValue("m_message", (object) this.m_message);
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using System;
using System.Runtime.Serialization;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [Serializable]
  public class AssertFailedException : UnitTestAssertException
  {
    internal AssertFailedException(UtfMessage message)
      : base(message)
    {
    }

    internal AssertFailedException(UtfMessage message, Exception inner)
      : base(message, inner)
    {
    }

    public AssertFailedException(string msg, Exception ex)
      : base(msg, ex)
    {
    }

    public AssertFailedException(string msg)
      : base(msg)
    {
    }

    public AssertFailedException()
    {
    }

    protected AssertFailedException(SerializationInfo info, StreamingContext context)
      : base(info, context)
    {
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using System;
using System.Runtime.Serialization;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [Serializable]
  public class AssertInconclusiveException : UnitTestAssertException
  {
    internal AssertInconclusiveException(UtfMessage message)
      : base(message)
    {
    }

    internal AssertInconclusiveException(UtfMessage message, Exception inner)
      : base(message, inner)
    {
    }

    public AssertInconclusiveException(string msg, Exception ex)
      : base(msg, ex)
    {
    }

    public AssertInconclusiveException(string msg)
      : base(msg)
    {
    }

    public AssertInconclusiveException()
    {
    }

    protected AssertInconclusiveException(SerializationInfo info, StreamingContext context)
      : base(info, context)
    {
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionBaseAttribute from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionBaseAttribute
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  public abstract class ExpectedExceptionBaseAttribute : Attribute
  {
    private string m_noExceptionMessage;

    protected internal TestContext TestContext { get; internal set; }

    protected internal virtual string NoExceptionMessage
    {
      get
      {
        if (string.IsNullOrEmpty(this.m_noExceptionMessage))
          return ExpectedExceptionBaseAttribute.GetDefaultNoExceptionMessage(this.TestContext.FullyQualifiedTestClassName, this.TestContext.TestName, this.GetType().FullName);
        else
          return this.m_noExceptionMessage;
      }
    }

    protected ExpectedExceptionBaseAttribute()
      : this(string.Empty)
    {
    }

    protected ExpectedExceptionBaseAttribute(string noExceptionMessage)
    {
      this.m_noExceptionMessage = noExceptionMessage == null ? string.Empty : noExceptionMessage.Trim();
    }

    protected internal abstract void Verify(Exception exception);

    protected void RethrowIfAssertException(Exception exception)
    {
      if (exception is AssertFailedException)
        throw new AssertFailedException(exception.Message);
      if (exception is AssertInconclusiveException)
        throw new AssertInconclusiveException(exception.Message);
    }

    internal static string GetDefaultNoExceptionMessage(string fullyQualifiedClassName, string testName, string expectedExceptionAttributeTypeName)
    {
      return (string) FrameworkMessages.UTF_TestMethodNoExceptionDefault((object) fullyQualifiedClassName, (object) testName, (object) expectedExceptionAttributeTypeName);
    }

    internal string GetNoExceptionMessage()
    {
      return this.m_noExceptionMessage;
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.ExpectedExceptionAttribute
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
  public sealed class ExpectedExceptionAttribute : ExpectedExceptionBaseAttribute
  {
    protected internal override string NoExceptionMessage
    {
      get
      {
        return (string) FrameworkMessages.UTF_TestMethodNoException((object) this.TestContext.FullyQualifiedTestClassName, (object) this.TestContext.TestName, (object) this.ExceptionType.FullName, (object) this.GetNoExceptionMessage());
      }
    }

    public Type ExceptionType { get; private set; }

    public bool AllowDerivedTypes { get; set; }

    public ExpectedExceptionAttribute(Type exceptionType)
      : this(exceptionType, string.Empty)
    {
    }

    public ExpectedExceptionAttribute(Type exceptionType, string noExceptionMessage)
      : base(noExceptionMessage)
    {
      if (exceptionType == null)
        throw new ArgumentNullException("exceptionType");
      if (!typeof (Exception).IsAssignableFrom(exceptionType))
        throw new ArgumentException((string) FrameworkMessages.UTF_ExpectedExceptionTypeMustDeriveFromException, "exceptionType");
      this.ExceptionType = exceptionType;
    }

    protected internal override void Verify(Exception exception)
    {
      Type type = exception.GetType();
      if (this.AllowDerivedTypes)
      {
        if (this.ExceptionType.IsAssignableFrom(type))
          return;
        this.RethrowIfAssertException(exception);
        throw new Exception((string) FrameworkMessages.UTF_TestMethodWrongExceptionDerivedAllowed((object) this.TestContext.FullyQualifiedTestClassName, (object) this.TestContext.TestName, (object) type.FullName, (object) this.ExceptionType.FullName, (object) UtfHelper.GetExceptionMsg(exception)));
      }
      else
      {
        if (type == this.ExceptionType)
          return;
        this.RethrowIfAssertException(exception);
        throw new Exception((string) FrameworkMessages.UTF_TestMethodWrongException((object) this.TestContext.FullyQualifiedTestClassName, (object) this.TestContext.TestName, (object) type.FullName, (object) this.ExceptionType.FullName, (object) UtfHelper.GetExceptionMsg(exception)));
      }
    }
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
  [Serializable]
  public sealed class TestClassAttribute : Attribute
  {
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using System;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  [AttributeUsage(AttributeTargets.Method, AllowMultiple = false)]
  public sealed class TestMethodAttribute : Attribute
  {
  }
}

Source Code of Microsoft.VisualStudio.TestTools.UnitTesting.TestContext from JetBrains dotPeek 1.0 at 2017-12-02

Complete Copy:

// Type: Microsoft.VisualStudio.TestTools.UnitTesting.TestContext
// Assembly: Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// Assembly location: C:\Program Files (x86)\VS2013_RTM_ULT_CHS\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

using Microsoft.VisualStudio.TestTools.Resources;
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Web.UI;

namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
  public abstract class TestContext
  {
    public const string AspNetDevelopmentServerPrefix = "AspNetDevelopmentServer.";

    public abstract IDictionary Properties { get; }

    public abstract DataRow DataRow { get; }

    public abstract DbConnection DataConnection { get; }

    public virtual string TestRunDirectory
    {
      get
      {
        return this.GetProperty<string>("TestRunDirectory");
      }
    }

    public virtual string DeploymentDirectory
    {
      get
      {
        return this.GetProperty<string>("DeploymentDirectory");
      }
    }

    public virtual string ResultsDirectory
    {
      get
      {
        return this.GetProperty<string>("ResultsDirectory");
      }
    }

    public virtual string TestRunResultsDirectory
    {
      get
      {
        return this.GetProperty<string>("TestRunResultsDirectory");
      }
    }

    public virtual string TestResultsDirectory
    {
      get
      {
        return this.GetProperty<string>("TestResultsDirectory");
      }
    }

    public virtual string TestDir
    {
      get
      {
        return this.GetProperty<string>("TestDir");
      }
    }

    public virtual string TestDeploymentDir
    {
      get
      {
        return this.GetProperty<string>("TestDeploymentDir");
      }
    }

    public virtual string TestLogsDir
    {
      get
      {
        return this.GetProperty<string>("TestLogsDir");
      }
    }

    public virtual string FullyQualifiedTestClassName
    {
      get
      {
        return this.GetProperty<string>("FullyQualifiedTestClassName");
      }
    }

    public virtual string TestName
    {
      get
      {
        return this.GetProperty<string>("TestName");
      }
    }

    public virtual UnitTestOutcome CurrentTestOutcome
    {
      get
      {
        return UnitTestOutcome.Unknown;
      }
    }

    public virtual Page RequestedPage
    {
      get
      {
        return this.GetProperty<Page>("RequestedPage");
      }
    }

    public abstract void WriteLine(string format, params object[] args);

    public abstract void AddResultFile(string fileName);

    public abstract void BeginTimer(string timerName);

    public abstract void EndTimer(string timerName);

    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;
    }
  }
}