I have a class, a service, and two interfaces:
public class MyBasicObject { public MyBasicObject() { } public int Id { get; set; } public string Name { get; set; } } public interface ICacheProvider { T Get<T>(string key, Func<T> fetcher) where T:class; } public interface IMyBasicObjectRepository { MyBasicObject GetByName(string name); } public class MyBasicObjectService { public MyBasicObjectService(ICacheProvider cacheProvider, IMyBasicObjectRepository repository) { CacheProvider = cacheProvider; MyBasicObjectRepository = repository; } public ICacheProvider CacheProvider { get; set; } public IMyBasicObjectRepository MyBasicObjectRepository { get; set; } public MyBasicObject GetByName(string name) { return CacheProvider.Get<MyBasicObject>(name, () => MyBasicObjectRepository.GetByName(name)); } }
Using RhinoMocks, I want to make sure that when MyBasicObjectService.GetByName("AnUniqueName") is executed, CacheProvider.Get("AnUniqueName", () => MyBasicObjectRepository.GetByName("AnUniqueName")) . I have a fixture configured like this:
[TestFixture] public class MyBasicObjectServiceFixture { [Test] public void GetByNameShouldCallCacheProviderFunction() {
I would expect this test to pass, but at the start this statement fails, telling me that the function outlined in cacheProvider.Expect is not called. Did I miss something. bullying and testing methods that accept Func parameters <
Edit:
So if I do:
cacheProvider.Expect(p => p.Get<MyBasicObject>("AnUniqueName", () => repo.GetByName("AnUniqueName"))).IgnoreArguments();
(i.e. add the IgnoreArguments () method at the end of the pending call)
... the test is just fine. I assume this is a problem with the argument passed. Is there something that I am doing wrong while waiting for the cache provider method to call, but it is choking on the anonymous method that is being passed to?
source share