We use C# and Linq2SQL with a MS SQL Server Database. We have a mockdatacontext to carry out some unit testing. When testing we have discovered two different behaviours depending on whether the "real" or "mock" database is used.
Scenario 1: Real Database
There are 5 records in the database:
db = realDatabase
db.InsertOnSubmit(new record)
var count1 = db.getTable.Count()
db.SubmitChanges()
var count2 = db.getTable.Count()
count1 = 5 count2 = 6
Scenario 2: Mock Database
There are 5 records in the database:
db= mockDatabase
db.InsertOnSubmit(new record)
var count1 = db.getTable.Count()
db.SubmitChanges()
var count2 = db.getTable.Count()
count1 = 6 count2 = 6
*The "mock" database is already aware of the new record before SubmitChanges() is called, so it is included in the count. For testing, we need the two behaviours to be the same.
Has anyone else come across this problem and can you suggest a solution?