Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simple `Assert.IsAssignableFrom<T>` failing

Why does this simple assert statement fail? From what I've read I should be . Unfortunately, since the functionality is so basic there isn't much information out there.

public interface IDummy{}
public class Dummy : IDummy {}

Assert.IsAssignableFrom<IDummy>(new Dummy());

Running this test yields

Expected: assignable from <Application.Tests.ViewModels.IDummy>
  But was:  <Application.Tests.ViewModels.Dummy>

I have tried swapping the interface and objects side to no avail.

like image 489
gcso Avatar asked Apr 06 '11 01:04

gcso


1 Answers

IsAssignableFrom works in reverse from what you are expecting. It's asking: Is (the value) Assignable From IDummy. Or: "Is assignable to (value)?"

From the XML doc: /// Asserts that an object may be assigned a value of a given Type.

You probably want Assert.IsInstanceOfType()

like image 66
Talljoe Avatar answered Sep 27 '22 22:09

Talljoe