Correct way to unit test the type of an object

The first example will fail if the types are not exactly the same while the second will only fail if myObject is not assignable to the given type e.g.

public class MySubObject : MyObject { ... }
var obj = new MySubObject();

Assert.AreEqual(obj.GetType(), typeof(MyObject));   //fails
Assert.IsInstanceOfType(obj, typeof(MyObject));     //passes

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)