Assert.AreSame Method

Definition

Overloads

AreSame(Object, Object)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame(Object, Object, String)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame(Object, Object, String, Object[])

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame<T>(T, T, String)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame<T>(T, T, String, Object[])

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame<T>(T, T, Assert.AssertAreSameInterpolatedStringHandler<T>)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame<T>(T, T)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

AreSame(Object, Object)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame(object expected, object actual);

Parameters

expected
Object

The first object to compare. This is the value the test expects.

actual
Object

The second object to compare. This is the value produced by the code under test.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 2.2.10 and other versions
Product Versions
MSTest.TestFramework 1.1.18, 1.2.1, 1.3.2, 1.4.0, 2.2.0, 2.1.2, 2.2.10

AreSame(Object, Object, String)

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame(object expected, object actual, string message);

Parameters

expected
Object

The first object to compare. This is the value the test expects.

actual
Object

The second object to compare. This is the value produced by the code under test.

message
String

The message to include in the exception when actual is not the same as expected. The message is shown in test results.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 2.2.10 and other versions
Product Versions
MSTest.TestFramework 1.1.18, 1.2.1, 1.3.2, 1.4.0, 2.2.0, 2.1.2, 2.2.10

AreSame(Object, Object, String, Object[])

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame(object expected, object actual, string message, params object[] parameters);

Parameters

expected
Object

The first object to compare. This is the value the test expects.

actual
Object

The second object to compare. This is the value produced by the code under test.

message
String

The message to include in the exception when actual is not the same as expected. The message is shown in test results.

parameters
Object[]

An array of parameters to use when formatting message.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 2.2.10 and other versions
Product Versions
MSTest.TestFramework 1.1.18, 1.2.1, 1.3.2, 1.4.0, 2.2.0, 2.1.2, 2.2.10

AreSame<T>(T, T, String)

Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame<T>(T? expected, T? actual, string? message);

Type Parameters

T

The type of values to compare.

Parameters

expected
T

The first object to compare. This is the value the test expects.

actual
T

The second object to compare. This is the value produced by the code under test.

message
String

The message to include in the exception when actual is not the same as expected. The message is shown in test results.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 3.8.0 and other versions
Product Versions
MSTest.TestFramework 3.0.4, 3.1.1, 3.2.2, 3.3.1, 3.4.3, 3.5.1, 3.6.4, 3.7.3, 3.8.0

AreSame<T>(T, T, String, Object[])

Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame<T>(T? expected, T? actual, string? message, params object?[]? parameters);

Type Parameters

T

The type of values to compare.

Parameters

expected
T

The first object to compare. This is the value the test expects.

actual
T

The second object to compare. This is the value produced by the code under test.

message
String

The message to include in the exception when actual is not the same as expected. The message is shown in test results.

parameters
Object[]

An array of parameters to use when formatting message.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 3.8.0 and other versions
Product Versions
MSTest.TestFramework 3.0.4, 3.1.1, 3.2.2, 3.3.1, 3.4.3, 3.5.1, 3.6.4, 3.7.3, 3.8.0

AreSame<T>(T, T, Assert.AssertAreSameInterpolatedStringHandler<T>)

Source:
Assert.AreSame.cs

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame<T>(T? expected, T? actual, ref Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AssertAreSameInterpolatedStringHandler<T> message);

Type Parameters

T

The type of values to compare.

Parameters

expected
T

The first object to compare. This is the value the test expects.

actual
T

The second object to compare. This is the value produced by the code under test.

message
Assert.AssertAreSameInterpolatedStringHandler<T>

The message to include in the exception when actual is not the same as expected. The message is shown in test results.

Applies to

MSTest.TestFramework 3.8.0
Product Versions
MSTest.TestFramework 3.8.0

AreSame<T>(T, T)

Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs
Source:
Assert.AreSame.cs

Tests whether the specified objects both refer to the same object and throws an exception if the two inputs do not refer to the same object.

public static void AreSame<T>(T? expected, T? actual);

Type Parameters

T

The type of values to compare.

Parameters

expected
T

The first object to compare. This is the value the test expects.

actual
T

The second object to compare. This is the value produced by the code under test.

Exceptions

Thrown if expected does not refer to the same object as actual.

Applies to

MSTest.TestFramework 3.8.0 and other versions
Product Versions
MSTest.TestFramework 3.0.4, 3.1.1, 3.2.2, 3.3.1, 3.4.3, 3.5.1, 3.6.4, 3.7.3, 3.8.0