© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
66 replies
joren

❔ ✅ Verifying the purpose of Moq usage

mockDatabase.Setup(db => db.GetUserName(It.IsAny<int>()))
    .Returns((int userId) => "User" + userId);
mockDatabase.Setup(db => db.GetUserName(It.IsAny<int>()))
    .Returns((int userId) => "User" + userId);

So, as you can see I use
It.IsAny<int>()
It.IsAny<int>()
to mimic a value that would be passed, since
GetUserName()
GetUserName()
requres an integer passed as argument.

However this value is not used in the actual mock, but rather the
string result = userManager.GetUserDisplayName(42);
string result = userManager.GetUserDisplayName(42);

the
42
42
that is passed here, which then calls
GetUserName()
GetUserName()
inside of it.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements
Next page

Similar Threads

✅ What is the purpose of `[FromServices]`
C#CC# / help
3y ago
What's the purpose of MarshalByRefObject?
C#CC# / help
4y ago
learning moq framework
C#CC# / help
2y ago
Purpose of Dependency Injection
C#CC# / help
2y ago