Here is my attempt to mock the interface (I actually want to return a value, but throw just to make it easier to identify):
Here is the method signature of FindLdapUserEmailsInGroup:
The pertinent part of the cachefactory interface:
The pertinent part of ICache:
I'm not sure where I am going wrong. I have tried several permutations of the dependencies object (using null, default etc), and I'm not sure what could be wrong with the Func<Dictionary<string,string>> arg but nothing I have done so far is getting the arrange to take effect. Any guidance is appreciated.
var cache = Mock.Create<ICache>();
_cacheFactoryMock.Arrange(m => m.Application).Returns(cache);
cache.Arrange(m => m.GetOrAdd(Arg.AnyString, Arg.IsAny<Func<Dictionary<
string
,
string
>>>, Arg.IsAny<DateTime>(), Arg.IsAny<TimeSpan>(),
null
)).Throws(
new
DivideByZeroException());
Here is the invocation:return
_caches.Application.GetOrAdd(
string
.Format(CacheKeyFormat, groupName),
() => _ldapService.FindLdapUserEmailsInGroup(groupName),
DateTime.Now.AddDays(1),
Cache.NoSlidingExpiration
);
Here is the method signature of FindLdapUserEmailsInGroup:
Dictionary<
string
,
string
> FindLdapUserEmailsInGroup(
string
groupName);
The pertinent part of the cachefactory interface:
public
interface
ICacheFactory
{
ICache Application {
get
; }
}
The pertinent part of ICache:
public
interface
ICache
{
TItem GetOrAdd<TItem, TState>(
string
key, Func<TState, TItem> getValue, TState state, DateTime absoluteExpiration, TimeSpan slidingExpiration,
object
dependencies =
default
(
object
));
TItem GetOrAdd<TItem>(
string
key, Func<TItem> getValue, DateTime absoluteExpiration, TimeSpan slidingExpiration,
object
dependencies =
default
(
object
));
}
I'm not sure where I am going wrong. I have tried several permutations of the dependencies object (using null, default etc), and I'm not sure what could be wrong with the Func<Dictionary<string,string>> arg but nothing I have done so far is getting the arrange to take effect. Any guidance is appreciated.