All quizzes
Free quiz · 20 questions in the bank

Moq quiz

Test your Moq knowledge with a free interactive quiz — 20 questions with answers and explanations. No signup needed to play.

Question 1/12Score 0

What does `mockRepo.Setup(r => r.GetAllUsers()).Returns(new List<User> { user1, user2 });` demonstrate about controlling collection-returning methods with Moq?

In this round
  1. What does `mockRepo.Setup(r => r.GetAllUsers()).Returns(new List<User> { user1, user2 });` demonstrate about controlling collection-returning methods with Moq?
  2. How would you configure a Moq mock to throw an exception when a specific method is called, to test error-handling logic?
  3. What does mocking a dependency's interface (rather than testing against the real concrete implementation) allow a unit test to achieve?
  4. What does `.Setup()` configure on a Moq mock?
  5. What is Moq?
  6. What is a `MockRepository` in Moq, and when would a test use one instead of creating individual `Mock<T>` instances directly?
  7. What does `.Verify()` let you check on a Moq mock, and why is this useful?
  8. What does chaining multiple `.Setup()` calls for the SAME method but with DIFFERENT specific argument values achieve on a Moq mock?
  9. What is the difference between `Times.Once`, `Times.Never`, and `Times.AtLeastOnce` when used with `.Verify()`?
  10. What is `It.IsAny<T>()` used for within a Moq `.Setup()` or `.Verify()` call?
  11. What is the basic syntax for creating a mock of an interface with Moq?
  12. What is the purpose of `mockRepo.Object` after configuring a Moq mock?
Gaps to close?
Read the curated Moq notes — core concepts, patterns, interview prep.
Moq notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web