Reputation: 11277
Say I have an interface
public interface IDatabase
{
IObjectSet<Table1> Table1 {get;}
IObjectSet<Table2> Table2 {get;}
//goes on to around Table400
}
So when I create an instance with FakeItEasy:
var fakeDb = A.Fake<IDatabase>();
All the properties (tables) have a default fake value.
I can see why this is handy in most senarios but in mine, I need all of them to be null
Is there a clever way of doing that?
Upvotes: 4
Views: 372
Reputation: 271
just for completeness. Another way to tell FakeItEasy it shouldn't automatically create default fake values is to declare your fake as strict like so:
var fake = A.Fake<IDatabase>(builder => builder.Strict());
though in this case FakeItEasy will throw an exception if a member is called that wasn't set up before.
In your case the suggested version is the best, though I would write it with the A
syntax so you better see which calls are setups on fakes:
A.CallTo(fake).DoesNothing();
these two are identical.
Upvotes: 4
Reputation: 30790
I'm not sure it that's how it was meant to work but I found that you can set expectation on all calls to an object:
[TestMethod]
public void TestMethod1()
{
var fake = A.Fake<IDatabase>();
fake.AnyCall().DoesNothing();
var result = fake.Table1;
Assert.IsNull(result);
}
By using AnyCall you can set expectation on all of the calls to a specific fake - in this case DoesNothing returns the default value of null
Upvotes: 5