Junior — Middle
Can you explain what the term MOQ means in the context of business or programming?
sobes.tech AI
Answer from AI
MOQ is a popular library for creating mock objects in testing in C#. It allows simulating the behavior of dependencies to test individual components in isolation.
Main features of MOQ:
- Creating stubs (mocks) of interfaces and classes.
- Configuring expected method calls and their return values.
- Checking whether certain methods were called with the required parameters.
Example of usage:
var mock = new Mock<IRepository>();
mock.Setup(repo => repo.GetById(1)).Returns(new User { Id = 1, Name = "John" });
var user = mock.Object.GetById(1);
// user.Name will be "John"
MOQ helps write clean and reliable unit tests by isolating the tested code from external dependencies.