This is a little sample application showing who to Fake application setting in a configuration object during unit testing.
There are a lot of published ways to solve the issue of running unit test on class that inject an IConfiguration object holding application settings. This is a new way I came across recently and want to create a sample project showing how to use it.
-
Clone this repository
git clone https://github.com/CodingWithDavid/MockIConfigurationForTesting cd MockIConfigurationForTesting
-
Open in Visual Studio or Visual Code a. With Visual Code you will need to install the C# extensions b. With Visual Code you will need to install the Blazor extensions
-
Press F5
- Blazor application that I have refactored the WeatherForecastService to inject a configuration. This service has a new method on it that will retrieve the value of the app setting.
- Unit test project with a test class for the Weather Forecast Service a. The test class shows how to use the new method for faking the IConfiguration object