Skip to content

Instantly share code, notes, and snippets.

@craigeddy
Last active June 2, 2024 15:15
Show Gist options
  • Save craigeddy/fc2b8c6713ccb4b0d016ecfc7044c09b to your computer and use it in GitHub Desktop.
Save craigeddy/fc2b8c6713ccb4b0d016ecfc7044c09b to your computer and use it in GitHub Desktop.
var mockConfiguration = new Mock<IConfiguration>();
// Set up the GetSection method to return a Mock<IConfigurationSection>
mockConfiguration.Setup(config => config.GetSection(It.IsAny<string>()))
.Returns(new Mock<IConfigurationSection>().Object); // returns a new Mock IConfigurationSection object
// Set up the Value property of the IConfigurationSection to return a specific value
mockConfiguration.Setup(config => config[It.IsAny<string>()])
.Returns("YourValue"); // returns "YourValue"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment