MockResponse.Middleware.LocalFolderStore 8.0.1-preview

This is a prerelease version of MockResponse.Middleware.LocalFolderStore.
There is a newer version of this package available.
See the version list below for details.
dotnet add package MockResponse.Middleware.LocalFolderStore --version 8.0.1-preview
                    
NuGet\Install-Package MockResponse.Middleware.LocalFolderStore -Version 8.0.1-preview
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MockResponse.Middleware.LocalFolderStore" Version="8.0.1-preview" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MockResponse.Middleware.LocalFolderStore" Version="8.0.1-preview" />
                    
Directory.Packages.props
<PackageReference Include="MockResponse.Middleware.LocalFolderStore" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MockResponse.Middleware.LocalFolderStore --version 8.0.1-preview
                    
#r "nuget: MockResponse.Middleware.LocalFolderStore, 8.0.1-preview"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MockResponse.Middleware.LocalFolderStore@8.0.1-preview
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MockResponse.Middleware.LocalFolderStore&version=8.0.1-preview&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=MockResponse.Middleware.LocalFolderStore&version=8.0.1-preview&prerelease
                    
Install as a Cake Tool

<a id="readme-top"></a>

MockResponse.Middleware.LocalFolderStore

.NET License

CI/CD Pipeline CodeQL NuGet - Local Folder Store

This package provides a file system-based implementation for use with the MockResponse.Middleware system. It enables serving mock API responses from a local folder, ideal for testing or offline development scenarios where remote providers like Azure Blob Storage are not feasible.

Table of Contents

๐Ÿ“ฆ Installation

dotnet add package MockResponse.Middleware.LocalFolderStore

<p align="right">(<a href="#readme-top">back to top</a>)</p>

โš™๏ธ Configuration

Specify your local folder path and mock mappings in appsettings.json:

{
  ...
  "MockOptions": {
    "ExcludedRequestPaths": ["/api/health", "/openapi", "/metrics", "/redoc", "/swagger"],
    "LocalFolderStoreOptions": {
      "FolderPath": "Mocks"
    },
    "ResponseMappings": {
      "Namespace.TypeName": "ExampleResponse.json",
      "Namespace.TypeName.Variant": "subfolder/ExampleResponse.Variant.json"
    },
    "UseMock": true
  },
  ...
}

๐Ÿ’ก You can also organize your mock files using subfolders inside the specified FolderPath.

For example, "Namespace.TypeName.Variant": "subfolder/ExampleResponse.Variant.json" will load the file from Mocks/subfolder/ExampleResponse.Variant.json.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

๐Ÿ”ง LocalFolderStoreOptions Configuration

The following configuration property is used by the local folder provider. It should be set under MockOptions:LocalFolderStoreOptions.

Property Type Required Description
FolderPath string โœ… Path to the folder containing mock JSON files. Relative paths are resolved from the application root.

๐Ÿ“ The folder should contain JSON files matching your ResponseMappings. You can also organize files into subfolders for variants or grouping.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

๐Ÿš€ Usage: AddLocalFolderStore

Register the middleware in Startup.cs or Program.cs:

services.AddApiMocking(Configuration)
	.AddLocalFolderStore();

Use the middleware:

app.UseApiMocking();

Place your mock JSON files in the folder specified by FolderPath. Each file is served based on its ResponseMappings key and corresponding HTTP response metadata.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

๐Ÿงช Troubleshooting

Missing Configurations

โš ๏ธ Missing FolderPath

Error Message

LocalFolderStoreOptions.FolderPath must not be null or empty.

Cause

The FolderPath was not specified under MockOptions:LocalFolderStoreOptions, or it was empty.

Solution

Make sure your appsettings.json (or other configuration source) includes a valid path:

{
  "MockOptions": {
    "LocalFolderStoreOptions": {
      "FolderPath": "Mocks"
    }
  }
}

Runtime Errors

โš ๏ธ File not found

Error Message

The mock file 'Mocks/WeatherForecast.json' could not be found.

Cause

The file mapped in ResponseMappings does not exist in the specified folder (or subfolder).

Solution

Verify that the filename and subdirectory (if applicable) exist under the FolderPath. Be sure filenames match exactly (including casing on case-sensitive systems).

๐Ÿ’ก Use relative paths like "subfolder/Example.json" for files inside subdirectories.

๐Ÿ“˜ For additional error handling scenarios, see the Core Troubleshooting Guide.

<p align="right">(<a href="#readme-top">back to top</a>)</p>

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
8.0.1 92 7/29/2025
8.0.1-preview 113 6/26/2025