Warning: fopen(/tmp/SghXTngBZPli-JFP2dv.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-JFP2dv.tmp): No such file or directory in /home/executea/public_html/blog/wp-admin/includes/class-wp-filesystem-ftpext.php on line 142
Site Loader
Auckland, New Zealand
In the last post we discussed how to test number of times a method being called using Moq framework and in this post we will discuss how to track or match the parameters with Moq.

Matching/Tracking parameter

  • Matching/ Tracking argument in Moq is one way to see if the expected arguments is passed in the Application Under Test or not.
  • This feature will greatly help us to test the arguments value being passed to any given method (if its correct or not)
  • Since these values play a important role in flow of our code execution
Here is the complete video of the above discussion Here is the complete code from the 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();

            moqPersonalDetail.Setup(x => x.GraduityEligibleCount).Returns(2);

            var pfDetails = new EmployeesDetails(moqPersonalDetail.Object);

            //Act
            pfDetails.GetGratuityEligibleCount(employees);

            //Assert
            moqPersonalDetail.VerifyGet(x => x.GraduityEligibleCount);
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

Leave a Reply

Your email address will not be published. Required fields are marked *