Site Loader
Auckland, New Zealand
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)”

Leave a Reply

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