The updated example really helps, @rhe1980.
First some notes about the test you supplied:
- the
A.CallTo
method doesn't do anything - it's not setting up behaviour (with a.Invokes
or a.Returns
or even a.DoesNothing
) or verifying that the method has been called (for example with.MustHaveHappened
). - Comparing
Action
s appears to be tough. I did find some advice over at Compare Delegates Action<T>, but if it were me, I'd take a slightly different tack.
Instead of attempting to compare the Action
delegate to a reference model, I figured I could emulate this by capturing the action supplied to Execute
and then running it on an IDataAccess
and see what the action does. Fortunately, we have FakeItEasy to help with that!
I had success with this test:
[TestMethod]
public void TestMethod1()
{
// Arrange
var foo = A.Fake<IFoo>(x => x.Strict());
var fakeDataAccess = A.Fake<IDataAccess>();
A.CallTo(() => foo.Execute(A<Action<IDataAccess>>.Ignored))
.Invokes((Action<IDataAccess> action)=>action(fakeDataAccess));
var cut = new ClassUnderTest(foo);
// Act
cut.MethodToTest(new Data { Property = 20 });
// Assert
A.CallTo(() => fakeDataAccess.Update(A<Data>.That.Matches(d => d.Property == 20)))
.MustHaveHappened();
}
I hope it helps.