Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed IsNotInstanceOfType failing when objected being asserted on is null #622

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/TestFramework/MSTest.Core/Assertions/Assert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,10 +1754,16 @@ public static void IsNotInstanceOfType(object value, Type wrongType, string mess
/// </exception>
public static void IsNotInstanceOfType(object value, Type wrongType, string message, params object[] parameters)
{
if (wrongType == null || value == null)
if (wrongType == null)
{
HandleFail("Assert.IsNotInstanceOfType", message, parameters);
}

// Null is not an instance of any type.
if (value == null)
{
return;
}

var elementTypeInfo = value.GetType().GetTypeInfo();
var expectedTypeInfo = wrongType.GetTypeInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ public void InstanceOfTypeShouldPassOnHigherInstance()
public void InstanceNotOfTypeShouldFailWhenValueIsNull()
{
Action action = () => TestFrameworkV2.Assert.IsNotInstanceOfType(null, typeof(AssertTests));
ActionUtility.ActionShouldThrowExceptionOfType(action, typeof(TestFrameworkV2.AssertFailedException));
}

[TestMethod]
Expand Down