An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

```markdown
# πŸš€ Soenneker Startup Filters Integration Tests

![Version](https://img.shields.io/badge/version-1.0.0-blue.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg) ![Build](https://img.shields.io/badge/build-passing-brightgreen.svg)

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.
```