Hi, I'm pretty new to Effort and for the most part I like this tool.
I stumbled on this tool when I was researching a way to unit test my linq queries with entity framework 6 in Visual Studio 2013. For my work we started a new project and with this project I wanted to setup the automated tests propperly, because with older projects
this was never done and it lead to major problems. In particular with the database queries.
So Effort gave me a very simple method for testing my linq queries. The Get methods perform flawlessly, however deleting and updating is giving me problems. I have the following repository:
public class FooRepository : IFooRepository
private readonly FooEntities dbContext;
public FooRepository(FooEntities context)
this.dbContext = context;
public async Task<Foo> GetAsync(int key)
var result = await this.dbContext.Foos
.SingleOrDefaultAsync(t => t.ID == key);
// .... more code
public void Delete(Foo entity)
this.dbContext.Entry(entity).State = EntityState.Deleted;
I call SaveChanges on the database context from a UnitOfWork instance. On this repository I am running the following unit test:
public class FooRepositoryTests
private FooEntities context;
public void TestInitialize()
var connection = Effort.EntityConnectionFactory.CreateTransient("name=FooEntities");
this.context = new FooEntities(connection);
this.context.Configuration.AutoDetectChangesEnabled = false;
this.context.Configuration.LazyLoadingEnabled = false;
this.context.Configuration.ProxyCreationEnabled = false;
this.context.Configuration.ValidateOnSaveEnabled = false;
public void TestCleanup()
// ... other test methods
public void UT_FooRepositoryDelete_OK()
var repository = new FooRepository(this.context);
var task = repository.GetAsync(1);
var foo = task.Result;
var fooID = foo.ID;
var result = this.context.SaveChanges();
// Additional Assert
var result2 = repository.GetAsync(fooID).Result;
I have set up the dbContext the same way as I did the context in my production code. But when I run the test from VS2013's Test Explorer it fails. In the Delete method the line
throws a InvalidOperationException with the message:
An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key.
I can make the unit test succeed by not using "AsNoTracking()" in my Get query. However I do not really want to do this, because 85% of the requests are for reads (to the database and webservices) and not for creating, updating or deleting. AsNoTracking
turns off a lot of overhead and increases the performance of the webservices.
When I run the repository code in production setting with manual tests then the "AsNoTracking()" does not give any problems. And the webservices function as they are supposed to.
Is there some kind of setting in effort that I have to make in order for my unit test to function with "AsNoTracking()" in the code?
Thanks in advance and kind regards