I decided to provide some integration testing before proceeding as a proof of concept. In integration testing I will connect to the database and perform unit testing while connecting to the database.\
This unit test is almost identical to the one in my previous post. Except here I am testing the results that is coming out from EF and Database.
My target is to test IDataContext Implemented methods in NorthwindDataContext. Find below the Integration unit testing class.
[TestClass]
public class NorthwindDataContextIntegrationTest : IDisposable
{
IDataContext _context;
public NorthwindDataContextIntegrationTest()
{
_context = new NorthwindDataContext(ConfigurationManager
.ConnectionStrings["NorthwindDatabaseContext"]
.ConnectionString);
}
[TestMethod]
public void NorthwindDataContext_CategoryDataSource_Returns_CategorySet()
{
Assert.IsNotNull(_context.CategoryDataSource);
}
[TestMethod]
public void NorthwindDataContext_ProductDataSource_Returns_ProductSet()
{
Assert.IsNotNull(_context.ProductDataSource);
}
[TestMethod]
public void NorthwindDataContext_SupplierDataSource_Returns_SupplierSet()
{
Assert.IsNotNull(_context.SupplierDataSource);
}
[TestMethod]
public void NorthwindDataContext_Insert_Should_Change_Instance_EntityState_To_Added()
{
var category = Category.CreateCategory(1, "New Category");
_context.InsertOnSubmit("CategorySet",category);
Assert.AreEqual(category.EntityState, System.Data.EntityState.Added);
}
[TestMethod]
public void NorthwindDataContext_Delete_Should_Change_Instance_EntityState_To_Deleted()
{
var category = _context.CategoryDataSource.FirstOrDefault();
_context.DeleteOnSubmit(category);
Assert.AreEqual(category.EntityState, System.Data.EntityState.Deleted);
}
public void Dispose()
{
((NorthwindDataContext)_context).Dispose();
}
}
Download Source Code.