Hi guys i have this code,
public class Demo { public interface IFoo { int Bar(string arg); } [Test] public void TestFoo() { var foo = new Mock<IFoo>(); foo.Setup(f => f.Bar("aaa")).Returns(1); foo.Setup(f => f.Bar("bbb")).Returns(2); // foo.Setup(f => f.Bar(It.IsAny<string>())).Returns(3); //instead of the previous line, I would go with something like this: //foo.Setup(f => f.Bar(It.IsAnyOther<string>())).Returns(3); //With the current setup, these first two asserts are gonna fail, //because It.IsAny<string>() is going to match for any string argument.... Assert.AreEqual(1, foo.Object.Bar("aaa")); Assert.AreEqual(2, foo.Object.Bar("bbb")); Assert.AreEqual(3, foo.Object.Bar("ccc")); } }
What I want, is to provide a default result for any invocation that does not match against the specified setup. I know if I remove It.IsAny<string> I'll get the default value of the method's return type, which in the sample above will be 0, but I want to be 3. Is there any hack or known workaround to do that? Thanks!
--
--
Post: moq...@googlegroups.com
Unsubscribe: moqdisc-u...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "Moq Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to moqdisc+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks, worked like a charm!