Tutorial by Examples

interface Mockable { bool DoSomething(); } var mock = new Mock<Mockable>(); mock.Setup(x => x.DoSomething()).Returns(true); var result = mock.Object.DoSomething(); //true
var logRepository = new Mock<ILogRepository>(); logRepository.Setup(x => x.Write(It.IsAny<Exception>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())) .Verifiable(); In this case, we are using t...
To mock a protected member you must first include the following at the top of your test fixture: using Moq.Protected; You then call Protected() on your mock, after which you can use the generic Setup<> with the return type of your method. var mock = new Mock<MyClass>(); mock.Protec...

Page 1 of 1