I want to write an UnitTest with Moq 4.14.7. The method to be tested is as follows:
public IFoo Get(Guid id)
{
Func<IFoo> getData = () => _repository.Get(id);
if (_cache.TryGetAndSet(vaultId, getData, out var result))
{
return result;
}
}
To briefly explain. I have a generic cache class. It checks in the cache if an entity with the passed guid exists. If this is not the case, the repository is called.
Now I have the following setup for the cache:
_cache.Setup
(
x => x.TryGetAndSet
(
_vaultId,
It.IsAny<Func<IFoo>>(),
out foo
)
)
.Returns(true);
The test works so far, but I do not achieve 100% coverage with it, because the func is not covered.
Is there a better way here than to work with It.IsAny and get 100% coverage?