Warning: fopen(/tmp/SghXTngBZPli-QvXML5.tmp): failed to open stream: Disk quota exceeded in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 139
Warning: unlink(/tmp/SghXTngBZPli-QvXML5.tmp): No such file or directory in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 142
Testing number of times method being called with Moq (Complex)
In the last post we discussed how to test the number of times a methods being called using Moq framework. In this post we will discuss little more complex scenario to test the number of times a method being called with the help of a collection type example.
Here is the complete video discussion
Here is the complete code from above video
List employees = new List()
{
new Employee()
{
EmpId = 1,
Name = "Karthik",
Salary = 4000,
DurationWorked = 24,
Grade = 1,
Email = "karthik@executeautomation.com"
},
new Employee()
{
EmpId = 2,
Name = "Prashanth",
Salary = 7000,
DurationWorked = 30,
Grade = 2,
Email = "prashanth@executeautomation.com"
}
};
//Arrange
var moqPersonalDetail = new Mock();
var empDetails = new EmployeesDetails(moqPersonalDetail.Object);
//Act
empDetails.GetHigherGradeEmployee(employees);
//Assert
moqPersonalDetail.Verify(x => x.GetEmployeeDetails(It.IsAny()),Times.Exactly(employees.Count));
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
Post Author:
Karthik kk
One Reply to “Testing number of times method being called with Moq (Complex)”
Great article.
very useful.
thank you