In the last post we discussed how we can create a simple Moq test. In this post we will try to set expected return value. Using Moq we can set the return value for a function and we can then use the moq function to pass into any function of our Application under test which expects the return value
Here is the complete video of the above discussion
Here is the complete code of the above video
//Arrange
var moqEmpPersonalDetails = new Mock();
moqEmpPersonalDetails.Setup(x => x.GetEmployeeSalary(It.IsAny()))
.Returns(() => 5000);
var pfDetails = new EmpPfDetails(moqEmpPersonalDetails.Object);
//Act
var isEligible = pfDetails.IsPfEligible(It.IsAny());
//Assert
Assert.IsTrue(isEligible,"Should be true");
Thanks for reading the post and watching the video!!!
Please leave your comments and let me know if there is anything I should update in this post.
Thanks,
Karthik KK