Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions CR.Exceptions.Tests.Shared/CR.Exceptions.Tests.Shared.csproj

This file was deleted.

10 changes: 0 additions & 10 deletions CR.Exceptions.Tests.Shared/TestInternalException.cs

This file was deleted.

10 changes: 0 additions & 10 deletions CR.Exceptions.Tests.Shared/TestNotFoundException.cs

This file was deleted.

10 changes: 0 additions & 10 deletions CR.Exceptions.Tests.Shared/TestUnknownException.cs

This file was deleted.

15 changes: 0 additions & 15 deletions CR.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs

This file was deleted.

10 changes: 0 additions & 10 deletions CR.Exceptions.slnx

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/ConflictException.cs

This file was deleted.

15 changes: 0 additions & 15 deletions CR.Exceptions/CrException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/ForbiddenException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/InternalException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/NotFoundException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/UnauthorizedException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/UnprocessableException.cs

This file was deleted.

16 changes: 0 additions & 16 deletions CR.Exceptions/ValidationException.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using CR.Exceptions.Tests.Shared;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System.Diagnostics;
using System.Text.Json;

namespace CR.Exceptions.AspNet.Tests.Component;
namespace Cr.Exceptions.AspNetCore.Tests.Component;

public sealed class CrExceptionHandlerTests
{
Expand All @@ -23,7 +22,7 @@ public CrExceptionHandlerTests(ITestOutputHelper output)
public Task Should_Return_404_For_NotFoundException()
{
return AssertHandlerResult(
new TestNotFoundException(),
new NotFoundException(),
StatusCodes.Status404NotFound,
canCreateActivity: true);
}
Expand Down Expand Up @@ -74,10 +73,10 @@ private async Task AssertHandlerResult(Exception exception, int expectedStatusCo
private static void AssertHttpContext(HttpContext context, int expectedStatusCode)
{
Assert.Equal(expectedStatusCode, context.Response.StatusCode);
Assert.Contains("application/problem+json", context.Response.ContentType);
Assert.Contains(System.Net.Mime.MediaTypeNames.Application.ProblemJson, context.Response.ContentType);
}

private static void AssertProblemDetails(TestProblemDetails? problem, int expectedStatusCode, string? expectedTraceId)
private static void AssertProblemDetails(TestProblemDetails? problem, int expectedStatusCode, string expectedTraceId)
{
Assert.NotNull(problem);

Expand All @@ -90,14 +89,13 @@ private static void AssertProblemDetails(TestProblemDetails? problem, int expect
Assert.Equal(expectedTraceId, traceId!.ToString());

Assert.NotNull(problem.Errors);
Assert.NotEmpty(problem.Errors);
}

private static ServiceProvider CreateServiceProvider()
{
return new ServiceCollection()
.AddLogging()
.AddCrExceptionsCore()
.AddCrExceptions()
.BuildServiceProvider();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using CR.Exceptions.Tests.Shared;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging;

namespace CR.Exceptions.AspNet.Tests.Component;
namespace Cr.Exceptions.AspNetCore.Tests.Component;

public sealed class LogLevelMapTests
{
private const LogLevel ExpectedLogLevel = LogLevel.Warning;
private static readonly TestInternalException ExistentException = new();
private static readonly TestUnknownException NonExistentException = new();
private static readonly InternalException ExistentException = new();
private static readonly CrException NonExistentException = new();

[Fact]
public void TryFind_ShouldReturn_TrueAndLevel_WhenExceptionExists()
Expand All @@ -32,7 +31,7 @@ public void TryFind_ShouldReturn_FalseAndDefault_WhenExceptionDoesNotExist()
private static LogLevelMap GetDefaultMap()
{
return new LogLevelMapBuilder()
.Map<TestInternalException>(ExpectedLogLevel)
.Map<InternalException>(ExpectedLogLevel)
.Build();
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
using CR.Exceptions.Tests.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http;

namespace CR.Exceptions.AspNet.Tests.Component;
namespace Cr.Exceptions.AspNetCore.Tests.Component;

public sealed class StatusCodeMapTests
{
private const int ExpectedStatusCode = StatusCodes.Status500InternalServerError;
private static readonly TestInternalException ExistentException = new();
private static readonly TestUnknownException NonExistentException = new();
private static readonly InternalException ExistentException = new();
private static readonly CrException NonExistentException = new();

[Fact]
public void TryFind_ShouldReturn_TrueAndCode_WhenExceptionExists()
Expand All @@ -32,7 +31,7 @@ public void TryFind_ShouldReturn_FalseAndDefault_WhenExceptionDoesNotExist()
private static StatusCodeMap GetDefaultMap()
{
return new StatusCodeMapBuilder()
.Map<TestInternalException>(ExpectedStatusCode)
.Map<InternalException>(ExpectedStatusCode)
.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CR.Exceptions.Tests.Shared\CR.Exceptions.Tests.Shared.csproj" />
<ProjectReference Include="..\Cr.Exceptions.AspNetCore\Cr.Exceptions.AspNetCore.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.Extensions.Logging;

namespace CR.Exceptions.AspNet.Tests.Unit;
namespace Cr.Exceptions.AspNetCore.Tests.Unit;

public sealed class LogLevelMapBuilderTests
{
Expand All @@ -10,23 +10,23 @@ public void Map_ShouldThrow_When_DuplicateLevelRegistered()
var builder = CreateBuilder()
.Map<InternalException>(LogLevel.Error);

Assert.ThrowsAny<ArgumentException>(() => builder.Map<InternalException>(LogLevel.Warning));
Assert.Throws<ArgumentException>(() => builder.Map<InternalException>(LogLevel.Warning));
}

[Fact]
public void Map_ShouldThrow_When_InvalidLevelRegistered()
{
var builder = CreateBuilder();

Assert.ThrowsAny<ArgumentException>(() => builder.Map<ConflictException>((LogLevel)4000));
Assert.Throws<ArgumentOutOfRangeException>(() => builder.Map<ConflictException>((LogLevel)4000));
}

[Fact]
public void Map_ShouldThrow_When_NoneLevelRegistered()
{
var builder = CreateBuilder();

Assert.ThrowsAny<ArgumentException>(() => builder.Map<ConflictException>(LogLevel.None));
Assert.Throws<ArgumentException>(() => builder.Map<ConflictException>(LogLevel.None));
}

[Fact]
Expand Down
Loading
Loading