From 1dc249bf5c8f46216a871913f6d9931a91c59525 Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Wed, 28 Sep 2022 04:39:53 +0200 Subject: [PATCH] Improve error message when duplicate controllers are found, to include the fully qualified type names of the conflicting controllers --- src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs | 3 ++- .../DuplicateResourceControllerTests.cs | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs b/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs index fe95d93446..58f8d18560 100644 --- a/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs +++ b/src/JsonApiDotNetCore/Middleware/JsonApiRoutingConvention.cs @@ -78,7 +78,8 @@ public void Apply(ApplicationModel application) { if (_controllerPerResourceTypeMap.ContainsKey(resourceType)) { - throw new InvalidConfigurationException($"Multiple controllers found for resource type '{resourceType}'."); + throw new InvalidConfigurationException( + $"Multiple controllers found for resource type '{resourceType}': '{_controllerPerResourceTypeMap[resourceType].ControllerType}' and '{controller.ControllerType}'."); } _resourceTypePerControllerTypeMap.Add(controller.ControllerType, resourceType); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs index b130523588..0f1b1178f4 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/NonJsonApiControllers/DuplicateResourceControllerTests.cs @@ -20,6 +20,9 @@ public void Fails_at_startup_when_multiple_controllers_exist_for_same_resource_t Action action = () => _ = Factory; // Assert - action.Should().ThrowExactly().WithMessage("Multiple controllers found for resource type 'knownResources'."); + InvalidConfigurationException exception = action.Should().ThrowExactly().Which!; + exception.Message.Should().StartWith("Multiple controllers found for resource type 'knownResources': "); + exception.Message.Should().Contain($"'{typeof(KnownResourcesController).FullName}'"); + exception.Message.Should().Contain($"'{typeof(DuplicateKnownResourcesController).FullName}'"); } }