We've just separated our SQL Server database adapters to allow for differences between SQL Server 2000 and 2005, specifically, the nvarchar(max) data type.
Because the code change is so small, instead of reimplementing our adapter interfaces and abstract base class, I subclassed the SQL 2005 adapter from SQL 2000 and just override the appropriate methods and properties.
public abstract class SqlDatabaseAdapter : DatabaseAdapter, ISqlDatabaseAdapter
...
public class Sql2000DatabaseAdapter : SqlDatabaseAdapter
...
public class Sql2005DatabaseAdapter : Sql2000DatabaseAdapter
...
Our unit test code previously just cast to a particular type of adapter and then made an assertion against that type, but now that we have an adapter factory method to build the appropriate SQL Server adapter (from configuration or found via SQL connection), I want to verify that the exact type is instantiated (since we now default to SQL Server 2005), the only problem is our old tests are passing when they should be failing :)
In the example below, the entity factory creates a Sql2005DatabaseAdapter, but the test passes because this type inherits from Sql2000DatabaseAdapter. And it also works further up the ancestor chain.
Entity foo = EntityFactory.Create("foo");
Assert.IsInstanceOfType(typeof(SqlDatabaseAdapter), foo.Adapter); // Should fail for test
Assert.IsInstanceOfType(typeof(Sql2000DatabaseAdapter), foo.Adapter); // Should fail for test
Assert.IsInstanceOfType(typeof(Sql2005DatabaseAdapter), foo.Adapter); // Should pass
I understand why it's passing, and I can use the general Assert.AreEqual method to fix this particular case.
Assert.AreEqual(typeof(Sql2005DatabaseAdapter), foo.Adapter.GetType());
But I'm curious if there's a way using Assert.IsInstanceOfType?