https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests
A StartupFilter injecting middleware crucial to integration testing
https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests
csharp dotnet filter fixture integration integrations integrationtests integrationtestsstartupfilter startup startupfilter startupfilters tests util
Last synced: about 1 year ago
JSON representation
A StartupFilter injecting middleware crucial to integration testing
- Host: GitHub
- URL: https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests
- Owner: chrom4kdkks
- License: mit
- Created: 2025-04-04T13:40:51.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-10T04:01:43.000Z (about 1 year ago)
- Last Synced: 2025-04-10T04:15:21.241Z (about 1 year ago)
- Topics: csharp, dotnet, filter, fixture, integration, integrations, integrationtests, integrationtestsstartupfilter, startup, startupfilter, startupfilters, tests, util
- Language: C#
- Size: 32.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
```markdown
# π Soenneker Startup Filters Integration Tests
  
Welcome to the **Soenneker Startup Filters Integration Tests** repository! This project provides essential middleware for integration testing in C# applications using the .NET framework. The middleware allows developers to easily manage and test various components of their applications during startup, ensuring a robust testing environment.
## π¦ Overview
The main purpose of this repository is to facilitate integration testing by providing a specialized startup filter that can be injected into the middleware pipeline. This enables developers to set up fixtures and execute integration tests smoothly.
## π Features
- Easy integration with existing .NET applications.
- Simplified management of middleware for testing.
- Configurable startup filters to meet diverse testing needs.
- Support for various testing scenarios, including unit tests and functional tests.
## π Table of Contents
- [Getting Started](#getting-started)
- [Installation](#installation)
- [Usage](#usage)
- [Examples](#examples)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)
## π Getting Started
To get started with **Soenneker Startup Filters Integration Tests**, follow these steps:
1. **Clone the Repository**
```bash
git clone https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests.git
```
2. **Navigate to the Project Directory**
```bash
cd soenneker.startupfilters.integrationtests
```
3. **Restore Dependencies**
Run the following command to restore the required packages:
```bash
dotnet restore
```
## π Installation
To install the middleware, use the NuGet package manager. Execute the following command:
```bash
dotnet add package Soenneker.StartupFilters
```
Alternatively, you can download the latest release from our [Releases page](https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests/releases) and follow the instructions in the README file provided in the release.
## π§ Usage
Integrating the startup filter is straightforward. Add the filter to your middleware configuration during application startup. Hereβs how you can do it:
1. **Modify `Startup.cs`**
Open your `Startup.cs` file and add the filter:
```csharp
public void ConfigureServices(IServiceCollection services)
{
services.AddStartupFilter();
}
```
2. **Create Your Custom Filter**
Create a class that implements the `IStartupFilter` interface:
```csharp
public class MyCustomStartupFilter : IStartupFilter
{
public Action Configure(Action next)
{
return builder =>
{
// Custom middleware logic here
next(builder);
};
}
}
```
3. **Run Your Application**
Once you've configured the startup filter, run your application:
```bash
dotnet run
```
## π Examples
Here are some example scenarios using the startup filter:
### Example 1: Simple Middleware
Create a simple middleware to log requests:
```csharp
public class RequestLoggingMiddleware
{
private readonly RequestDelegate _next;
public RequestLoggingMiddleware(RequestDelegate next)
{
_next = next;
}
public async Task InvokeAsync(HttpContext context)
{
Console.WriteLine($"Incoming request: {context.Request.Path}");
await _next(context);
}
}
```
Then, use the middleware in your startup filter:
```csharp
public class LoggingStartupFilter : IStartupFilter
{
public Action Configure(Action next)
{
return builder =>
{
builder.UseMiddleware();
next(builder);
};
}
}
```
### Example 2: Configuration-based Middleware
Suppose you want to conditionally enable middleware based on configuration settings:
```csharp
public class ConfigurableMiddleware
{
private readonly RequestDelegate _next;
private readonly bool _isEnabled;
public ConfigurableMiddleware(RequestDelegate next, bool isEnabled)
{
_next = next;
_isEnabled = isEnabled;
}
public async Task InvokeAsync(HttpContext context)
{
if (_isEnabled)
{
Console.WriteLine("Configurable middleware is active.");
}
await _next(context);
}
}
```
Use it in your startup filter like this:
```csharp
public class ConfigurableStartupFilter : IStartupFilter
{
private readonly IConfiguration _configuration;
public ConfigurableStartupFilter(IConfiguration configuration)
{
_configuration = configuration;
}
public Action Configure(Action next)
{
var isEnabled = _configuration.GetValue("Middleware:ConfigurableMiddleware");
return builder =>
{
builder.UseMiddleware(isEnabled);
next(builder);
};
}
}
```
## π€ Contributing
Contributions are welcome! If you wish to enhance this project or fix issues, please follow these steps:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature/YourFeature`).
3. Make your changes.
4. Commit your changes (`git commit -m 'Add some feature'`).
5. Push to the branch (`git push origin feature/YourFeature`).
6. Open a pull request.
Please ensure your code follows the projectβs style guidelines and is well-tested.
## π License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## π« Contact
For any questions or suggestions, please contact the maintainer:
- GitHub: [chrom4kdkks](https://github.com/chrom4kdkks)
- Email: your_email@example.com
Feel free to open an issue if you encounter any problems or have feature requests.
## π· Topics
- C#
- .NET
- Filter
- Fixture
- Integration Testing
- Middleware
- Startup Filters
- Tests
Thank you for visiting the **Soenneker Startup Filters Integration Tests** repository! We hope you find it useful for your integration testing needs. For more information, check our [Releases section](https://github.com/chrom4kdkks/soenneker.startupfilters.integrationtests/releases) for the latest updates and downloads.
```