Using Moq.It.IsAny to test a string starts with something

try:

logger.Verify(x => x.WriteData(Moq.It.Is<string>(str => str.StartsWith("ABC"))), Times.Exactly(3));

you can see another example of It.Is:

// matching Func<int>, lazy evaluated
mock.Setup(foo => foo.Add(It.Is<int>(i => i % 2 == 0))).Returns(true); 

that comes from Moq documentation: https://github.com/Moq/moq4/wiki/Quickstart

Leave a Comment