var mock = new Mock(); mock.Setup(x => x.DoSomething()).Returns(true); var result = mock.Object.DoSomething(); Assert.True(result);
var mock = new Mock(); mock.Setup(x => x.DoSomething(It.IsAny (), It.IsAny ())).Returns(true); var result = mock.Object.DoSomething("foo", 42); Assert.True(result);
var mock = new MockIn this example, we set up an expectation for the DoSomething method with a parameter of type Person, which is a complex object. We then create a new Person object and call the method on the mock object with it as a parameter, verifying that it returns the expected value. The Moq library is available via the Moq package on NuGet.(); mock.Setup(x => x.DoSomething(It.IsAny ())).Returns(true); var person = new Person { FirstName = "John", LastName = "Doe", Age = 30 }; var result = mock.Object.DoSomething(person); Assert.True(result);