David, I'd appreciate a way to get an Action matching the signature of
my void method. I could then use it to call methods on the void
method's arguments.
A simplification of my current problem:
public interface IMaintainIndexes {
void RegisterIndex<T>(Predicate<T> criterion);
}
public interface IRegisterIndexes {
void RegisterIndexes(IMaintainIndexes indexer);
}
[TestFixture]
public void TestsIndexer() {
[Test]
public void CriteriaIsCalled() {
bool wasCalled = false;
var indexer = new ConcreteIndexer();
var definer = Substitute.For(IRegisterIndexes);
Func<object, bool> criterion = {
wasCalled = true;
return false;
};
// OnCallOf returns dynamic to achieve the following
definer.OnCallOf.RegisterIndexes(indexer =>
indexer.RegisterIndex<object>(criterion));
indexer.Add(new object());
// WasCalled returns dynamic, too…
definer.WasCalled.RegisterIndexes;
Assert.True(wasCalled);
}
}
The trick is that ConcreteIndexer does not implement IMaintainIndexes.
I might refactor my way around that; I did it to myself because I was
spending too much time fighting one behaviour of generics. It just
occurred to me there's a much simpler way…
Yours,
Garth.