Tuesday, April 5, 2011

Mock set indexer in Moq

I can do:

var req = new Mock<HttpRequestBase>();
var vals = new Dictionary<string, string>();

req.Expect(r => r[It.IsAny<string>()])
    .Returns(s => vals[s]);

But what about something like this ???

req.ExpectSet(r => r[It.IsAny<string>()], It.IsAny<string>())
    .Callback((s, v) => vals[s] = v);
From stackoverflow
  • I don't believe so, I had to use Expect over ExpectSet when accessing indexers.

    Chris Porter : Can you show an example please ?

0 comments:

Post a Comment