Reputation: 12339
I have the following interfaces:
interface IManufacturing
{
IJobApi JobApi {get;}
}
interface IJobApi
{
IList<JobSpec> GetSpecs (string wo, string name);
}
I have a class which uses IManufacturing and calls GetSpecs() like so:
var specs = _manufacturing.JobApi.GetSpecs (wo, name);
I setup my mocks like:
var jobApi = A.Fake<IJobApi> ();
A.CallTo (() => jobApi.GetSpecs (It.IsAny<string> (), It.IsAny<string> ()))
.Invokes (() => System.Diagnostics.Trace.WriteLine("GetSpecs called!"))
.Returns (new List<JobSpec>
{
new JobSpec("blablabla", "0.125", "something")
});
var manufacturing = A.Fake<IManufacturing> ();
A.CallTo (() => manufacturing.JobAPI)
.Invokes (() => System.Diagnostics.Trace.WriteLine ("JobAPI called!"))
.Returns (jobApi);
Upon running the test, I only see the "JobAPI called" string in the output. So, the GetSpecs() does not get mocked and indeed the caller throws because it expected a list of specs whereas it received an empty string...
What could be the culprit here?
Thanks.
Upvotes: 2
Views: 166
Reputation: 12339
Dammit!
You're gonna laugh, I have!
Turned out that the following line
A.CallTo (() => jobApi.GetSpecs (It.IsAny<string> (), It.IsAny<string> ()))
was not correct for FakeItEasy. It should be written as
A.CallTo (() => jobApi.GetSpecs (A<string>.Ignored, A<string>.Ignored))
So, you may wonder why it did compile and run... Yeah me too. ;)
It.IsAny is for Moq (!)
I had a Using Moq lingering at the top of the class. (I'm in the process of switching to fakeiteasy from moq).
[face palm]
TGIF
Upvotes: 3