← Back to team overview

nunit-core team mailing list archive

[Bug 809679] Re: Assert.IsAssignableFrom is not implemented properly

 

** Changed in: nunitv2
       Status: New => Opinion

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/809679

Title:
  Assert.IsAssignableFrom is not implemented properly

Status in NUnit V2 Test Framework:
  Opinion

Bug description:
  I'm using 2.5.10.11092.

  I think the Assert.IsAssignableFrom is not implemented correctly. It
  does not work like Type.IsAssignableFrom. The unit tests below
  illustrate the problem. I expected both of the following to pass:

  class Room { };
  class Kitchen : Room { };

  [Test]
  public void AssertIsAssignableFrom_WorksLike_TypeIsAssignableFrom()
  {
      Assert.IsTrue(typeof(Room).IsAssignableFrom(typeof(Kitchen)));
      Assert.IsAssignableFrom(typeof(Room), new Kitchen());
  }

  I looked at the source in TypeConstraints.cs,
  AssignableFromConstraint, Matches. I think it is backwards. It has
  this:

   return actual != null &&
  actual.GetType().IsAssignableFrom(expectedType);

  It should be this:

   return actual != null && expected != null &&
  expectedType.IsAssignableFrom(actual.GetType());

  I looked at the unit tests for this method in TypeAssertTest.cs. None
  of the unit tests exercise the case of class hierarchy.

  This blog post may be helpful:
  http://codegoeshere.blogspot.com/2009/02/typeisassignablefrom-seems-backwards.html

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/809679/+subscriptions


References