All quizzes
Free quiz · 20 questions in the bank

NSubstitute quiz

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

Question 1/5Score 0

How would a test using NSubstitute typically verify that a method was called with an argument matching a specific object's properties, without needing that argument to be the EXACT same object reference?

Questions in this quiz
  1. How would a test using NSubstitute typically verify that a method was called with an argument matching a specific object's properties, without needing that argument to be the EXACT same object reference?
  2. What does `DidNotReceive()` let a test verify in NSubstitute?
  3. What is the purpose of `Received(n)` (with a specific call count argument) in NSubstitute, as opposed to plain `Received()`?
  4. What is the basic syntax for creating a substitute of an interface with NSubstitute?
  5. What does the term "substitute" specifically emphasize about NSubstitute's naming/design philosophy, compared to the more common industry term "mock"?
  6. What is the purpose of `.Returns()` accepting a callback function (rather than a static value) in NSubstitute, e.g. `repo.GetUserById(Arg.Any<int>()).Returns(x => new User { Id = x.Arg<int>() });`?
  7. How would you configure an NSubstitute substitute to throw an exception when a method is called, to test error-handling logic?
  8. How do you verify that a specific method was called on an NSubstitute substitute?
  9. What is the significance of NSubstitute requiring the mocked member to be an interface member, or a virtual/abstract class member -- similar to the constraint other .NET mocking libraries like Moq share?
  10. What is `Arg.Any<T>()` used for in NSubstitute?
  11. What is `Arg.Is<T>()` used for as a more specific alternative to `Arg.Any<T>()` in NSubstitute?
  12. What is the significance of NSubstitute (like other .NET mocking libraries) being commonly paired with dependency injection as a design pattern in the code under test?
Gaps to close?
Read the curated NSubstitute notes — core concepts, patterns, interview prep.
NSubstitute notes

More quizzes

.NET.NET MAUIAbsintheAccessibilityActixActix Web