From 356f3729fd02690a04db5d17e4866f6d353444b8 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 13:24:25 +0300 Subject: [PATCH 01/15] Renaming --- CR.Exceptions.slnx | 10 ---------- .../Component/CrExceptionHandlerTests.cs | 4 ++-- .../Component/LogLevelMapTests.cs | 4 ++-- .../Component/StatusCodeMapTests.cs | 4 ++-- .../Cr.Exceptions.AspNetCore.Tests.csproj | 4 ++-- .../Unit/LogLevelMapBuilderTests.cs | 2 +- .../Unit/StatusCodeMapBuilderTests.cs | 2 +- .../Cr.Exceptions.AspNetCore.csproj | 10 +++++----- .../CrExceptionHandler.cs | 2 +- .../CrExceptionHandlerLogExtensions.cs | 2 +- .../Mapping/LogLevelMap.cs | 2 +- .../Mapping/LogLevelMapBuilder.cs | 2 +- .../Mapping/LogLevelMapBuilderExtensions.cs | 2 +- .../Mapping/StatusCodeMap.cs | 2 +- .../Mapping/StatusCodeMapBuilder.cs | 2 +- .../Mapping/StatusCodeMapBuilderExtensions.cs | 2 +- .../ProblemDetailsExtensionNames.cs | 2 +- .../README.md | 0 .../ServiceCollectionExtensions.cs | 2 +- .../Cr.Exceptions.Tests.Shared.csproj | 2 +- .../TestInternalException.cs | 2 +- .../TestNotFoundException.cs | 2 +- .../TestUnknownException.cs | 2 +- .../Component/ExceptionFactoryTests.cs | 4 ++-- .../Component/ExceptionTranslatorTests.cs | 4 ++-- .../Cr.Exceptions.Tests.csproj | 2 +- .../Unit/ExceptionFactoryBuilderTests.cs | 4 ++-- .../Unit/ExceptionTranslatorBuilderTests.cs | 4 ++-- Cr.Exceptions.slnx | 10 ++++++++++ {CR.Exceptions => Cr.Exceptions}/ConflictException.cs | 2 +- .../Cr.Exceptions.csproj | 4 ++-- {CR.Exceptions => Cr.Exceptions}/CrError.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/CrException.cs | 2 +- .../Extensions/ImmutableArrayExtensions.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/ForbiddenException.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/InternalException.cs | 2 +- .../Mapping/ExceptionFactory.cs | 2 +- .../Mapping/ExceptionFactoryBuilder.cs | 2 +- .../Mapping/ExceptionTranslator.cs | 2 +- .../Mapping/ExceptionTranslatorBuilder.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/Mapping/Map.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/Mapping/MapBuilder.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/Mapping/TypeMap.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/NotFoundException.cs | 2 +- {CR.Exceptions => Cr.Exceptions}/README.md | 0 .../UnauthorizedException.cs | 2 +- .../UnprocessableException.cs | 2 +- .../ValidationException.cs | 2 +- README.md | 10 +++++----- 49 files changed, 72 insertions(+), 72 deletions(-) delete mode 100644 CR.Exceptions.slnx rename {CR.Exceptions.AspNet.Tests => Cr.Exceptions.AspNetCore.Tests}/Component/CrExceptionHandlerTests.cs (97%) rename {CR.Exceptions.AspNet.Tests => Cr.Exceptions.AspNetCore.Tests}/Component/LogLevelMapTests.cs (92%) rename {CR.Exceptions.AspNet.Tests => Cr.Exceptions.AspNetCore.Tests}/Component/StatusCodeMapTests.cs (92%) rename CR.Exceptions.AspNet.Tests/CR.Exceptions.AspNet.Tests.csproj => Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj (86%) rename {CR.Exceptions.AspNet.Tests => Cr.Exceptions.AspNetCore.Tests}/Unit/LogLevelMapBuilderTests.cs (95%) rename {CR.Exceptions.AspNet.Tests => Cr.Exceptions.AspNetCore.Tests}/Unit/StatusCodeMapBuilderTests.cs (94%) rename CR.Exceptions.AspNet/CR.Exceptions.AspNet.csproj => Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj (77%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/CrExceptionHandler.cs (98%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/CrExceptionHandlerLogExtensions.cs (98%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/LogLevelMap.cs (91%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/LogLevelMapBuilder.cs (96%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/LogLevelMapBuilderExtensions.cs (94%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/StatusCodeMap.cs (90%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/StatusCodeMapBuilder.cs (94%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/Mapping/StatusCodeMapBuilderExtensions.cs (95%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/ProblemDetailsExtensionNames.cs (78%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/README.md (100%) rename {CR.Exceptions.AspNet => Cr.Exceptions.AspNetCore}/ServiceCollectionExtensions.cs (98%) rename CR.Exceptions.Tests.Shared/CR.Exceptions.Tests.Shared.csproj => Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj (81%) rename {CR.Exceptions.Tests.Shared => Cr.Exceptions.Tests.Shared}/TestInternalException.cs (87%) rename {CR.Exceptions.Tests.Shared => Cr.Exceptions.Tests.Shared}/TestNotFoundException.cs (89%) rename {CR.Exceptions.Tests.Shared => Cr.Exceptions.Tests.Shared}/TestUnknownException.cs (90%) rename {CR.Exceptions.Tests => Cr.Exceptions.Tests}/Component/ExceptionFactoryTests.cs (95%) rename {CR.Exceptions.Tests => Cr.Exceptions.Tests}/Component/ExceptionTranslatorTests.cs (95%) rename CR.Exceptions.Tests/CR.Exceptions.Tests.csproj => Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj (94%) rename {CR.Exceptions.Tests => Cr.Exceptions.Tests}/Unit/ExceptionFactoryBuilderTests.cs (84%) rename {CR.Exceptions.Tests => Cr.Exceptions.Tests}/Unit/ExceptionTranslatorBuilderTests.cs (84%) create mode 100644 Cr.Exceptions.slnx rename {CR.Exceptions => Cr.Exceptions}/ConflictException.cs (95%) rename CR.Exceptions/CR.Exceptions.csproj => Cr.Exceptions/Cr.Exceptions.csproj (98%) rename {CR.Exceptions => Cr.Exceptions}/CrError.cs (90%) rename {CR.Exceptions => Cr.Exceptions}/CrException.cs (93%) rename {CR.Exceptions => Cr.Exceptions}/Extensions/ImmutableArrayExtensions.cs (96%) rename {CR.Exceptions => Cr.Exceptions}/ForbiddenException.cs (95%) rename {CR.Exceptions => Cr.Exceptions}/InternalException.cs (94%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/ExceptionFactory.cs (96%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/ExceptionFactoryBuilder.cs (94%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/ExceptionTranslator.cs (97%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/ExceptionTranslatorBuilder.cs (93%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/Map.cs (97%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/MapBuilder.cs (96%) rename {CR.Exceptions => Cr.Exceptions}/Mapping/TypeMap.cs (96%) rename {CR.Exceptions => Cr.Exceptions}/NotFoundException.cs (94%) rename {CR.Exceptions => Cr.Exceptions}/README.md (100%) rename {CR.Exceptions => Cr.Exceptions}/UnauthorizedException.cs (95%) rename {CR.Exceptions => Cr.Exceptions}/UnprocessableException.cs (95%) rename {CR.Exceptions => Cr.Exceptions}/ValidationException.cs (94%) diff --git a/CR.Exceptions.slnx b/CR.Exceptions.slnx deleted file mode 100644 index 9bffe89..0000000 --- a/CR.Exceptions.slnx +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/CR.Exceptions.AspNet.Tests/Component/CrExceptionHandlerTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs similarity index 97% rename from CR.Exceptions.AspNet.Tests/Component/CrExceptionHandlerTests.cs rename to Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs index 2e2f148..15d240c 100644 --- a/CR.Exceptions.AspNet.Tests/Component/CrExceptionHandlerTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs @@ -1,4 +1,4 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; using Microsoft.AspNetCore.Diagnostics; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; @@ -6,7 +6,7 @@ using System.Diagnostics; using System.Text.Json; -namespace CR.Exceptions.AspNet.Tests.Component; +namespace Cr.Exceptions.AspNetCore.Tests.Component; public sealed class CrExceptionHandlerTests { diff --git a/CR.Exceptions.AspNet.Tests/Component/LogLevelMapTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs similarity index 92% rename from CR.Exceptions.AspNet.Tests/Component/LogLevelMapTests.cs rename to Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs index 9a4c889..2055e9a 100644 --- a/CR.Exceptions.AspNet.Tests/Component/LogLevelMapTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs @@ -1,7 +1,7 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; using Microsoft.Extensions.Logging; -namespace CR.Exceptions.AspNet.Tests.Component; +namespace Cr.Exceptions.AspNetCore.Tests.Component; public sealed class LogLevelMapTests { diff --git a/CR.Exceptions.AspNet.Tests/Component/StatusCodeMapTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs similarity index 92% rename from CR.Exceptions.AspNet.Tests/Component/StatusCodeMapTests.cs rename to Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs index eeba7b8..d914163 100644 --- a/CR.Exceptions.AspNet.Tests/Component/StatusCodeMapTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs @@ -1,7 +1,7 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; using Microsoft.AspNetCore.Http; -namespace CR.Exceptions.AspNet.Tests.Component; +namespace Cr.Exceptions.AspNetCore.Tests.Component; public sealed class StatusCodeMapTests { diff --git a/CR.Exceptions.AspNet.Tests/CR.Exceptions.AspNet.Tests.csproj b/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj similarity index 86% rename from CR.Exceptions.AspNet.Tests/CR.Exceptions.AspNet.Tests.csproj rename to Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj index 0d197aa..12b993c 100644 --- a/CR.Exceptions.AspNet.Tests/CR.Exceptions.AspNet.Tests.csproj +++ b/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj @@ -21,8 +21,8 @@ - - + + diff --git a/CR.Exceptions.AspNet.Tests/Unit/LogLevelMapBuilderTests.cs b/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs similarity index 95% rename from CR.Exceptions.AspNet.Tests/Unit/LogLevelMapBuilderTests.cs rename to Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs index 63a2bca..4307874 100644 --- a/CR.Exceptions.AspNet.Tests/Unit/LogLevelMapBuilderTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace CR.Exceptions.AspNet.Tests.Unit; +namespace Cr.Exceptions.AspNetCore.Tests.Unit; public sealed class LogLevelMapBuilderTests { diff --git a/CR.Exceptions.AspNet.Tests/Unit/StatusCodeMapBuilderTests.cs b/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs similarity index 94% rename from CR.Exceptions.AspNet.Tests/Unit/StatusCodeMapBuilderTests.cs rename to Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs index 2c3e3f9..8b6ec36 100644 --- a/CR.Exceptions.AspNet.Tests/Unit/StatusCodeMapBuilderTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Http; -namespace CR.Exceptions.AspNet.Tests.Unit; +namespace Cr.Exceptions.AspNetCore.Tests.Unit; public sealed class StatusCodeMapBuilderTests { diff --git a/CR.Exceptions.AspNet/CR.Exceptions.AspNet.csproj b/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj similarity index 77% rename from CR.Exceptions.AspNet/CR.Exceptions.AspNet.csproj rename to Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj index a442889..33cc231 100644 --- a/CR.Exceptions.AspNet/CR.Exceptions.AspNet.csproj +++ b/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj @@ -8,16 +8,16 @@ - ASP.NET Core integration for CR.Exceptions. - - $(NuGetPackagePrefix).Exceptions.AspNet + ASP.NET Core integration for Cr.Exceptions. + + $(NuGetPackagePrefix).Exceptions.AspNetCore exceptions;aspnetcore;webapi;problem-details;rfc7807;middleware;exception-handler - + README.md - + diff --git a/CR.Exceptions.AspNet/CrExceptionHandler.cs b/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs similarity index 98% rename from CR.Exceptions.AspNet/CrExceptionHandler.cs rename to Cr.Exceptions.AspNetCore/CrExceptionHandler.cs index afe63b0..c7f58d4 100644 --- a/CR.Exceptions.AspNet/CrExceptionHandler.cs +++ b/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs @@ -4,7 +4,7 @@ using Microsoft.Extensions.Logging; using System.Collections.Immutable; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public sealed class CrExceptionHandler : IExceptionHandler { diff --git a/CR.Exceptions.AspNet/CrExceptionHandlerLogExtensions.cs b/Cr.Exceptions.AspNetCore/CrExceptionHandlerLogExtensions.cs similarity index 98% rename from CR.Exceptions.AspNet/CrExceptionHandlerLogExtensions.cs rename to Cr.Exceptions.AspNetCore/CrExceptionHandlerLogExtensions.cs index 0187174..70eda92 100644 --- a/CR.Exceptions.AspNet/CrExceptionHandlerLogExtensions.cs +++ b/Cr.Exceptions.AspNetCore/CrExceptionHandlerLogExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; internal static partial class CrExceptionHandlerLogExtensions { diff --git a/CR.Exceptions.AspNet/Mapping/LogLevelMap.cs b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs similarity index 91% rename from CR.Exceptions.AspNet/Mapping/LogLevelMap.cs rename to Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs index 44b7057..f9bdeae 100644 --- a/CR.Exceptions.AspNet/Mapping/LogLevelMap.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs @@ -2,7 +2,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public class LogLevelMap : TypeMap { diff --git a/CR.Exceptions.AspNet/Mapping/LogLevelMapBuilder.cs b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilder.cs similarity index 96% rename from CR.Exceptions.AspNet/Mapping/LogLevelMapBuilder.cs rename to Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilder.cs index e158ca4..30831d8 100644 --- a/CR.Exceptions.AspNet/Mapping/LogLevelMapBuilder.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilder.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public class LogLevelMapBuilder : MapBuilder { diff --git a/CR.Exceptions.AspNet/Mapping/LogLevelMapBuilderExtensions.cs b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilderExtensions.cs similarity index 94% rename from CR.Exceptions.AspNet/Mapping/LogLevelMapBuilderExtensions.cs rename to Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilderExtensions.cs index 2253630..168bd64 100644 --- a/CR.Exceptions.AspNet/Mapping/LogLevelMapBuilderExtensions.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMapBuilderExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.Logging; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public static class LogLevelMapBuilderExtensions { diff --git a/CR.Exceptions.AspNet/Mapping/StatusCodeMap.cs b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs similarity index 90% rename from CR.Exceptions.AspNet/Mapping/StatusCodeMap.cs rename to Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs index f65f4e3..161c823 100644 --- a/CR.Exceptions.AspNet/Mapping/StatusCodeMap.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public class StatusCodeMap : TypeMap { diff --git a/CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilder.cs b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilder.cs similarity index 94% rename from CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilder.cs rename to Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilder.cs index 7df2ff7..43cbbf4 100644 --- a/CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilder.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilder.cs @@ -1,6 +1,6 @@ using System.Net; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public class StatusCodeMapBuilder : MapBuilder { diff --git a/CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilderExtensions.cs b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilderExtensions.cs similarity index 95% rename from CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilderExtensions.cs rename to Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilderExtensions.cs index 9ec57a6..ba6598b 100644 --- a/CR.Exceptions.AspNet/Mapping/StatusCodeMapBuilderExtensions.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMapBuilderExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Http; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public static class StatusCodeMapBuilderExtensions { diff --git a/CR.Exceptions.AspNet/ProblemDetailsExtensionNames.cs b/Cr.Exceptions.AspNetCore/ProblemDetailsExtensionNames.cs similarity index 78% rename from CR.Exceptions.AspNet/ProblemDetailsExtensionNames.cs rename to Cr.Exceptions.AspNetCore/ProblemDetailsExtensionNames.cs index 02b43a2..457d51b 100644 --- a/CR.Exceptions.AspNet/ProblemDetailsExtensionNames.cs +++ b/Cr.Exceptions.AspNetCore/ProblemDetailsExtensionNames.cs @@ -1,4 +1,4 @@ -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public static class ProblemDetailsExtensionNames { diff --git a/CR.Exceptions.AspNet/README.md b/Cr.Exceptions.AspNetCore/README.md similarity index 100% rename from CR.Exceptions.AspNet/README.md rename to Cr.Exceptions.AspNetCore/README.md diff --git a/CR.Exceptions.AspNet/ServiceCollectionExtensions.cs b/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs similarity index 98% rename from CR.Exceptions.AspNet/ServiceCollectionExtensions.cs rename to Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs index b0cdf9d..efd0cb7 100644 --- a/CR.Exceptions.AspNet/ServiceCollectionExtensions.cs +++ b/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; -namespace CR.Exceptions.AspNet; +namespace Cr.Exceptions.AspNetCore; public static class ServiceCollectionExtensions { diff --git a/CR.Exceptions.Tests.Shared/CR.Exceptions.Tests.Shared.csproj b/Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj similarity index 81% rename from CR.Exceptions.Tests.Shared/CR.Exceptions.Tests.Shared.csproj rename to Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj index 5c75d70..bf3f68f 100644 --- a/CR.Exceptions.Tests.Shared/CR.Exceptions.Tests.Shared.csproj +++ b/Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/CR.Exceptions.Tests.Shared/TestInternalException.cs b/Cr.Exceptions.Tests.Shared/TestInternalException.cs similarity index 87% rename from CR.Exceptions.Tests.Shared/TestInternalException.cs rename to Cr.Exceptions.Tests.Shared/TestInternalException.cs index d67c6e5..15242b9 100644 --- a/CR.Exceptions.Tests.Shared/TestInternalException.cs +++ b/Cr.Exceptions.Tests.Shared/TestInternalException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions.Tests.Shared; +namespace Cr.Exceptions.Tests.Shared; public sealed class TestInternalException : InternalException { diff --git a/CR.Exceptions.Tests.Shared/TestNotFoundException.cs b/Cr.Exceptions.Tests.Shared/TestNotFoundException.cs similarity index 89% rename from CR.Exceptions.Tests.Shared/TestNotFoundException.cs rename to Cr.Exceptions.Tests.Shared/TestNotFoundException.cs index 658e8d5..7a73454 100644 --- a/CR.Exceptions.Tests.Shared/TestNotFoundException.cs +++ b/Cr.Exceptions.Tests.Shared/TestNotFoundException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions.Tests.Shared; +namespace Cr.Exceptions.Tests.Shared; public sealed class TestNotFoundException : NotFoundException { diff --git a/CR.Exceptions.Tests.Shared/TestUnknownException.cs b/Cr.Exceptions.Tests.Shared/TestUnknownException.cs similarity index 90% rename from CR.Exceptions.Tests.Shared/TestUnknownException.cs rename to Cr.Exceptions.Tests.Shared/TestUnknownException.cs index 82ed37a..d7fcc24 100644 --- a/CR.Exceptions.Tests.Shared/TestUnknownException.cs +++ b/Cr.Exceptions.Tests.Shared/TestUnknownException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions.Tests.Shared; +namespace Cr.Exceptions.Tests.Shared; public sealed class TestUnknownException : CrException { diff --git a/CR.Exceptions.Tests/Component/ExceptionFactoryTests.cs b/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs similarity index 95% rename from CR.Exceptions.Tests/Component/ExceptionFactoryTests.cs rename to Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs index 5c6c811..c8662a1 100644 --- a/CR.Exceptions.Tests/Component/ExceptionFactoryTests.cs +++ b/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs @@ -1,6 +1,6 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; -namespace CR.Exceptions.Tests.Component; +namespace Cr.Exceptions.Tests.Component; public sealed class ExceptionFactoryTests { diff --git a/CR.Exceptions.Tests/Component/ExceptionTranslatorTests.cs b/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs similarity index 95% rename from CR.Exceptions.Tests/Component/ExceptionTranslatorTests.cs rename to Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs index b5a35a2..7135626 100644 --- a/CR.Exceptions.Tests/Component/ExceptionTranslatorTests.cs +++ b/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs @@ -1,6 +1,6 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; -namespace CR.Exceptions.Tests.Component; +namespace Cr.Exceptions.Tests.Component; public sealed class ExceptionTranslatorTests { diff --git a/CR.Exceptions.Tests/CR.Exceptions.Tests.csproj b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj similarity index 94% rename from CR.Exceptions.Tests/CR.Exceptions.Tests.csproj rename to Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj index 4f5554c..8751bf8 100644 --- a/CR.Exceptions.Tests/CR.Exceptions.Tests.csproj +++ b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj @@ -21,7 +21,7 @@ - + diff --git a/CR.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs b/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs similarity index 84% rename from CR.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs rename to Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs index 741f98e..7d92485 100644 --- a/CR.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs +++ b/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs @@ -1,6 +1,6 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; -namespace CR.Exceptions.Tests.Unit; +namespace Cr.Exceptions.Tests.Unit; public sealed class ExceptionFactoryBuilderTests { diff --git a/CR.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs b/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs similarity index 84% rename from CR.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs rename to Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs index 18531fd..cf0cc5f 100644 --- a/CR.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs +++ b/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs @@ -1,6 +1,6 @@ -using CR.Exceptions.Tests.Shared; +using Cr.Exceptions.Tests.Shared; -namespace CR.Exceptions.Tests.Unit; +namespace Cr.Exceptions.Tests.Unit; public sealed class ExceptionTranslatorBuilderTests { diff --git a/Cr.Exceptions.slnx b/Cr.Exceptions.slnx new file mode 100644 index 0000000..7fc7e66 --- /dev/null +++ b/Cr.Exceptions.slnx @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/CR.Exceptions/ConflictException.cs b/Cr.Exceptions/ConflictException.cs similarity index 95% rename from CR.Exceptions/ConflictException.cs rename to Cr.Exceptions/ConflictException.cs index 3e56219..7dc54d4 100644 --- a/CR.Exceptions/ConflictException.cs +++ b/Cr.Exceptions/ConflictException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class ConflictException : CrException { diff --git a/CR.Exceptions/CR.Exceptions.csproj b/Cr.Exceptions/Cr.Exceptions.csproj similarity index 98% rename from CR.Exceptions/CR.Exceptions.csproj rename to Cr.Exceptions/Cr.Exceptions.csproj index 5729cf5..c8e3124 100644 --- a/CR.Exceptions/CR.Exceptions.csproj +++ b/Cr.Exceptions/Cr.Exceptions.csproj @@ -9,10 +9,10 @@ Core library for advanced .NET error handling. Provides a unified exception set, an exception factory, and an exception translator. - + $(NuGetPackagePrefix).Exceptions exception;exceptions;error-handling;exception-handling;exception-factory;exception-translator;exception-mapping;domain-exceptions;architecture;helpers - + README.md diff --git a/CR.Exceptions/CrError.cs b/Cr.Exceptions/CrError.cs similarity index 90% rename from CR.Exceptions/CrError.cs rename to Cr.Exceptions/CrError.cs index 26805f2..1ab57dd 100644 --- a/CR.Exceptions/CrError.cs +++ b/Cr.Exceptions/CrError.cs @@ -1,4 +1,4 @@ -namespace CR.Exceptions; +namespace Cr.Exceptions; public record class CrError { diff --git a/CR.Exceptions/CrException.cs b/Cr.Exceptions/CrException.cs similarity index 93% rename from CR.Exceptions/CrException.cs rename to Cr.Exceptions/CrException.cs index a1c5d99..1181e5e 100644 --- a/CR.Exceptions/CrException.cs +++ b/Cr.Exceptions/CrException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class CrException : Exception { diff --git a/CR.Exceptions/Extensions/ImmutableArrayExtensions.cs b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs similarity index 96% rename from CR.Exceptions/Extensions/ImmutableArrayExtensions.cs rename to Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs index 1de079b..30b214f 100644 --- a/CR.Exceptions/Extensions/ImmutableArrayExtensions.cs +++ b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs @@ -1,7 +1,7 @@ using System.Collections.Immutable; using System.Runtime.CompilerServices; -namespace CR.Exceptions; +namespace Cr.Exceptions; internal static class ImmutableArrayExtensions { diff --git a/CR.Exceptions/ForbiddenException.cs b/Cr.Exceptions/ForbiddenException.cs similarity index 95% rename from CR.Exceptions/ForbiddenException.cs rename to Cr.Exceptions/ForbiddenException.cs index 1f42b18..c9ad375 100644 --- a/CR.Exceptions/ForbiddenException.cs +++ b/Cr.Exceptions/ForbiddenException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class ForbiddenException : CrException { diff --git a/CR.Exceptions/InternalException.cs b/Cr.Exceptions/InternalException.cs similarity index 94% rename from CR.Exceptions/InternalException.cs rename to Cr.Exceptions/InternalException.cs index fdbb554..5a4cc31 100644 --- a/CR.Exceptions/InternalException.cs +++ b/Cr.Exceptions/InternalException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class InternalException : CrException { diff --git a/CR.Exceptions/Mapping/ExceptionFactory.cs b/Cr.Exceptions/Mapping/ExceptionFactory.cs similarity index 96% rename from CR.Exceptions/Mapping/ExceptionFactory.cs rename to Cr.Exceptions/Mapping/ExceptionFactory.cs index 774f20d..8b6a258 100644 --- a/CR.Exceptions/Mapping/ExceptionFactory.cs +++ b/Cr.Exceptions/Mapping/ExceptionFactory.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions; +namespace Cr.Exceptions; public class ExceptionFactory : Map> { diff --git a/CR.Exceptions/Mapping/ExceptionFactoryBuilder.cs b/Cr.Exceptions/Mapping/ExceptionFactoryBuilder.cs similarity index 94% rename from CR.Exceptions/Mapping/ExceptionFactoryBuilder.cs rename to Cr.Exceptions/Mapping/ExceptionFactoryBuilder.cs index 58d2b9a..1f4c1c5 100644 --- a/CR.Exceptions/Mapping/ExceptionFactoryBuilder.cs +++ b/Cr.Exceptions/Mapping/ExceptionFactoryBuilder.cs @@ -1,4 +1,4 @@ -namespace CR.Exceptions; +namespace Cr.Exceptions; public class ExceptionFactoryBuilder : MapBuilder> { diff --git a/CR.Exceptions/Mapping/ExceptionTranslator.cs b/Cr.Exceptions/Mapping/ExceptionTranslator.cs similarity index 97% rename from CR.Exceptions/Mapping/ExceptionTranslator.cs rename to Cr.Exceptions/Mapping/ExceptionTranslator.cs index 74eb70d..8ab9d89 100644 --- a/CR.Exceptions/Mapping/ExceptionTranslator.cs +++ b/Cr.Exceptions/Mapping/ExceptionTranslator.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions; +namespace Cr.Exceptions; public class ExceptionTranslator : TypeMap> { diff --git a/CR.Exceptions/Mapping/ExceptionTranslatorBuilder.cs b/Cr.Exceptions/Mapping/ExceptionTranslatorBuilder.cs similarity index 93% rename from CR.Exceptions/Mapping/ExceptionTranslatorBuilder.cs rename to Cr.Exceptions/Mapping/ExceptionTranslatorBuilder.cs index bcba23d..6acd33b 100644 --- a/CR.Exceptions/Mapping/ExceptionTranslatorBuilder.cs +++ b/Cr.Exceptions/Mapping/ExceptionTranslatorBuilder.cs @@ -1,4 +1,4 @@ -namespace CR.Exceptions; +namespace Cr.Exceptions; public class ExceptionTranslatorBuilder : MapBuilder> { diff --git a/CR.Exceptions/Mapping/Map.cs b/Cr.Exceptions/Mapping/Map.cs similarity index 97% rename from CR.Exceptions/Mapping/Map.cs rename to Cr.Exceptions/Mapping/Map.cs index e90b67a..6a2a4a3 100644 --- a/CR.Exceptions/Mapping/Map.cs +++ b/Cr.Exceptions/Mapping/Map.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class Map where TKey : notnull { diff --git a/CR.Exceptions/Mapping/MapBuilder.cs b/Cr.Exceptions/Mapping/MapBuilder.cs similarity index 96% rename from CR.Exceptions/Mapping/MapBuilder.cs rename to Cr.Exceptions/Mapping/MapBuilder.cs index 73d0819..56e06aa 100644 --- a/CR.Exceptions/Mapping/MapBuilder.cs +++ b/Cr.Exceptions/Mapping/MapBuilder.cs @@ -1,6 +1,6 @@ using System.Collections.Frozen; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class MapBuilder where TKey : notnull { diff --git a/CR.Exceptions/Mapping/TypeMap.cs b/Cr.Exceptions/Mapping/TypeMap.cs similarity index 96% rename from CR.Exceptions/Mapping/TypeMap.cs rename to Cr.Exceptions/Mapping/TypeMap.cs index 7d5dc2d..799dc62 100644 --- a/CR.Exceptions/Mapping/TypeMap.cs +++ b/Cr.Exceptions/Mapping/TypeMap.cs @@ -1,7 +1,7 @@ using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class TypeMap : Map { diff --git a/CR.Exceptions/NotFoundException.cs b/Cr.Exceptions/NotFoundException.cs similarity index 94% rename from CR.Exceptions/NotFoundException.cs rename to Cr.Exceptions/NotFoundException.cs index 4844c86..c381c4b 100644 --- a/CR.Exceptions/NotFoundException.cs +++ b/Cr.Exceptions/NotFoundException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class NotFoundException : CrException { diff --git a/CR.Exceptions/README.md b/Cr.Exceptions/README.md similarity index 100% rename from CR.Exceptions/README.md rename to Cr.Exceptions/README.md diff --git a/CR.Exceptions/UnauthorizedException.cs b/Cr.Exceptions/UnauthorizedException.cs similarity index 95% rename from CR.Exceptions/UnauthorizedException.cs rename to Cr.Exceptions/UnauthorizedException.cs index 4bbb8d4..0c74ace 100644 --- a/CR.Exceptions/UnauthorizedException.cs +++ b/Cr.Exceptions/UnauthorizedException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class UnauthorizedException : CrException { diff --git a/CR.Exceptions/UnprocessableException.cs b/Cr.Exceptions/UnprocessableException.cs similarity index 95% rename from CR.Exceptions/UnprocessableException.cs rename to Cr.Exceptions/UnprocessableException.cs index 525247f..003ced5 100644 --- a/CR.Exceptions/UnprocessableException.cs +++ b/Cr.Exceptions/UnprocessableException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class UnprocessableException : CrException { diff --git a/CR.Exceptions/ValidationException.cs b/Cr.Exceptions/ValidationException.cs similarity index 94% rename from CR.Exceptions/ValidationException.cs rename to Cr.Exceptions/ValidationException.cs index fb07f39..1f3882d 100644 --- a/CR.Exceptions/ValidationException.cs +++ b/Cr.Exceptions/ValidationException.cs @@ -1,6 +1,6 @@ using System.Collections.Immutable; -namespace CR.Exceptions; +namespace Cr.Exceptions; public abstract class ValidationException : CrException { diff --git a/README.md b/README.md index c17e16a..27ac0db 100644 --- a/README.md +++ b/README.md @@ -4,18 +4,18 @@ A lightweight framework for defining application errors, creating typed exceptio ## Modules -### CR.Exceptions +### Cr.Exceptions Core library for defining application errors, exception categories and their creation. -[README](./CR.Exceptions/README.md) +[README](./Cr.Exceptions/README.md) [NuGet](https://www.nuget.org/packages/CrCore.Exceptions/) --- -### CR.Exceptions.AspNet +### Cr.Exceptions.AspNetCore ASP.NET Core integration for handling exceptions and converting them into RFC 7807 ProblemDetails responses. -[README](./CR.Exceptions.AspNet/README.md) -[NuGet](https://www.nuget.org/packages/CrCore.Exceptions.AspNet/) \ No newline at end of file +[README](./Cr.Exceptions.AspNetCore/README.md) +[NuGet](https://www.nuget.org/packages/CrCore.Exceptions.AspNetCore/) \ No newline at end of file From 30918b3cda8d4074225fbccbc976ec4f603763b8 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 14:01:11 +0300 Subject: [PATCH 02/15] Update Directory.Build.props --- Directory.Build.props | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index be79613..3db9b3f 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,5 +1,13 @@ + + latest + Recommended + true + true + $(NoWarn);1591 + + apptade apptade @@ -7,17 +15,17 @@ true git - true - $(NoWarn);1591 + true + snupkg Apache-2.0 + README.md + CrCore - - latest - Recommended - true - + + + \ No newline at end of file From e91963138f8a666ede5989b57af41afd670fe74d Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 14:28:31 +0300 Subject: [PATCH 03/15] Update Cr.Exceptions.csproj --- Cr.Exceptions/Cr.Exceptions.csproj | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Cr.Exceptions/Cr.Exceptions.csproj b/Cr.Exceptions/Cr.Exceptions.csproj index c8e3124..46928ab 100644 --- a/Cr.Exceptions/Cr.Exceptions.csproj +++ b/Cr.Exceptions/Cr.Exceptions.csproj @@ -9,15 +9,8 @@ Core library for advanced .NET error handling. Provides a unified exception set, an exception factory, and an exception translator. - $(NuGetPackagePrefix).Exceptions exception;exceptions;error-handling;exception-handling;exception-factory;exception-translator;exception-mapping;domain-exceptions;architecture;helpers - - README.md - - - - \ No newline at end of file From d63291efe846355b566982d2fe2132a97ac5debe Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 14:29:33 +0300 Subject: [PATCH 04/15] Create GlobalUsings.cs in Cr.Exceptions --- Cr.Exceptions/GlobalUsings.cs | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Cr.Exceptions/GlobalUsings.cs diff --git a/Cr.Exceptions/GlobalUsings.cs b/Cr.Exceptions/GlobalUsings.cs new file mode 100644 index 0000000..56b6745 --- /dev/null +++ b/Cr.Exceptions/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using System.Collections.Frozen; +global using System.Collections.Immutable; \ No newline at end of file From ab6d4ace2be3a13379c31284edd1eeed9471a905 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 14:33:17 +0300 Subject: [PATCH 05/15] Remove abstraction in exception categories --- Cr.Exceptions/ConflictException.cs | 10 ++++------ Cr.Exceptions/CrException.cs | 8 +++----- Cr.Exceptions/ForbiddenException.cs | 10 ++++------ Cr.Exceptions/InternalException.cs | 10 ++++------ Cr.Exceptions/NotFoundException.cs | 10 ++++------ Cr.Exceptions/UnauthorizedException.cs | 10 ++++------ Cr.Exceptions/UnprocessableException.cs | 10 ++++------ Cr.Exceptions/ValidationException.cs | 10 ++++------ 8 files changed, 31 insertions(+), 47 deletions(-) diff --git a/Cr.Exceptions/ConflictException.cs b/Cr.Exceptions/ConflictException.cs index 7dc54d4..65f310c 100644 --- a/Cr.Exceptions/ConflictException.cs +++ b/Cr.Exceptions/ConflictException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class ConflictException : CrException +public class ConflictException : CrException { - protected ConflictException(ImmutableArray errors, Exception? innerException = null) + public ConflictException(ImmutableArray errors, Exception? innerException = null) : base(errors, "The requested operation could not be completed due to a conflict.", innerException) { } - protected ConflictException(ImmutableArray errors, string? message, Exception? innerException = null) + public ConflictException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/CrException.cs b/Cr.Exceptions/CrException.cs index 1181e5e..da556ae 100644 --- a/Cr.Exceptions/CrException.cs +++ b/Cr.Exceptions/CrException.cs @@ -1,12 +1,10 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class CrException : Exception +public class CrException : Exception { public ImmutableArray Errors { get; } - protected CrException(ImmutableArray errors, string? message = null, Exception? innerException = null) : base(message, innerException) + public CrException(ImmutableArray errors, string? message = null, Exception? innerException = null) : base(message, innerException) { errors.ThrowIfEmptyOrContainsNull(); diff --git a/Cr.Exceptions/ForbiddenException.cs b/Cr.Exceptions/ForbiddenException.cs index c9ad375..315ac09 100644 --- a/Cr.Exceptions/ForbiddenException.cs +++ b/Cr.Exceptions/ForbiddenException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class ForbiddenException : CrException +public class ForbiddenException : CrException { - protected ForbiddenException(ImmutableArray errors, Exception? innerException = null) + public ForbiddenException(ImmutableArray errors, Exception? innerException = null) : base(errors, "You do not have permission to perform this operation.", innerException) { } - protected ForbiddenException(ImmutableArray errors, string? message, Exception? innerException = null) + public ForbiddenException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/InternalException.cs b/Cr.Exceptions/InternalException.cs index 5a4cc31..28fb874 100644 --- a/Cr.Exceptions/InternalException.cs +++ b/Cr.Exceptions/InternalException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class InternalException : CrException +public class InternalException : CrException { - protected InternalException(ImmutableArray errors, Exception? innerException = null) + public InternalException(ImmutableArray errors, Exception? innerException = null) : base(errors, "An unexpected internal error occurred.", innerException) { } - protected InternalException(ImmutableArray errors, string? message, Exception? innerException = null) + public InternalException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/NotFoundException.cs b/Cr.Exceptions/NotFoundException.cs index c381c4b..b4dd1b1 100644 --- a/Cr.Exceptions/NotFoundException.cs +++ b/Cr.Exceptions/NotFoundException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class NotFoundException : CrException +public class NotFoundException : CrException { - protected NotFoundException(ImmutableArray errors, Exception? innerException = null) + public NotFoundException(ImmutableArray errors, Exception? innerException = null) : base(errors, "The requested resource was not found.", innerException) { } - protected NotFoundException(ImmutableArray errors, string? message, Exception? innerException = null) + public NotFoundException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/UnauthorizedException.cs b/Cr.Exceptions/UnauthorizedException.cs index 0c74ace..5171b6e 100644 --- a/Cr.Exceptions/UnauthorizedException.cs +++ b/Cr.Exceptions/UnauthorizedException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class UnauthorizedException : CrException +public class UnauthorizedException : CrException { - protected UnauthorizedException(ImmutableArray errors, Exception? innerException = null) + public UnauthorizedException(ImmutableArray errors, Exception? innerException = null) : base(errors, "Authentication is required to access this resource.", innerException) { } - protected UnauthorizedException(ImmutableArray errors, string? message, Exception? innerException = null) + public UnauthorizedException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/UnprocessableException.cs b/Cr.Exceptions/UnprocessableException.cs index 003ced5..afb7244 100644 --- a/Cr.Exceptions/UnprocessableException.cs +++ b/Cr.Exceptions/UnprocessableException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class UnprocessableException : CrException +public class UnprocessableException : CrException { - protected UnprocessableException(ImmutableArray errors, Exception? innerException = null) + public UnprocessableException(ImmutableArray errors, Exception? innerException = null) : base(errors, "The request could not be processed.", innerException) { } - protected UnprocessableException(ImmutableArray errors, string? message, Exception? innerException = null) + public UnprocessableException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } diff --git a/Cr.Exceptions/ValidationException.cs b/Cr.Exceptions/ValidationException.cs index 1f3882d..d684d42 100644 --- a/Cr.Exceptions/ValidationException.cs +++ b/Cr.Exceptions/ValidationException.cs @@ -1,15 +1,13 @@ -using System.Collections.Immutable; +namespace Cr.Exceptions; -namespace Cr.Exceptions; - -public abstract class ValidationException : CrException +public class ValidationException : CrException { - protected ValidationException(ImmutableArray errors, Exception? innerException = null) + public ValidationException(ImmutableArray errors, Exception? innerException = null) : base(errors, "The provided data is invalid.", innerException) { } - protected ValidationException(ImmutableArray errors, string? message, Exception? innerException = null) + public ValidationException(ImmutableArray errors, string? message, Exception? innerException = null) : base(errors, message, innerException) { } From 36806dc3f1256212e972433a0ae150073ae1f226 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 14:47:24 +0300 Subject: [PATCH 06/15] Add ctor overload in CrException --- Cr.Exceptions/ConflictException.cs | 12 ++++-------- Cr.Exceptions/CrException.cs | 5 +++++ Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs | 7 +++---- Cr.Exceptions/ForbiddenException.cs | 12 ++++-------- Cr.Exceptions/InternalException.cs | 12 ++++-------- Cr.Exceptions/NotFoundException.cs | 12 ++++-------- Cr.Exceptions/UnauthorizedException.cs | 12 ++++-------- Cr.Exceptions/UnprocessableException.cs | 12 ++++-------- Cr.Exceptions/ValidationException.cs | 12 ++++-------- 9 files changed, 36 insertions(+), 60 deletions(-) diff --git a/Cr.Exceptions/ConflictException.cs b/Cr.Exceptions/ConflictException.cs index 65f310c..0854d62 100644 --- a/Cr.Exceptions/ConflictException.cs +++ b/Cr.Exceptions/ConflictException.cs @@ -2,13 +2,9 @@ public class ConflictException : CrException { - public ConflictException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "The requested operation could not be completed due to a conflict.", innerException) - { - } + private const string DefaultMessage = "The requested operation could not be completed due to a conflict."; - public ConflictException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public ConflictException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public ConflictException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/CrException.cs b/Cr.Exceptions/CrException.cs index da556ae..daf05ab 100644 --- a/Cr.Exceptions/CrException.cs +++ b/Cr.Exceptions/CrException.cs @@ -4,6 +4,11 @@ public class CrException : Exception { public ImmutableArray Errors { get; } + public CrException(string? message = null, Exception? innerException = null) : base(message, innerException) + { + Errors = []; + } + public CrException(ImmutableArray errors, string? message = null, Exception? innerException = null) : base(message, innerException) { errors.ThrowIfEmptyOrContainsNull(); diff --git a/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs index 30b214f..ea43c46 100644 --- a/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs +++ b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs @@ -1,9 +1,8 @@ -using System.Collections.Immutable; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; namespace Cr.Exceptions; -internal static class ImmutableArrayExtensions +public static class ImmutableArrayExtensions { extension(ImmutableArray source) { @@ -11,7 +10,7 @@ public void ThrowIfEmptyOrContainsNull([CallerArgumentExpression(nameof(source)) { if (source.IsDefaultOrEmpty) { - throw new ArgumentException("The array cannot be empty.", paramName); + throw new ArgumentException("The array cannot be default or empty.", paramName); } for (var i = 0; i < source.Length; i++) diff --git a/Cr.Exceptions/ForbiddenException.cs b/Cr.Exceptions/ForbiddenException.cs index 315ac09..79adae1 100644 --- a/Cr.Exceptions/ForbiddenException.cs +++ b/Cr.Exceptions/ForbiddenException.cs @@ -2,13 +2,9 @@ public class ForbiddenException : CrException { - public ForbiddenException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "You do not have permission to perform this operation.", innerException) - { - } + private const string DefaultMessage = "You do not have permission to perform this operation."; - public ForbiddenException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public ForbiddenException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public ForbiddenException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/InternalException.cs b/Cr.Exceptions/InternalException.cs index 28fb874..07dca6c 100644 --- a/Cr.Exceptions/InternalException.cs +++ b/Cr.Exceptions/InternalException.cs @@ -2,13 +2,9 @@ public class InternalException : CrException { - public InternalException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "An unexpected internal error occurred.", innerException) - { - } + private const string DefaultMessage = "An unexpected internal error occurred."; - public InternalException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public InternalException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public InternalException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/NotFoundException.cs b/Cr.Exceptions/NotFoundException.cs index b4dd1b1..1df9c6e 100644 --- a/Cr.Exceptions/NotFoundException.cs +++ b/Cr.Exceptions/NotFoundException.cs @@ -2,13 +2,9 @@ public class NotFoundException : CrException { - public NotFoundException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "The requested resource was not found.", innerException) - { - } + private const string DefaultMessage = "The requested resource was not found."; - public NotFoundException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public NotFoundException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public NotFoundException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/UnauthorizedException.cs b/Cr.Exceptions/UnauthorizedException.cs index 5171b6e..b1d9f5f 100644 --- a/Cr.Exceptions/UnauthorizedException.cs +++ b/Cr.Exceptions/UnauthorizedException.cs @@ -2,13 +2,9 @@ public class UnauthorizedException : CrException { - public UnauthorizedException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "Authentication is required to access this resource.", innerException) - { - } + private const string DefaultMessage = "Authentication is required to access this resource."; - public UnauthorizedException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public UnauthorizedException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public UnauthorizedException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/UnprocessableException.cs b/Cr.Exceptions/UnprocessableException.cs index afb7244..267126f 100644 --- a/Cr.Exceptions/UnprocessableException.cs +++ b/Cr.Exceptions/UnprocessableException.cs @@ -2,13 +2,9 @@ public class UnprocessableException : CrException { - public UnprocessableException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "The request could not be processed.", innerException) - { - } + private const string DefaultMessage = "The request could not be processed."; - public UnprocessableException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public UnprocessableException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public UnprocessableException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file diff --git a/Cr.Exceptions/ValidationException.cs b/Cr.Exceptions/ValidationException.cs index d684d42..dbe888e 100644 --- a/Cr.Exceptions/ValidationException.cs +++ b/Cr.Exceptions/ValidationException.cs @@ -2,13 +2,9 @@ public class ValidationException : CrException { - public ValidationException(ImmutableArray errors, Exception? innerException = null) - : base(errors, "The provided data is invalid.", innerException) - { - } + private const string DefaultMessage = "The provided data is invalid."; - public ValidationException(ImmutableArray errors, string? message, Exception? innerException = null) - : base(errors, message, innerException) - { - } + public ValidationException(Exception? innerException = null) : base(DefaultMessage, innerException) { } + + public ValidationException(ImmutableArray errors, Exception? innerException = null) : base(errors, DefaultMessage, innerException) { } } \ No newline at end of file From 8946b6b3b0029e91b355e5eaec845b75d2d1d8cc Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 15:49:05 +0300 Subject: [PATCH 07/15] Update ImmutableArrayExtensions.cs --- Cr.Exceptions/CrException.cs | 3 ++- Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs | 9 ++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/Cr.Exceptions/CrException.cs b/Cr.Exceptions/CrException.cs index daf05ab..f6effbb 100644 --- a/Cr.Exceptions/CrException.cs +++ b/Cr.Exceptions/CrException.cs @@ -11,7 +11,8 @@ public CrException(string? message = null, Exception? innerException = null) : b public CrException(ImmutableArray errors, string? message = null, Exception? innerException = null) : base(message, innerException) { - errors.ThrowIfEmptyOrContainsNull(); + errors.ThrowIfDefault(); + errors.ThrowIfContainsNull(); Errors = errors; } diff --git a/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs index ea43c46..ba724c0 100644 --- a/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs +++ b/Cr.Exceptions/Extensions/ImmutableArrayExtensions.cs @@ -6,13 +6,16 @@ public static class ImmutableArrayExtensions { extension(ImmutableArray source) { - public void ThrowIfEmptyOrContainsNull([CallerArgumentExpression(nameof(source))] string? paramName = null) + public void ThrowIfDefault([CallerArgumentExpression(nameof(source))] string? paramName = null) { - if (source.IsDefaultOrEmpty) + if (source.IsDefault) { - throw new ArgumentException("The array cannot be default or empty.", paramName); + throw new ArgumentException("The array cannot be default.", paramName); } + } + public void ThrowIfContainsNull([CallerArgumentExpression(nameof(source))] string? paramName = null) + { for (var i = 0; i < source.Length; i++) { if (source[i] is null) From 667206ead67a40d7423a908ea19aadde80ffb6dd Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 15:57:48 +0300 Subject: [PATCH 08/15] Remove unused usings in CrException --- Cr.Exceptions/Mapping/ExceptionFactory.cs | 3 +-- Cr.Exceptions/Mapping/ExceptionTranslator.cs | 3 +-- Cr.Exceptions/Mapping/Map.cs | 3 +-- Cr.Exceptions/Mapping/MapBuilder.cs | 4 +--- Cr.Exceptions/Mapping/TypeMap.cs | 3 +-- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/Cr.Exceptions/Mapping/ExceptionFactory.cs b/Cr.Exceptions/Mapping/ExceptionFactory.cs index 8b6a258..ce1d659 100644 --- a/Cr.Exceptions/Mapping/ExceptionFactory.cs +++ b/Cr.Exceptions/Mapping/ExceptionFactory.cs @@ -1,5 +1,4 @@ -using System.Collections.Frozen; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions; diff --git a/Cr.Exceptions/Mapping/ExceptionTranslator.cs b/Cr.Exceptions/Mapping/ExceptionTranslator.cs index 8ab9d89..b9d4981 100644 --- a/Cr.Exceptions/Mapping/ExceptionTranslator.cs +++ b/Cr.Exceptions/Mapping/ExceptionTranslator.cs @@ -1,5 +1,4 @@ -using System.Collections.Frozen; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions; diff --git a/Cr.Exceptions/Mapping/Map.cs b/Cr.Exceptions/Mapping/Map.cs index 6a2a4a3..5e41bd3 100644 --- a/Cr.Exceptions/Mapping/Map.cs +++ b/Cr.Exceptions/Mapping/Map.cs @@ -1,5 +1,4 @@ -using System.Collections.Frozen; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions; diff --git a/Cr.Exceptions/Mapping/MapBuilder.cs b/Cr.Exceptions/Mapping/MapBuilder.cs index 56e06aa..b15316e 100644 --- a/Cr.Exceptions/Mapping/MapBuilder.cs +++ b/Cr.Exceptions/Mapping/MapBuilder.cs @@ -1,6 +1,4 @@ -using System.Collections.Frozen; - -namespace Cr.Exceptions; +namespace Cr.Exceptions; public abstract class MapBuilder where TKey : notnull { diff --git a/Cr.Exceptions/Mapping/TypeMap.cs b/Cr.Exceptions/Mapping/TypeMap.cs index 799dc62..a58d2d4 100644 --- a/Cr.Exceptions/Mapping/TypeMap.cs +++ b/Cr.Exceptions/Mapping/TypeMap.cs @@ -1,5 +1,4 @@ -using System.Collections.Frozen; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions; From 5aa9428f4862916793ad73f308e216d85fa088d5 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 16:03:58 +0300 Subject: [PATCH 09/15] Create GlobalUsings.cs in Cr.Exceptions.AspNetCore --- Cr.Exceptions.AspNetCore/CrExceptionHandler.cs | 1 - Cr.Exceptions.AspNetCore/GlobalUsings.cs | 2 ++ Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs | 1 - Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs | 3 +-- 4 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 Cr.Exceptions.AspNetCore/GlobalUsings.cs diff --git a/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs b/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs index c7f58d4..dcb56db 100644 --- a/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs +++ b/Cr.Exceptions.AspNetCore/CrExceptionHandler.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; -using System.Collections.Immutable; namespace Cr.Exceptions.AspNetCore; diff --git a/Cr.Exceptions.AspNetCore/GlobalUsings.cs b/Cr.Exceptions.AspNetCore/GlobalUsings.cs new file mode 100644 index 0000000..56b6745 --- /dev/null +++ b/Cr.Exceptions.AspNetCore/GlobalUsings.cs @@ -0,0 +1,2 @@ +global using System.Collections.Frozen; +global using System.Collections.Immutable; \ No newline at end of file diff --git a/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs index f9bdeae..e97939c 100644 --- a/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/LogLevelMap.cs @@ -1,5 +1,4 @@ using Microsoft.Extensions.Logging; -using System.Collections.Frozen; using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions.AspNetCore; diff --git a/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs index 161c823..baca0ac 100644 --- a/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs +++ b/Cr.Exceptions.AspNetCore/Mapping/StatusCodeMap.cs @@ -1,5 +1,4 @@ -using System.Collections.Frozen; -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; namespace Cr.Exceptions.AspNetCore; From dd36ece19774dd9c1500e0c3a0755f68a7bd757c Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 16:24:21 +0300 Subject: [PATCH 10/15] Update ServiceCollectionExtensions --- .../Component/CrExceptionHandlerTests.cs | 2 +- .../ServiceCollectionExtensions.cs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs index 15d240c..45152b2 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs @@ -97,7 +97,7 @@ private static ServiceProvider CreateServiceProvider() { return new ServiceCollection() .AddLogging() - .AddCrExceptionsCore() + .AddCrExceptions() .BuildServiceProvider(); } diff --git a/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs b/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs index efd0cb7..afbefa4 100644 --- a/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs +++ b/Cr.Exceptions.AspNetCore/ServiceCollectionExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using System.Diagnostics; namespace Cr.Exceptions.AspNetCore; @@ -6,7 +7,7 @@ public static class ServiceCollectionExtensions { extension(IServiceCollection services) { - public IServiceCollection AddCrExceptionsCore() + public IServiceCollection AddCrExceptions() { return services .AddCrExceptionHandler() @@ -53,11 +54,10 @@ private IServiceCollection AddCustomProblemDetails() { options.CustomizeProblemDetails = static context => { - var currentActivity = System.Diagnostics.Activity.Current; + var traceId = Activity.Current?.TraceId.ToHexString() + ?? context.HttpContext.TraceIdentifier; - context.ProblemDetails.Extensions[ProblemDetailsExtensionNames.TraceId] = currentActivity != null - ? currentActivity.TraceId.ToHexString() - : context.HttpContext.TraceIdentifier; + context.ProblemDetails.Extensions[ProblemDetailsExtensionNames.TraceId] = traceId; }; }); } From 522f26acdcbf5cabf503071604b9225cdd467d8a Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 16:29:42 +0300 Subject: [PATCH 11/15] Update Cr.Exceptions.Tests --- .../Component/ExceptionFactoryTests.cs | 20 +++++++++---------- .../Component/ExceptionTranslatorTests.cs | 14 ++++++------- .../Cr.Exceptions.Tests.csproj | 4 ---- .../Unit/ExceptionFactoryBuilderTests.cs | 8 +++----- .../Unit/ExceptionTranslatorBuilderTests.cs | 8 +++----- 5 files changed, 21 insertions(+), 33 deletions(-) diff --git a/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs b/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs index c8662a1..be5d064 100644 --- a/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs +++ b/Cr.Exceptions.Tests/Component/ExceptionFactoryTests.cs @@ -1,6 +1,4 @@ -using Cr.Exceptions.Tests.Shared; - -namespace Cr.Exceptions.Tests.Component; +namespace Cr.Exceptions.Tests.Component; public sealed class ExceptionFactoryTests { @@ -10,18 +8,18 @@ public sealed class ExceptionFactoryTests [Fact] public void TryCreate_ShouldReturn_TrueAndException_WhenCodeExists() { - var factory = GetDefaultFactory(ExistentCode); + var factory = GetDefaultFactory(); var result = factory.TryCreate(ExistentCode, out var exception); Assert.True(result); Assert.NotNull(exception); - Assert.IsType(exception); + Assert.IsType(exception); } [Fact] public void TryCreate_ShouldReturn_FalseAndNull_WhenCodeDoesNotExist() { - var factory = GetDefaultFactory("?"); + var factory = GetDefaultFactory(); var result = factory.TryCreate(NonExistentCode, out var exception); Assert.False(result); @@ -31,25 +29,25 @@ public void TryCreate_ShouldReturn_FalseAndNull_WhenCodeDoesNotExist() [Fact] public void Create_ShouldReturn_Exception_WhenCodeExists() { - var factory = GetDefaultFactory(ExistentCode); + var factory = GetDefaultFactory(); var exception = factory.Create(ExistentCode); Assert.NotNull(exception); - Assert.IsType(exception); + Assert.IsType(exception); } [Fact] public void Create_ShouldThrow_WhenCodeDoesNotExist() { - var factory = GetDefaultFactory("?"); + var factory = GetDefaultFactory(); Assert.Throws(() => factory.Create(NonExistentCode)); } - private static ExceptionFactory GetDefaultFactory(string code) + private static ExceptionFactory GetDefaultFactory() { return new ExceptionFactoryBuilder() - .Map(code, () => new TestInternalException()) + .Map(ExistentCode, () => new InternalException()) .Build(); } } \ No newline at end of file diff --git a/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs b/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs index 7135626..8bf7bd9 100644 --- a/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs +++ b/Cr.Exceptions.Tests/Component/ExceptionTranslatorTests.cs @@ -1,11 +1,9 @@ -using Cr.Exceptions.Tests.Shared; - -namespace Cr.Exceptions.Tests.Component; +namespace Cr.Exceptions.Tests.Component; public sealed class ExceptionTranslatorTests { - private static readonly TestInternalException ExistentException = new(); - private static readonly TestUnknownException NonExistentException = new(); + private static readonly InternalException ExistentException = new(); + private static readonly ConflictException NonExistentException = new(); [Fact] public void TryTranslate_ShouldReturn_TrueAndException_WhenExceptionExists() @@ -15,7 +13,7 @@ public void TryTranslate_ShouldReturn_TrueAndException_WhenExceptionExists() Assert.True(result); Assert.NotNull(exception); - Assert.IsType(exception); + Assert.IsType(exception); } [Fact] @@ -35,7 +33,7 @@ public void Translate_ShouldReturn_Exception_WhenExceptionExists() var exception = translator.Translate(ExistentException); Assert.NotNull(exception); - Assert.IsType(exception); + Assert.IsType(exception); } [Fact] @@ -49,7 +47,7 @@ public void Translate_ShouldThrow_WhenExceptionDoesNotExist() private static ExceptionTranslator GetDefaultTranslator() { return new ExceptionTranslatorBuilder() - .Map(ex => new TestUnknownException(ex)) + .Map(ex => new ConflictException(ex)) .Build(); } } \ No newline at end of file diff --git a/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj index 8751bf8..d31abdc 100644 --- a/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj +++ b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj @@ -20,10 +20,6 @@ - - - - diff --git a/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs b/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs index 7d92485..46cbccd 100644 --- a/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs +++ b/Cr.Exceptions.Tests/Unit/ExceptionFactoryBuilderTests.cs @@ -1,6 +1,4 @@ -using Cr.Exceptions.Tests.Shared; - -namespace Cr.Exceptions.Tests.Unit; +namespace Cr.Exceptions.Tests.Unit; public sealed class ExceptionFactoryBuilderTests { @@ -10,8 +8,8 @@ public void Map_ShouldThrow_WhenDuplicateRegistered() const string code = "duplicate"; var builder = new ExceptionFactoryBuilder() - .Map(code, () => new TestUnknownException()); + .Map(code, () => new UnprocessableException()); - Assert.ThrowsAny(() => builder.Map(code, () => new TestUnknownException())); + Assert.ThrowsAny(() => builder.Map(code, () => new CrException())); } } \ No newline at end of file diff --git a/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs b/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs index cf0cc5f..ccf71ba 100644 --- a/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs +++ b/Cr.Exceptions.Tests/Unit/ExceptionTranslatorBuilderTests.cs @@ -1,6 +1,4 @@ -using Cr.Exceptions.Tests.Shared; - -namespace Cr.Exceptions.Tests.Unit; +namespace Cr.Exceptions.Tests.Unit; public sealed class ExceptionTranslatorBuilderTests { @@ -8,8 +6,8 @@ public sealed class ExceptionTranslatorBuilderTests public void Map_ShouldThrow_WhenDuplicateRegistered() { var builder = new ExceptionTranslatorBuilder() - .Map(ex => new TestUnknownException(ex)); + .Map(ex => new UnprocessableException(ex)); - Assert.ThrowsAny(() => builder.Map(ex => new TestUnknownException(ex))); + Assert.ThrowsAny(() => builder.Map(ex => new ConflictException(ex))); } } \ No newline at end of file From 8bc319db3cffd30798671b41692d5df4d2cbf4c3 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 16:48:19 +0300 Subject: [PATCH 12/15] Update Cr.Exceptions.AspNetCore.Tests --- .../Component/CrExceptionHandlerTests.cs | 6 ++---- .../Component/LogLevelMapTests.cs | 9 ++++----- .../Component/StatusCodeMapTests.cs | 9 ++++----- .../Cr.Exceptions.AspNetCore.Tests.csproj | 1 - .../Unit/LogLevelMapBuilderTests.cs | 6 +++--- .../Unit/StatusCodeMapBuilderTests.cs | 4 ++-- Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj | 4 ++++ 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs index 45152b2..1b13d06 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs @@ -1,5 +1,4 @@ -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; @@ -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); } @@ -90,7 +89,6 @@ 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() diff --git a/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs index 2055e9a..1e7a7b7 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/LogLevelMapTests.cs @@ -1,13 +1,12 @@ -using Cr.Exceptions.Tests.Shared; -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; 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() @@ -32,7 +31,7 @@ public void TryFind_ShouldReturn_FalseAndDefault_WhenExceptionDoesNotExist() private static LogLevelMap GetDefaultMap() { return new LogLevelMapBuilder() - .Map(ExpectedLogLevel) + .Map(ExpectedLogLevel) .Build(); } } \ No newline at end of file diff --git a/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs index d914163..2ea0228 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/StatusCodeMapTests.cs @@ -1,13 +1,12 @@ -using Cr.Exceptions.Tests.Shared; -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; 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() @@ -32,7 +31,7 @@ public void TryFind_ShouldReturn_FalseAndDefault_WhenExceptionDoesNotExist() private static StatusCodeMap GetDefaultMap() { return new StatusCodeMapBuilder() - .Map(ExpectedStatusCode) + .Map(ExpectedStatusCode) .Build(); } } \ No newline at end of file diff --git a/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj b/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj index 12b993c..29b4296 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj +++ b/Cr.Exceptions.AspNetCore.Tests/Cr.Exceptions.AspNetCore.Tests.csproj @@ -22,7 +22,6 @@ - diff --git a/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs b/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs index 4307874..69a1a9a 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Unit/LogLevelMapBuilderTests.cs @@ -10,7 +10,7 @@ public void Map_ShouldThrow_When_DuplicateLevelRegistered() var builder = CreateBuilder() .Map(LogLevel.Error); - Assert.ThrowsAny(() => builder.Map(LogLevel.Warning)); + Assert.Throws(() => builder.Map(LogLevel.Warning)); } [Fact] @@ -18,7 +18,7 @@ public void Map_ShouldThrow_When_InvalidLevelRegistered() { var builder = CreateBuilder(); - Assert.ThrowsAny(() => builder.Map((LogLevel)4000)); + Assert.Throws(() => builder.Map((LogLevel)4000)); } [Fact] @@ -26,7 +26,7 @@ public void Map_ShouldThrow_When_NoneLevelRegistered() { var builder = CreateBuilder(); - Assert.ThrowsAny(() => builder.Map(LogLevel.None)); + Assert.Throws(() => builder.Map(LogLevel.None)); } [Fact] diff --git a/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs b/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs index 8b6ec36..3e78096 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Unit/StatusCodeMapBuilderTests.cs @@ -10,7 +10,7 @@ public void Map_ShouldThrow_When_DuplicateCodeRegistered() var builder = CreateBuilder() .Map(StatusCodes.Status400BadRequest); - Assert.ThrowsAny(() => builder.Map(StatusCodes.Status404NotFound)); + Assert.Throws(() => builder.Map(StatusCodes.Status404NotFound)); } [Fact] @@ -18,7 +18,7 @@ public void Map_ShouldThrow_When_InvalidCodeRegistered() { var builder = CreateBuilder(); - Assert.ThrowsAny(() => builder.Map(4000)); + Assert.Throws(() => builder.Map(4000)); } [Fact] diff --git a/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj index d31abdc..1848299 100644 --- a/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj +++ b/Cr.Exceptions.Tests/Cr.Exceptions.Tests.csproj @@ -20,6 +20,10 @@ + + + + From da7601c39bdad9a28166854a5b71f813705f1619 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 17:02:28 +0300 Subject: [PATCH 13/15] Remove Cr.Exceptions.Tests.Shared --- .../Cr.Exceptions.Tests.Shared.csproj | 14 -------------- .../TestInternalException.cs | 10 ---------- .../TestNotFoundException.cs | 10 ---------- Cr.Exceptions.Tests.Shared/TestUnknownException.cs | 10 ---------- Cr.Exceptions.slnx | 1 - 5 files changed, 45 deletions(-) delete mode 100644 Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj delete mode 100644 Cr.Exceptions.Tests.Shared/TestInternalException.cs delete mode 100644 Cr.Exceptions.Tests.Shared/TestNotFoundException.cs delete mode 100644 Cr.Exceptions.Tests.Shared/TestUnknownException.cs diff --git a/Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj b/Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj deleted file mode 100644 index bf3f68f..0000000 --- a/Cr.Exceptions.Tests.Shared/Cr.Exceptions.Tests.Shared.csproj +++ /dev/null @@ -1,14 +0,0 @@ - - - - net10.0 - enable - enable - false - - - - - - - \ No newline at end of file diff --git a/Cr.Exceptions.Tests.Shared/TestInternalException.cs b/Cr.Exceptions.Tests.Shared/TestInternalException.cs deleted file mode 100644 index 15242b9..0000000 --- a/Cr.Exceptions.Tests.Shared/TestInternalException.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Immutable; - -namespace Cr.Exceptions.Tests.Shared; - -public sealed class TestInternalException : InternalException -{ - private static readonly ImmutableArray _errors = [new("TestInternalCode", "Test internal message")]; - - public TestInternalException() : base(_errors) { } -} \ No newline at end of file diff --git a/Cr.Exceptions.Tests.Shared/TestNotFoundException.cs b/Cr.Exceptions.Tests.Shared/TestNotFoundException.cs deleted file mode 100644 index 7a73454..0000000 --- a/Cr.Exceptions.Tests.Shared/TestNotFoundException.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Immutable; - -namespace Cr.Exceptions.Tests.Shared; - -public sealed class TestNotFoundException : NotFoundException -{ - private static readonly ImmutableArray _errors = [new("TestNotFoundCode", "Test not found message")]; - - public TestNotFoundException(Exception? innerException = null) : base(_errors, innerException) { } -} \ No newline at end of file diff --git a/Cr.Exceptions.Tests.Shared/TestUnknownException.cs b/Cr.Exceptions.Tests.Shared/TestUnknownException.cs deleted file mode 100644 index d7fcc24..0000000 --- a/Cr.Exceptions.Tests.Shared/TestUnknownException.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Collections.Immutable; - -namespace Cr.Exceptions.Tests.Shared; - -public sealed class TestUnknownException : CrException -{ - private static readonly ImmutableArray _errors = [new("TestUnknownCode", "Test unknown message")]; - - public TestUnknownException(Exception? innerException = null) : base(_errors, "Test unknown exception message", innerException) { } -} \ No newline at end of file diff --git a/Cr.Exceptions.slnx b/Cr.Exceptions.slnx index 7fc7e66..43f5a4c 100644 --- a/Cr.Exceptions.slnx +++ b/Cr.Exceptions.slnx @@ -4,7 +4,6 @@ - From b105e18919295e4039b2137a1dc11848b385dde0 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 17:08:17 +0300 Subject: [PATCH 14/15] Update Cr.Exceptions.AspNetCore.csproj --- Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj b/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj index 33cc231..f0f44e4 100644 --- a/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj +++ b/Cr.Exceptions.AspNetCore/Cr.Exceptions.AspNetCore.csproj @@ -9,11 +9,8 @@ ASP.NET Core integration for Cr.Exceptions. - $(NuGetPackagePrefix).Exceptions.AspNetCore exceptions;aspnetcore;webapi;problem-details;rfc7807;middleware;exception-handler - - README.md @@ -24,8 +21,4 @@ - - - - \ No newline at end of file From b436eba2136032349efa34b792c33f7824fc24b3 Mon Sep 17 00:00:00 2001 From: apptade Date: Sun, 20 Sep 2026 17:16:14 +0300 Subject: [PATCH 15/15] Update CrExceptionHandlerTests.cs --- .../Component/CrExceptionHandlerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs index 1b13d06..4a2a36d 100644 --- a/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs +++ b/Cr.Exceptions.AspNetCore.Tests/Component/CrExceptionHandlerTests.cs @@ -73,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);