I have a simple data method that does this:
public void Write(Foo foo)
{
db.Foos.Add(foo);
db.SaveChanges();
}
I was asked to write unit tests for this. To do so, I had to create a fake DbContext and DbSet. I'm basically just asserting that Add()
was called on the DbSet, and that Save()
was called on the DbContext.
My concern is that it's too tightly coupling the test to the code. The test is basically dictating how the code does its job, instead of what it does.
I'm just looking for a sanity check here. Am I wrong? Is it good to have tests like this?