I have a problem mocking an interface with an (async) method. The Interface looks like this:
public interface IDataAccessLayer
{
Task<bool> ExistsUserAsync(string username, CancellationToken cancellationToken);
Task<IUser> CreateUserAsync(string username, string password, DateTime dateOfBirth, CancellationToken cancellationToken);
}
.. the cancellationToken parameter up there is always created and passed in from the outside during runtime (via NancyFx), and when mocking the calls inside a test method like this:
var validSignupRequest = new UserSignupRequest()
{
Username = "meh-spacey_space",
DateOfBirth = DateTime.Now.Subtract(TimeSpan.FromDays(365*35)),
Password = "someproper_passw*rd"
};
var testDataAccessLayer = A.Fake<IDataAccessLayer>(options => options.Strict());
var fakeUserInstance = A.Fake<IUser>();
A.CallTo(() => fakeUserInstance.Username).Returns(validSignupRequest.Username);
A.CallTo(() => testDataAccessLayer.ExistsUserAsync(validSignupRequest.Username, CancellationToken.None)).Returns(false); // works
A.CallTo(() => testDataAccessLayer.CreateUserAsync(validSignupRequest.Username, validSignupRequest.Password, validSignupRequest.DateOfBirth, CancellationToken.None)).Returns(fakeUserInstance); // does not work / throws ExpectationException
.. the mocked call to .ExistsUserAsync(...) does work, the .CreateUserAsync one does not work / throws an ExpectationException.
I've checked the underlying code that is being tested and the call is being made using the same values to the .CreateUserAsync(...) method are used & I suspected the dateOfBirth being the culprit, but at least .Ticks wise it is exactly the same.
I am a bit uncertain as to how FakeItEasy performs the signature / parameter value matching because in theory that call IS mocked, but FakeItEasy says it is not. So far it is winning..
Does anyone know what's wrong in my method mocking call(s) up there?