I crate domain project to store dbml file and several domain classes. I create unit test project to test CRUD operation. I reference domain project to the test project.
I declare the db context in the unit test, in the test method I try to access method db.SubmitChanges(); but It is not accessible.
But when the unit test file stored in the domain project, the db method is accessible.
[TestFixture]
class CustomerRepositoryTest
{
NorthWindDataContext db = new NorthWindDataContext();
Customer _customer = null;
[SetUp]
public void SetUp() {
//initialize customer
}
[Test]
public void Should_able_to_get_data_when_data_is_inserted()
{
db.Customers.InsertOnSubmit(_customer);
db.SubmitChanges();
Customer customer = db.Customers.FirstOrDefault(c => c.CustomerID == _customer.CustomerID);
Assert.AreEqual(customer.CustomerID.Trim(), _customer.CustomerID);
Assert.AreEqual(customer.ContactName.Trim(), _customer.ContactName);
}
[TearDown]
public void After()
{
db.Customers.DeleteOnSubmit(_customer);
db.SubmitChanges();
}
}
Let me know how to fix this.
EDIT:
Error 1 'AppProject.Domain.NorthWindDataContext' does not contain a definition for 'SubmitChanges' and no extension method 'SubmitChanges' accepting a first argument of type 'AppProject.Domain.NorthWindDataContext' could be found (are you missing a using directive or an assembly reference?) D:\tutorial\dotNET\LINQtoSQL\AppProject.Spec\Should_insert_customer.cs 40 16 AppProject.Spec
You need to add reference to
System.Data.Linqassembly in your test project.The assembly reference is added to your main project when creating dbml file (data context). in order to use all of the LinqToSQL functionality, you need to reference
System.Data.Linqin all of the projects where DataContext is used.