Enigmatry.Entry.AspNetCore.Tests.Utilities
9.1.1-preview.4
See the version list below for details.
dotnet add package Enigmatry.Entry.AspNetCore.Tests.Utilities --version 9.1.1-preview.4
NuGet\Install-Package Enigmatry.Entry.AspNetCore.Tests.Utilities -Version 9.1.1-preview.4
<PackageReference Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="9.1.1-preview.4" />
<PackageVersion Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" Version="9.1.1-preview.4" />
<PackageReference Include="Enigmatry.Entry.AspNetCore.Tests.Utilities" />
paket add Enigmatry.Entry.AspNetCore.Tests.Utilities --version 9.1.1-preview.4
#r "nuget: Enigmatry.Entry.AspNetCore.Tests.Utilities, 9.1.1-preview.4"
#:package Enigmatry.Entry.AspNetCore.Tests.Utilities@9.1.1-preview.4
#addin nuget:?package=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=9.1.1-preview.4&prerelease
#tool nuget:?package=Enigmatry.Entry.AspNetCore.Tests.Utilities&version=9.1.1-preview.4&prerelease
ASP.NET Core Tests Utilities
A library that provides testing utilities and helpers for ASP.NET Core applications, making it easier to write clean, effective tests for web applications and APIs.
Intended Usage
Use this library when you need to write tests for ASP.NET Core applications. It provides utilities for mocking HTTP contexts, working with controllers, testing middleware, and more.
Installation
Add the package to your project:
dotnet add package Enigmatry.Entry.AspNetCore.Tests.Utilities
Usage Example
Testing exception handling in a controller:
using Enigmatry.Entry.AspNetCore.Tests;
using Enigmatry.Entry.AspNetCore.Filters;
using Microsoft.AspNetCore.Mvc;
using NUnit.Framework;
using FakeItEasy;
using FluentValidation;
[TestFixture]
public class ExceptionHandlingTests
{ [Test]
public void HandleExceptionsFilter_ShouldReturnBadRequest_WhenValidationExceptionOccurs()
{
// Arrange
var exceptionContext = ExceptionContextBuilder.Create()
.WithValidationException()
.WithJsonRequest()
.Build();
var filter = new HandleExceptionsFilter();
// Act
filter.OnException(exceptionContext);
// Assert var result = exceptionContext.Result as BadRequestObjectResult;
Assert.That(result, Is.Not.Null);
Assert.That(result.Value, Is.Not.Null);
}
}
Testing HTTP contexts:
using Enigmatry.Entry.AspNetCore.Tests;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Diagnostics;
using NUnit.Framework;
[TestFixture]
public class HttpContextTests
{ [Test]
public void HttpContextBuilder_ShouldCreateValidContext_WithException()
{
// Arrange
var exception = new InvalidOperationException("Test exception");
// Act
var context = HttpContextBuilder.Create()
.With(exception)
.Build();
// Assert
var feature = context.Features.Get<IExceptionHandlerPathFeature>();
Assert.That(feature, Is.Not.Null);
Assert.That(feature.Error.Message, Is.EqualTo("Test exception"));
Assert.That(context.Request.Headers["Accept"], Is.EqualTo("application/json"));
}
}
Service Scope Example
using Enigmatry.Entry.AspNetCore.Tests.Utilities;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
[TestFixture]
public class ServiceTests
{ [Test]
public void ServiceScope_ResolvesService_Successfully()
{
// Arrange
var services = new ServiceCollection();
services.AddScoped<IMyService, MyService>();
var provider = services.BuildServiceProvider();
// Act
using var scope = provider.CreateScope();
var service = scope.Resolve<IMyService>();
// Assert
Assert.That(service, Is.Not.Null);
Assert.That(service, Is.TypeOf<MyService>());
}
}
Database Utilities Example
using Enigmatry.Entry.AspNetCore.Tests.Utilities.Database;
using Microsoft.Data.SqlClient;
using NUnit.Framework;
[TestFixture]
public class DatabaseTests
{ [Test]
public void DatabaseHelpers_ProvidesDropAllSql()
{
// Arrange
var connectionString = "Server=(localdb)\\MSSQLLocalDB;Database=TestDb;Integrated Security=true";
// Act & Assert
Assert.NotNull(DatabaseHelpers.DropAllSql);
// Example of how you might use it in a real test
// using var connection = new SqlConnection(connectionString);
// connection.Open();
// var command = new SqlCommand(DatabaseHelpers.DropAllSql, connection);
// command.ExecuteNonQuery();
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. 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. |
-
net9.0
- Enigmatry.Entry.Core (>= 9.1.1-preview.4)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Shouldly (>= 4.3.0)
- System.Net.Http.Json (>= 9.0.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Enigmatry.Entry.AspNetCore.Tests.Utilities:
Package | Downloads |
---|---|
Enigmatry.Entry.AspNetCore.Tests.SystemTextJson
Building Block for writing tests in an Entry AspNetCore based project with SystemText Json |
|
Enigmatry.Entry.AspNetCore.Tests.NewtonsoftJson
Building Block for writing tests in an Entry AspNetCore based project with Newtonsoft Json |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
9.1.1-preview.5 | 141 | 8/8/2025 |
9.1.1-preview.4 | 83 | 6/27/2025 |
9.1.1-preview.3 | 124 | 6/4/2025 |
9.1.0 | 418 | 6/3/2025 |
9.0.1-preview.8 | 124 | 5/26/2025 |
9.0.1-preview.7 | 211 | 5/13/2025 |
9.0.1-preview.6 | 224 | 5/9/2025 |
9.0.1-preview.5 | 148 | 5/7/2025 |
9.0.1-preview.4 | 120 | 4/30/2025 |
9.0.1-preview.2 | 132 | 4/1/2025 |
9.0.0 | 1,004 | 2/26/2025 |
8.1.1-preview.3 | 118 | 5/7/2025 |
8.1.1-preview.1 | 129 | 4/1/2025 |
8.1.0 | 493 | 2/19/2025 |
8.0.1-preview.4 | 74 | 2/7/2025 |
8.0.1-preview.2 | 58 | 1/15/2025 |
8.0.0 | 990 | 11/27/2024 |
3.4.6-preview.10 | 68 | 11/27/2024 |
3.4.3 | 1,941 | 10/22/2024 |
3.4.2 | 2,093 | 10/11/2024 |
3.4.1 | 154 | 10/9/2024 |
3.4.0 | 140 | 10/9/2024 |
3.3.2 | 499 | 8/28/2024 |
3.3.2-preview.7 | 90 | 8/27/2024 |
3.3.1 | 426 | 7/16/2024 |
3.3.1-preview.4 | 71 | 7/12/2024 |
3.3.0 | 1,132 | 6/20/2024 |
3.2.1-preview.4 | 66 | 6/17/2024 |
3.2.1-preview.1 | 75 | 5/23/2024 |
3.2.0 | 4,034 | 4/3/2024 |
3.1.1-preview.1 | 1,017 | 3/13/2024 |
3.1.0 | 367 | 3/8/2024 |
3.1.0-preview.2 | 305 | 2/19/2024 |
3.0.1-preview.2 | 918 | 2/9/2024 |
3.0.1-preview.1 | 84 | 1/24/2024 |
3.0.0 | 992 | 1/15/2024 |
3.0.0-preview.14 | 130 | 1/9/2024 |
3.0.0-preview.12 | 80 | 1/9/2024 |
3.0.0-preview.5 | 69 | 1/10/2024 |
3.0.0-preview.2 | 138 | 12/28/2023 |
3.0.0-preview | 174 | 12/20/2023 |
2.1.0 | 228 | 12/28/2023 |
2.0.1-preview.3 | 106 | 12/1/2023 |
2.0.1-preview.2 | 86 | 11/29/2023 |
2.0.1-preview.1 | 86 | 11/28/2023 |
2.0.0 | 362 | 11/8/2023 |
2.0.0-preview.3 | 286 | 10/27/2023 |
2.0.0-preview.2 | 92 | 10/27/2023 |
2.0.0-preview.1 | 96 | 10/27/2023 |
2.0.0-preview | 174 | 10/27/2023 |
1.1.500 | 210 | 10/27/2023 |
1.1.495 | 269 | 9/24/2023 |
1.1.486 | 513 | 9/13/2023 |
1.1.484 | 306 | 9/7/2023 |
1.1.482 | 250 | 9/6/2023 |
1.1.480 | 340 | 8/24/2023 |
1.1.477 | 476 | 8/2/2023 |
1.1.464 | 317 | 7/5/2023 |
1.1.447 | 763 | 5/26/2023 |
1.1.396 | 443 | 4/11/2023 |
1.1.383 | 392 | 4/3/2023 |
1.1.377 | 394 | 3/13/2023 |
1.1.376 | 554 | 3/13/2023 |