There is a function:
public class MyCacheClass : ICache
{
public void T GetObject<T>(Func<T> func)
{
T t;
...
t = func();
...
return t;
}
}
public class MyWorkClass : IWork
{
public Object MyWorkMethod(string value)
{
return new object();
}
}
These functions are been called in the following way:
public class MyTestableClass
{
public void MyTestableFunc(ICache cache, IWorkClass work)
{
string strVal="...";
...
Object obj = cache(()=>work.MyWorkMethod(strVal));
...
}
}
It is necessary to write a UnitTest (with Moq) for that and check if proper parameter as passing into 'MaCacheClass.GetObject'.
It should be something like this:
[TestMethod]
public void MyTest()
{
Mock<ICache> mockCache = new Mock<ICache>();
Mock<IWorkClass> mockWorkClass = new Mock<IWorkClass>();
MyTestableClass testable = new MyTestableClass();
testable.MyTestableFunc(mockCache.Object, mockWorkClass.Object);
// should I check if 'MyCacheClass' was called with proper parameter?
mockCache.Verify(mock=>mock.GetObject(...)).Times.Once());
}
How could I provide parameter that will fit as 'lambda-function'? Are there any other options?
Any thoughts are welcome.