This question is locked. New answers and comments are not allowed.
Hi again,
I'm trying to write some automated integration tests against my database objects, using Telerik Q2 2014 SP1.
The general form of a test is like this:
I'm inside of a transaction and using FlushChanges() so that I get a full cleanup if the test fails. This has worked great - except for one type of entity:
This is the only entity in my model with a composite key - a cross-reference table with some extra columns. When I trace this at the database layer, the delete is executed (it happens to be a stored procedure), but the context doesn't re-query the database to assert the record was deleted. The deletedEntity variable contains a reference to the entity. They are both in the "Deleted" state, and attempts to access any properties throws an exception - as expected! - but I am used to getting a null back from the final SingleOrDefault() query.
Any advice on what I might be doing wrong?
I'm trying to write some automated integration tests against my database objects, using Telerik Q2 2014 SP1.
The general form of a test is like this:
using
(var context =
new
MyContext())
{
// Create any related objects necessary for test
context.FlushChanges();
var entityUnderTest =
new
Entity();
context.Add(entityUnderTest);
// Or update, or delete - whatever I'm testing.
context.FlushChanges();
context.Refresh(RefreshMode.OverwriteChangesFromStore, entityUnderTest);
// Asserts, etc.
context.ClearChanges();
}
I'm inside of a transaction and using FlushChanges() so that I get a full cleanup if the test fails. This has worked great - except for one type of entity:
using
(var context =
new
MyContext())
{
// Create individual, organization, membership...
context.FlushChanges();
var entity = context.GetAll<Membership>()
.Where(i => i.MemberId == individualId && i.MemberOfId == organizationId).Single();
context.Delete(entity);
context.FlushChanges();
var deletedEntity = context.GetAll<Membership>()
.Where(i => i.MemberId == individualId && i.MemberOfId == organizationId).SingleOrDefault();
Assert.IsNull(deletedEntity);
context.ClearChanges();
}
This is the only entity in my model with a composite key - a cross-reference table with some extra columns. When I trace this at the database layer, the delete is executed (it happens to be a stored procedure), but the context doesn't re-query the database to assert the record was deleted. The deletedEntity variable contains a reference to the entity. They are both in the "Deleted" state, and attempts to access any properties throws an exception - as expected! - but I am used to getting a null back from the final SingleOrDefault() query.
Any advice on what I might be doing wrong?