Site Loader
Auckland, New Zealand
In the last post of this series, we discussed how to track parameters with Moq, and in this post we will discuss how to test properties get and set operations with Moq.

Mocking properties

  • Using Moq we can set a value to the property or get the value out from a property.​
  • This way you can ensure that the code you are working, works as expected while there requires some functionality which is tied with an properties value.​
  • Lets quickly see this in Visual studio
Here is the complete video of the above discussion Here is the complete code of the above video
         List employees = new List()
                new Employee()
                    EmpId = 1,
                    Name = "Karthik",
                    Salary = 4000,
                    DurationWorked = 24,
                    Grade = 1,
                    Email = ""

                new Employee()
                    EmpId = 2,
                    Name = "Prashanth",
                    Salary = 7000,
                    DurationWorked = 30,
                    Grade = 2,
                    Email = ""


            var moqPersonalDetail = new Mock();

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

            var pfDetails = new EmployeesDetails(moqPersonalDetail.Object);


            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 *