From 164c87ef9f1db0e54788e22e60ae35709b8d5ceb Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:00:55 +0200 Subject: [PATCH 1/2] AddJsonApi: Only register IoC services when not already provided This makes app setup easier. Previously, you often had to register overrides *after* calling AddJsonApi (last one wins). With this change, order does not matter anymore. Note that the order of MVC filters still matters, it is unrelated to this change. --- docs/usage/common-pitfalls.md | 8 +- src/Examples/MultiDbContextExample/Program.cs | 6 +- .../NoEntityFrameworkExample/Program.cs | 4 +- .../JsonApiApplicationBuilder.cs | 132 +++++++++--------- .../Configuration/ServiceDiscoveryFacade.cs | 5 +- .../Archiving/ArchiveTests.cs | 2 +- .../Creating/AtomicCreateResourceTests.cs | 2 +- ...reateResourceWithClientGeneratedIdTests.cs | 2 +- .../Links/AtomicAbsoluteLinksTests.cs | 2 +- .../AtomicRelativeLinksWithNamespaceTests.cs | 2 +- .../Meta/AtomicResourceMetaTests.cs | 2 +- .../Meta/AtomicResponseMetaTests.cs | 2 +- .../Mixed/AtomicLoggingTests.cs | 6 +- .../Mixed/AtomicSerializationTests.cs | 2 +- .../AtomicModelStateValidationTests.cs | 2 +- .../QueryStrings/AtomicQueryStringTests.cs | 5 +- ...micSerializationResourceDefinitionTests.cs | 2 +- ...icSparseFieldSetResourceDefinitionTests.cs | 2 +- .../AtomicTransactionConsistencyTests.cs | 2 +- .../Resources/AtomicUpdateResourceTests.cs | 2 +- .../IntegrationTests/Blobs/BlobTests.cs | 2 +- .../CompositeKeys/CompositeKeyTests.cs | 2 +- .../ApiControllerAttributeLogTests.cs | 2 +- .../EagerLoading/EagerLoadingTests.cs | 2 +- .../ExceptionHandlerTests.cs | 9 +- .../ModelState/ModelStateValidationTests.cs | 2 +- .../RequestBody/WorkflowTests.cs | 2 +- .../Links/AbsoluteLinksWithNamespaceTests.cs | 2 +- .../AbsoluteLinksWithoutNamespaceTests.cs | 2 +- .../Links/RelativeLinksWithNamespaceTests.cs | 2 +- .../RelativeLinksWithoutNamespaceTests.cs | 2 +- .../IntegrationTests/Logging/LoggingTests.cs | 2 +- .../Meta/ResourceMetaTests.cs | 3 +- .../Meta/ResponseMetaTests.cs | 2 +- .../Meta/TopLevelCountTests.cs | 2 +- .../FireAndForgetDelivery/FireForgetTests.cs | 2 +- .../TransactionalOutboxPattern/OutboxTests.cs | 2 +- .../MultiTenancy/MultiTenancyTests.cs | 11 +- .../IsUpperCase/IsUpperCaseFilterTests.cs | 2 +- .../StringLength/LengthFilterTests.cs | 2 +- .../StringLength/LengthSortTests.cs | 2 +- .../CustomFunctions/Sum/SumFilterTests.cs | 2 +- .../TimeOffset/TimeOffsetTests.cs | 2 +- .../SparseFieldSets/SparseFieldSetTests.cs | 6 +- ...reateResourceWithClientGeneratedIdTests.cs | 2 +- .../RemoveFromToManyRelationshipTests.cs | 2 +- .../ReplaceToManyRelationshipTests.cs | 2 +- .../Updating/Resources/UpdateResourceTests.cs | 2 +- .../Resources/UpdateToOneRelationshipTests.cs | 2 +- .../ResourceInjectionTests.cs | 2 +- .../Reading/ResourceDefinitionReadTests.cs | 2 +- .../ResourceDefinitionSerializationTests.cs | 3 +- .../ResourceInheritanceReadTests.cs | 2 +- .../ResourceInheritanceWriteTests.cs | 2 +- .../DisableQueryStringTests.cs | 4 +- .../Serialization/SerializationTests.cs | 2 +- .../SoftDeletion/SoftDeletionTests.cs | 8 +- .../DependencyContainerRegistrationTests.cs | 80 +++++++++++ .../IntegrationTestContext.cs | 37 ++--- 59 files changed, 234 insertions(+), 179 deletions(-) diff --git a/docs/usage/common-pitfalls.md b/docs/usage/common-pitfalls.md index 7941face82..f1f3fed3d6 100644 --- a/docs/usage/common-pitfalls.md +++ b/docs/usage/common-pitfalls.md @@ -87,11 +87,13 @@ Neither sounds very compelling. If stored procedures is what you need, you're be Although recommended by Microsoft for hard-written controllers, the opinionated behavior of [`[ApiController]`](https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-7.0#apicontroller-attribute) violates the JSON:API specification. Despite JsonApiDotNetCore trying its best to deal with it, the experience won't be as good as leaving it out. -#### Replace injectable services *after* calling `AddJsonApi()` -Registering your own services in the IoC container afterwards increases the chances that your replacements will take effect. -Also, register with `services.AddResourceDefinition/AddResourceService/AddResourceRepository()` instead of `services.AddScoped()`. +#### Register/override injectable services +Register your JSON:API resource services, resource definitions and repositories with `services.AddResourceService/AddResourceDefinition/AddResourceRepository()` instead of `services.AddScoped()`. When using [Auto-discovery](~/usage/resource-graph.md#auto-discovery), you don't need to register these at all. +> [!NOTE] +> In older versions of JsonApiDotNetCore, registering your own services in the IoC container *afterwards* increased the chances that your replacements would take effect. + #### Never use the Entity Framework Core In-Memory Database Provider When using this provider, many invalid mappings go unnoticed, leading to strange errors or wrong behavior. A real SQL engine fails to create the schema when mappings are invalid. If you're in need of a quick setup, use [SQLite](https://www.sqlite.org/). After adding its [NuGet package](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Sqlite), it's as simple as: diff --git a/src/Examples/MultiDbContextExample/Program.cs b/src/Examples/MultiDbContextExample/Program.cs index a8acd7ae83..2cf567b9b5 100644 --- a/src/Examples/MultiDbContextExample/Program.cs +++ b/src/Examples/MultiDbContextExample/Program.cs @@ -22,6 +22,9 @@ SetDbContextDebugOptions(options); }); +builder.Services.AddResourceRepository>(); +builder.Services.AddResourceRepository>(); + builder.Services.AddJsonApi(options => { options.Namespace = "api"; @@ -39,9 +42,6 @@ typeof(DbContextB) }); -builder.Services.AddResourceRepository>(); -builder.Services.AddResourceRepository>(); - WebApplication app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/src/Examples/NoEntityFrameworkExample/Program.cs b/src/Examples/NoEntityFrameworkExample/Program.cs index 8b299e2c24..8546e939e8 100755 --- a/src/Examples/NoEntityFrameworkExample/Program.cs +++ b/src/Examples/NoEntityFrameworkExample/Program.cs @@ -5,6 +5,8 @@ // Add services to the container. +builder.Services.AddScoped(); + builder.Services.AddJsonApi(options => { options.Namespace = "api"; @@ -18,8 +20,6 @@ #endif }, discovery => discovery.AddCurrentAssembly()); -builder.Services.AddScoped(); - WebApplication app = builder.Build(); // Configure the HTTP request pipeline. diff --git a/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs b/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs index c0b4638e40..17ca6677c3 100644 --- a/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs +++ b/src/JsonApiDotNetCore/Configuration/JsonApiApplicationBuilder.cs @@ -89,7 +89,7 @@ public void ConfigureResourceGraph(ICollection dbContextTypes, Action @@ -109,7 +109,7 @@ public void ConfigureMvc() if (_options.ValidateModelState) { _mvcBuilder.AddDataAnnotations(); - _services.AddSingleton(); + _services.Replace(new ServiceDescriptor(typeof(IModelMetadataProvider), typeof(JsonApiModelMetadataProvider), ServiceLifetime.Singleton)); } } @@ -130,19 +130,19 @@ public void ConfigureServiceContainer(ICollection dbContextTypes) if (dbContextTypes.Any()) { - _services.AddScoped(typeof(DbContextResolver<>)); + _services.TryAddScoped(typeof(DbContextResolver<>)); foreach (Type dbContextType in dbContextTypes) { Type dbContextResolverClosedType = typeof(DbContextResolver<>).MakeGenericType(dbContextType); - _services.AddScoped(typeof(IDbContextResolver), dbContextResolverClosedType); + _services.TryAddScoped(typeof(IDbContextResolver), dbContextResolverClosedType); } - _services.AddScoped(); + _services.TryAddScoped(); } else { - _services.AddScoped(); + _services.TryAddScoped(); } AddResourceLayer(); @@ -153,46 +153,46 @@ public void ConfigureServiceContainer(ICollection dbContextTypes) AddQueryStringLayer(); AddOperationsLayer(); - _services.AddScoped(typeof(IResourceChangeTracker<>), typeof(ResourceChangeTracker<>)); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); + _services.TryAddScoped(typeof(IResourceChangeTracker<>), typeof(ResourceChangeTracker<>)); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); } private void AddMiddlewareLayer() { - _services.AddSingleton(_options); - _services.AddSingleton(this); - _services.AddSingleton(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddSingleton(); - _services.AddSingleton(); - _services.AddSingleton(); - _services.AddSingleton(sp => sp.GetRequiredService()); - _services.AddSingleton(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); + _services.TryAddSingleton(_options); + _services.TryAddSingleton(this); + _services.TryAddSingleton(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddSingleton(); + _services.TryAddSingleton(); + _services.TryAddSingleton(); + _services.TryAddSingleton(provider => provider.GetRequiredService()); + _services.TryAddSingleton(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); } private void AddResourceLayer() { RegisterImplementationForInterfaces(ServiceDiscoveryFacade.ResourceDefinitionUnboundInterfaces, typeof(JsonApiResourceDefinition<,>)); - _services.AddScoped(); - _services.AddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); } private void AddRepositoryLayer() { RegisterImplementationForInterfaces(ServiceDiscoveryFacade.RepositoryUnboundInterfaces, typeof(EntityFrameworkCoreRepository<,>)); - _services.AddScoped(); + _services.TryAddScoped(); _services.TryAddTransient(); _services.TryAddTransient(); @@ -225,12 +225,12 @@ private void AddQueryStringLayer() _services.TryAddTransient(); _services.TryAddTransient(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); RegisterDependentService(); RegisterDependentService(); @@ -246,50 +246,50 @@ private void AddQueryStringLayer() RegisterDependentService(); RegisterDependentService(); - _services.AddScoped(); - _services.AddSingleton(); + _services.TryAddScoped(); + _services.TryAddSingleton(); } private void RegisterDependentService() where TCollectionElement : class where TElementToAdd : TCollectionElement { - _services.AddScoped(serviceProvider => serviceProvider.GetRequiredService()); + _services.AddScoped(provider => provider.GetRequiredService()); } private void AddSerializationLayer() { - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); - _services.AddSingleton(); - _services.AddSingleton(); - _services.AddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddSingleton(); + _services.TryAddSingleton(); + _services.TryAddScoped(); } private void AddOperationsLayer() { - _services.AddScoped(typeof(ICreateProcessor<,>), typeof(CreateProcessor<,>)); - _services.AddScoped(typeof(IUpdateProcessor<,>), typeof(UpdateProcessor<,>)); - _services.AddScoped(typeof(IDeleteProcessor<,>), typeof(DeleteProcessor<,>)); - _services.AddScoped(typeof(IAddToRelationshipProcessor<,>), typeof(AddToRelationshipProcessor<,>)); - _services.AddScoped(typeof(ISetRelationshipProcessor<,>), typeof(SetRelationshipProcessor<,>)); - _services.AddScoped(typeof(IRemoveFromRelationshipProcessor<,>), typeof(RemoveFromRelationshipProcessor<,>)); - - _services.AddScoped(); - _services.AddScoped(); - _services.AddScoped(); + _services.TryAddScoped(typeof(ICreateProcessor<,>), typeof(CreateProcessor<,>)); + _services.TryAddScoped(typeof(IUpdateProcessor<,>), typeof(UpdateProcessor<,>)); + _services.TryAddScoped(typeof(IDeleteProcessor<,>), typeof(DeleteProcessor<,>)); + _services.TryAddScoped(typeof(IAddToRelationshipProcessor<,>), typeof(AddToRelationshipProcessor<,>)); + _services.TryAddScoped(typeof(ISetRelationshipProcessor<,>), typeof(SetRelationshipProcessor<,>)); + _services.TryAddScoped(typeof(IRemoveFromRelationshipProcessor<,>), typeof(RemoveFromRelationshipProcessor<,>)); + + _services.TryAddScoped(); + _services.TryAddScoped(); + _services.TryAddScoped(); } public void Dispose() diff --git a/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs b/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs index 85f95c232f..d17ddfa1ba 100644 --- a/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs +++ b/src/JsonApiDotNetCore/Configuration/ServiceDiscoveryFacade.cs @@ -5,6 +5,7 @@ using JsonApiDotNetCore.Services; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; namespace JsonApiDotNetCore.Configuration; @@ -119,7 +120,7 @@ private void AddDbContextResolvers(Assembly assembly) foreach (Type dbContextType in dbContextTypes) { Type dbContextResolverClosedType = typeof(DbContextResolver<>).MakeGenericType(dbContextType); - _services.AddScoped(typeof(IDbContextResolver), dbContextResolverClosedType); + _services.TryAddScoped(typeof(IDbContextResolver), dbContextResolverClosedType); } } @@ -163,7 +164,7 @@ private void RegisterImplementations(Assembly assembly, Type interfaceType, Reso if (result != null) { (Type implementationType, Type serviceInterface) = result.Value; - _services.AddScoped(serviceInterface, implementationType); + _services.TryAddScoped(serviceInterface, implementationType); } } } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/ArchiveTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/ArchiveTests.cs index 2af39b3d26..7c282051f0 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/ArchiveTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Archiving/ArchiveTests.cs @@ -21,7 +21,7 @@ public ArchiveTests(IntegrationTestContext, testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs index 3331b1f1cc..99b3b3bc5b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceTests.cs @@ -27,7 +27,7 @@ public AtomicCreateResourceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesBeforeStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs index 15dbc19b07..5bd4acb39e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Creating/AtomicCreateResourceWithClientGeneratedIdTests.cs @@ -24,7 +24,7 @@ public AtomicCreateResourceWithClientGeneratedIdTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicAbsoluteLinksTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicAbsoluteLinksTests.cs index a6e162f72a..fdc7369a71 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicAbsoluteLinksTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicAbsoluteLinksTests.cs @@ -25,7 +25,7 @@ public AtomicAbsoluteLinksTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicRelativeLinksWithNamespaceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicRelativeLinksWithNamespaceTests.cs index db6ee06bbf..9184161c07 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicRelativeLinksWithNamespaceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Links/AtomicRelativeLinksWithNamespaceTests.cs @@ -26,7 +26,7 @@ public AtomicRelativeLinksWithNamespaceTests( testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResourceMetaTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResourceMetaTests.cs index 2bd9dc8edf..3edb88b14a 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResourceMetaTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResourceMetaTests.cs @@ -22,7 +22,7 @@ public AtomicResourceMetaTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResponseMetaTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResponseMetaTests.cs index ab084a0e90..e4c31db1e6 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResponseMetaTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Meta/AtomicResponseMetaTests.cs @@ -21,7 +21,7 @@ public AtomicResponseMetaTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicLoggingTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicLoggingTests.cs index f871e90238..d59cd3d8b2 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicLoggingTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicLoggingTests.cs @@ -28,13 +28,9 @@ public AtomicLoggingTests(IntegrationTestContext + testContext.ConfigureServices(services => { services.AddSingleton(loggerFactory); - }); - - testContext.ConfigureServicesAfterStartup(services => - { services.AddSingleton(); }); } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs index 0dcc99fdcd..b59100dbd9 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Mixed/AtomicSerializationTests.cs @@ -21,7 +21,7 @@ public AtomicSerializationTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ModelStateValidation/AtomicModelStateValidationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ModelStateValidation/AtomicModelStateValidationTests.cs index 03a04fb431..4a8b7d9e52 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ModelStateValidation/AtomicModelStateValidationTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ModelStateValidation/AtomicModelStateValidationTests.cs @@ -18,7 +18,7 @@ public AtomicModelStateValidationTests(IntegrationTestContext + _testContext.ConfigureServices(services => { services.AddSingleton(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/AtomicQueryStringTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/AtomicQueryStringTests.cs index 392a76c08d..a9d0fbd44b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/AtomicQueryStringTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/QueryStrings/AtomicQueryStringTests.cs @@ -21,10 +21,11 @@ public AtomicQueryStringTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { - services.AddSingleton(); services.AddResourceDefinition(); + + services.AddSingleton(); }); } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/Serialization/AtomicSerializationResourceDefinitionTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/Serialization/AtomicSerializationResourceDefinitionTests.cs index 27e44ec234..4e2fa4f937 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/Serialization/AtomicSerializationResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/Serialization/AtomicSerializationResourceDefinitionTests.cs @@ -22,7 +22,7 @@ public AtomicSerializationResourceDefinitionTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/SparseFieldSets/AtomicSparseFieldSetResourceDefinitionTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/SparseFieldSets/AtomicSparseFieldSetResourceDefinitionTests.cs index f70a289ba1..63fb7e8eb2 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/SparseFieldSets/AtomicSparseFieldSetResourceDefinitionTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/ResourceDefinitions/SparseFieldSets/AtomicSparseFieldSetResourceDefinitionTests.cs @@ -21,7 +21,7 @@ public AtomicSparseFieldSetResourceDefinitionTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs index d5e74fa4c3..896813986d 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Transactions/AtomicTransactionConsistencyTests.cs @@ -21,7 +21,7 @@ public AtomicTransactionConsistencyTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceRepository(); services.AddResourceRepository(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs index 895d1a0df5..0af67d4c20 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/AtomicOperations/Updating/Resources/AtomicUpdateResourceTests.cs @@ -25,7 +25,7 @@ public AtomicUpdateResourceTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Blobs/BlobTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Blobs/BlobTests.cs index 4d21e284e8..727245f06e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Blobs/BlobTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Blobs/BlobTests.cs @@ -19,7 +19,7 @@ public BlobTests(IntegrationTestContext, BlobDbCo testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeKeyTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeKeyTests.cs index 3ff947d7b4..a015ac52fa 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeKeyTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/CompositeKeys/CompositeKeyTests.cs @@ -21,7 +21,7 @@ public CompositeKeyTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceRepository>(); services.AddResourceRepository>(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/CustomRoutes/ApiControllerAttributeLogTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/CustomRoutes/ApiControllerAttributeLogTests.cs index 2b4a8c70d6..dce62dec7e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/CustomRoutes/ApiControllerAttributeLogTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/CustomRoutes/ApiControllerAttributeLogTests.cs @@ -22,7 +22,7 @@ public ApiControllerAttributeLogTests() options.AddProvider(_loggerFactory); }); - ConfigureServicesBeforeStartup(services => + ConfigureServices(services => { services.AddSingleton(_loggerFactory); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/EagerLoadingTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/EagerLoadingTests.cs index 5d2ddf0ece..f12123c203 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/EagerLoadingTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/EagerLoading/EagerLoadingTests.cs @@ -21,7 +21,7 @@ public EagerLoadingTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceRepository(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ExceptionHandling/ExceptionHandlerTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ExceptionHandling/ExceptionHandlerTests.cs index 53a2415627..7bf804a7d0 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ExceptionHandling/ExceptionHandlerTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ExceptionHandling/ExceptionHandlerTests.cs @@ -30,14 +30,11 @@ public ExceptionHandlerTests(IntegrationTestContext - { - services.AddSingleton(loggerFactory); - }); - - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceService(); + + services.AddSingleton(loggerFactory); services.AddScoped(); }); } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs index 9e104eef01..55e293aab1 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/ModelState/ModelStateValidationTests.cs @@ -19,7 +19,7 @@ public ModelStateValidationTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesBeforeStartup(services => + testContext.ConfigureServices(services => { // Polyfill for missing DateOnly/TimeOnly support in .NET 6 ModelState validation. services.AddDateOnlyTimeOnlyStringConverters(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/RequestBody/WorkflowTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/RequestBody/WorkflowTests.cs index 4653118ab6..895a8d2dc8 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/RequestBody/WorkflowTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/InputValidation/RequestBody/WorkflowTests.cs @@ -17,7 +17,7 @@ public WorkflowTests(IntegrationTestContext, testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithNamespaceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithNamespaceTests.cs index 62ba148dc4..e2449d802b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithNamespaceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithNamespaceTests.cs @@ -25,7 +25,7 @@ public AbsoluteLinksWithNamespaceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithoutNamespaceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithoutNamespaceTests.cs index 0d496f18eb..48f49abb99 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithoutNamespaceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/AbsoluteLinksWithoutNamespaceTests.cs @@ -25,7 +25,7 @@ public AbsoluteLinksWithoutNamespaceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithNamespaceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithNamespaceTests.cs index a51f522b82..fb26ca6533 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithNamespaceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithNamespaceTests.cs @@ -25,7 +25,7 @@ public RelativeLinksWithNamespaceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithoutNamespaceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithoutNamespaceTests.cs index cf614fc8f8..4fc2198bca 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithoutNamespaceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Links/RelativeLinksWithoutNamespaceTests.cs @@ -25,7 +25,7 @@ public RelativeLinksWithoutNamespaceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Logging/LoggingTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Logging/LoggingTests.cs index d297467bc4..3b92994de9 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Logging/LoggingTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Logging/LoggingTests.cs @@ -27,7 +27,7 @@ public LoggingTests(IntegrationTestContext, Lo options.SetMinimumLevel(LogLevel.Trace); }); - testContext.ConfigureServicesBeforeStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton(loggerFactory); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResourceMetaTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResourceMetaTests.cs index ba15de73d7..230bdd8b23 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResourceMetaTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResourceMetaTests.cs @@ -20,9 +20,10 @@ public ResourceMetaTests(IntegrationTestContext, testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); + services.AddSingleton(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResponseMetaTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResponseMetaTests.cs index 5b86a62322..a5ae347886 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResponseMetaTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/ResponseMetaTests.cs @@ -19,7 +19,7 @@ public ResponseMetaTests(IntegrationTestContext, testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs index 8bfb268daa..955a8514b6 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Meta/TopLevelCountTests.cs @@ -21,7 +21,7 @@ public TopLevelCountTests(IntegrationTestContext, testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/FireAndForgetDelivery/FireForgetTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/FireAndForgetDelivery/FireForgetTests.cs index fe7eabd112..86456d2d43 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/FireAndForgetDelivery/FireForgetTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/FireAndForgetDelivery/FireForgetTests.cs @@ -20,7 +20,7 @@ public FireForgetTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.cs index 529fcdab6c..2faa69051a 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Microservices/TransactionalOutboxPattern/OutboxTests.cs @@ -23,7 +23,7 @@ public OutboxTests(IntegrationTestContext, Outb testContext.UseController(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/MultiTenancy/MultiTenancyTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/MultiTenancy/MultiTenancyTests.cs index b2b100b0bd..e48470c6ab 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/MultiTenancy/MultiTenancyTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/MultiTenancy/MultiTenancyTests.cs @@ -25,16 +25,13 @@ public MultiTenancyTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesBeforeStartup(services => - { - services.AddSingleton(); - services.AddScoped(); - }); - - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceService>(); services.AddResourceService>(); + + services.AddSingleton(); + services.AddScoped(); }); var options = (JsonApiOptions)_testContext.Factory.Services.GetRequiredService(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseFilterTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseFilterTests.cs index a61c8ea744..be3240fdef 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseFilterTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/IsUpperCase/IsUpperCaseFilterTests.cs @@ -20,7 +20,7 @@ public IsUpperCaseFilterTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddTransient(); services.AddTransient(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthFilterTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthFilterTests.cs index 9954a0925e..5b6874f5b9 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthFilterTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthFilterTests.cs @@ -20,7 +20,7 @@ public LengthFilterTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddTransient(); services.AddTransient(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthSortTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthSortTests.cs index 46c0a68a07..340e571ecf 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthSortTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/StringLength/LengthSortTests.cs @@ -20,7 +20,7 @@ public LengthSortTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddTransient(); services.AddTransient(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumFilterTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumFilterTests.cs index f558fbb36b..6589120922 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumFilterTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/Sum/SumFilterTests.cs @@ -21,7 +21,7 @@ public SumFilterTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddTransient(); services.AddTransient(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetTests.cs index 3a171bdae0..baec74602b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/CustomFunctions/TimeOffset/TimeOffsetTests.cs @@ -25,7 +25,7 @@ public TimeOffsetTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesBeforeStartup(services => + testContext.ConfigureServices(services => { services.AddTransient(); services.AddSingleton(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs index 2dacb19ea7..feba8013b5 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/QueryStrings/SparseFieldSets/SparseFieldSetTests.cs @@ -22,13 +22,13 @@ public SparseFieldSetTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { - services.AddSingleton(); - services.AddResourceRepository>(); services.AddResourceRepository>(); services.AddResourceRepository>(); + + services.AddSingleton(); }); } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithClientGeneratedIdTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithClientGeneratedIdTests.cs index 58c804a073..3a04f5e937 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithClientGeneratedIdTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Creating/CreateResourceWithClientGeneratedIdTests.cs @@ -22,7 +22,7 @@ public CreateResourceWithClientGeneratedIdTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/RemoveFromToManyRelationshipTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/RemoveFromToManyRelationshipTests.cs index 82c21e1369..c4928b0924 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/RemoveFromToManyRelationshipTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Relationships/RemoveFromToManyRelationshipTests.cs @@ -25,7 +25,7 @@ public RemoveFromToManyRelationshipTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton, RemoveExtraFromWorkItemDefinition>(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs index 5836c2d7de..b3007bb936 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/ReplaceToManyRelationshipTests.cs @@ -22,7 +22,7 @@ public ReplaceToManyRelationshipTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateResourceTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateResourceTests.cs index 12cc45a577..6087f09fff 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateResourceTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateResourceTests.cs @@ -25,7 +25,7 @@ public UpdateResourceTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs index f96f4a9efa..636dbe6d3c 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ReadWrite/Updating/Resources/UpdateToOneRelationshipTests.cs @@ -22,7 +22,7 @@ public UpdateToOneRelationshipTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/ResourceInjectionTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/ResourceInjectionTests.cs index 19b38cf071..403f86757b 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/ResourceInjectionTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceConstructorInjection/ResourceInjectionTests.cs @@ -22,7 +22,7 @@ public ResourceInjectionTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesBeforeStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs index ed2b061f80..f1590b52ce 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Reading/ResourceDefinitionReadTests.cs @@ -21,7 +21,7 @@ public ResourceDefinitionReadTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddResourceDefinition(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Serialization/ResourceDefinitionSerializationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Serialization/ResourceDefinitionSerializationTests.cs index a5f5794bd1..950ba84b00 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Serialization/ResourceDefinitionSerializationTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceDefinitions/Serialization/ResourceDefinitionSerializationTests.cs @@ -22,13 +22,12 @@ public ResourceDefinitionSerializationTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); services.AddSingleton(); services.AddSingleton(); - services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs index def4638520..9cea6284b8 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceReadTests.cs @@ -35,7 +35,7 @@ protected ResourceInheritanceReadTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddResourceDefinition(); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceWriteTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceWriteTests.cs index a13629bb76..0fcd65e701 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceWriteTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/ResourceInheritance/ResourceInheritanceWriteTests.cs @@ -37,7 +37,7 @@ protected ResourceInheritanceWriteTests(IntegrationTestContext(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddSingleton>(); services.AddResourceDefinition>(); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/RestrictedControllers/DisableQueryStringTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/RestrictedControllers/DisableQueryStringTests.cs index ac2a3aa6a9..22044421e2 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/RestrictedControllers/DisableQueryStringTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/RestrictedControllers/DisableQueryStringTests.cs @@ -19,10 +19,10 @@ public DisableQueryStringTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(); - services.AddScoped(sp => sp.GetRequiredService()); + services.AddScoped(provider => provider.GetRequiredService()); }); } diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/Serialization/SerializationTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/Serialization/SerializationTests.cs index da87b6b82d..b7f55bee8e 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/Serialization/SerializationTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/Serialization/SerializationTests.cs @@ -23,7 +23,7 @@ public SerializationTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { services.AddScoped(typeof(IResourceChangeTracker<>), typeof(NeverSameResourceChangeTracker<>)); }); diff --git a/test/JsonApiDotNetCoreTests/IntegrationTests/SoftDeletion/SoftDeletionTests.cs b/test/JsonApiDotNetCoreTests/IntegrationTests/SoftDeletion/SoftDeletionTests.cs index 63ae9689a0..f750826f8c 100644 --- a/test/JsonApiDotNetCoreTests/IntegrationTests/SoftDeletion/SoftDeletionTests.cs +++ b/test/JsonApiDotNetCoreTests/IntegrationTests/SoftDeletion/SoftDeletionTests.cs @@ -25,15 +25,15 @@ public SoftDeletionTests(IntegrationTestContext(); testContext.UseController(); - testContext.ConfigureServicesAfterStartup(services => + testContext.ConfigureServices(services => { + services.AddResourceService>(); + services.AddResourceService>(); + services.AddSingleton(new FrozenSystemClock { UtcNow = 1.January(2005).AsUtc() }); - - services.AddResourceService>(); - services.AddResourceService>(); }); } diff --git a/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs index 8642461d50..2e9f74add6 100644 --- a/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/DependencyContainerRegistrationTests.cs @@ -1,12 +1,17 @@ using FluentAssertions; using JetBrains.Annotations; using JsonApiDotNetCore; +using JsonApiDotNetCore.Configuration; +using JsonApiDotNetCore.Controllers.Annotations; +using JsonApiDotNetCore.Queries; +using JsonApiDotNetCore.QueryStrings; using JsonApiDotNetCore.Resources; using JsonApiDotNetCore.Resources.Annotations; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Primitives; using TestBuildingBlocks; using Xunit; @@ -69,6 +74,55 @@ public void Cannot_resolve_registered_services_with_circular_dependency() action.Should().ThrowExactly().WithMessage("Some services are not able to be constructed * A circular dependency was detected *"); } + [Fact] + public void Can_replace_enumerable_service() + { + // Arrange + var services = new ServiceCollection(); + services.AddLogging(); + + services.AddScoped(); + + // Act + services.AddJsonApi(); + + // Assert + ServiceProvider provider = services.BuildServiceProvider(); + + IQueryStringParameterReader[] parameterReaders = provider.GetRequiredService>().ToArray(); + parameterReaders.Should().NotContain(parameterReader => parameterReader is FilterQueryStringParameterReader); + parameterReaders.Should().ContainSingle(parameterReader => parameterReader is CustomFilterQueryStringParameterReader); + + IQueryConstraintProvider[] constraintProviders = provider.GetRequiredService>().ToArray(); + constraintProviders.Should().NotContain(constraintProvider => constraintProvider is FilterQueryStringParameterReader); + constraintProviders.Should().ContainSingle(constraintProvider => constraintProvider is CustomFilterQueryStringParameterReader); + } + + [Fact] + public void Can_add_enumerable_service() + { + // Arrange + var services = new ServiceCollection(); + services.AddLogging(); + + services.AddScoped(); + services.AddScoped(); + + // Act + services.AddJsonApi(); + + // Assert + ServiceProvider provider = services.BuildServiceProvider(); + + IQueryStringParameterReader[] parameterReaders = provider.GetRequiredService>().ToArray(); + parameterReaders.Should().ContainSingle(parameterReader => parameterReader is CustomFilterQueryStringParameterReader); + parameterReaders.Should().ContainSingle(parameterReader => parameterReader is FilterQueryStringParameterReader); + + IQueryConstraintProvider[] constraintProviders = provider.GetRequiredService>().ToArray(); + constraintProviders.Should().ContainSingle(constraintProvider => constraintProvider is CustomFilterQueryStringParameterReader); + constraintProviders.Should().ContainSingle(constraintProvider => constraintProvider is FilterQueryStringParameterReader); + } + private static IHostBuilder CreateValidatingHostBuilder() { IHostBuilder hostBuilder = Host.CreateDefaultBuilder().ConfigureWebHostDefaults(webBuilder => @@ -140,4 +194,30 @@ private sealed class Resource : Identifiable [Attr] public string? Field { get; set; } } + + [UsedImplicitly(ImplicitUseKindFlags.Access)] + private sealed class CustomFilterQueryStringParameterReader : IFilterQueryStringParameterReader + { + public bool AllowEmptyValue => throw new NotImplementedException(); + + public bool IsEnabled(DisableQueryStringAttribute disableQueryStringAttribute) + { + throw new NotImplementedException(); + } + + public bool CanRead(string parameterName) + { + throw new NotImplementedException(); + } + + public void Read(string parameterName, StringValues parameterValue) + { + throw new NotImplementedException(); + } + + public IReadOnlyCollection GetConstraints() + { + throw new NotImplementedException(); + } + } } diff --git a/test/TestBuildingBlocks/IntegrationTestContext.cs b/test/TestBuildingBlocks/IntegrationTestContext.cs index f5d2b072f6..80dd4abfb6 100644 --- a/test/TestBuildingBlocks/IntegrationTestContext.cs +++ b/test/TestBuildingBlocks/IntegrationTestContext.cs @@ -33,8 +33,7 @@ public class IntegrationTestContext : IntegrationTest private readonly Lazy> _lazyFactory; private readonly TestControllerProvider _testControllerProvider = new(); private Action? _loggingConfiguration; - private Action? _beforeServicesConfiguration; - private Action? _afterServicesConfiguration; + private Action? _configureServices; protected override JsonSerializerOptions SerializerOptions { @@ -74,9 +73,9 @@ private WebApplicationFactory CreateFactory() factory.ConfigureLogging(_loggingConfiguration); - factory.ConfigureServicesBeforeStartup(services => + factory.ConfigureServices(services => { - _beforeServicesConfiguration?.Invoke(services); + _configureServices?.Invoke(services); services.ReplaceControllers(_testControllerProvider); @@ -87,8 +86,6 @@ private WebApplicationFactory CreateFactory() }); }); - factory.ConfigureServicesAfterStartup(_afterServicesConfiguration); - // We have placed an appsettings.json in the TestBuildingBlock project folder and set the content root to there. Note that controllers // are not discovered in the content root but are registered manually using IntegrationTestContext.UseController. WebApplicationFactory factoryWithConfiguredContentRoot = @@ -114,14 +111,9 @@ public void ConfigureLogging(Action loggingConfiguration) _loggingConfiguration = loggingConfiguration; } - public void ConfigureServicesBeforeStartup(Action servicesConfiguration) - { - _beforeServicesConfiguration = servicesConfiguration; - } - - public void ConfigureServicesAfterStartup(Action servicesConfiguration) + public void ConfigureServices(Action configureServices) { - _afterServicesConfiguration = servicesConfiguration; + _configureServices = configureServices; } public async Task RunOnDatabaseAsync(Func asyncAction) @@ -151,22 +143,16 @@ public override async Task DisposeAsync() private sealed class IntegrationTestWebApplicationFactory : WebApplicationFactory { private Action? _loggingConfiguration; - private Action? _beforeServicesConfiguration; - private Action? _afterServicesConfiguration; + private Action? _configureServices; public void ConfigureLogging(Action? loggingConfiguration) { _loggingConfiguration = loggingConfiguration; } - public void ConfigureServicesBeforeStartup(Action? servicesConfiguration) + public void ConfigureServices(Action? configureServices) { - _beforeServicesConfiguration = servicesConfiguration; - } - - public void ConfigureServicesAfterStartup(Action? servicesConfiguration) - { - _afterServicesConfiguration = servicesConfiguration; + _configureServices = configureServices; } protected override IHostBuilder CreateHostBuilder() @@ -189,15 +175,10 @@ protected override IHostBuilder CreateHostBuilder() { webBuilder.ConfigureServices(services => { - _beforeServicesConfiguration?.Invoke(services); + _configureServices?.Invoke(services); }); webBuilder.UseStartup(); - - webBuilder.ConfigureServices(services => - { - _afterServicesConfiguration?.Invoke(services); - }); }) .ConfigureLogging(options => { From f179362897941a0f0a9f0eeec9be08c60b92080c Mon Sep 17 00:00:00 2001 From: Bart Koelman <10324372+bkoelman@users.noreply.github.com> Date: Fri, 6 Oct 2023 00:45:50 +0200 Subject: [PATCH 2/2] Convert legacy unit tests --- .../ServiceCollectionExtensionsTests.cs | 39 +++++-------------- 1 file changed, 10 insertions(+), 29 deletions(-) rename test/{UnitTests/Extensions => JsonApiDotNetCoreTests/UnitTests/Configuration}/ServiceCollectionExtensionsTests.cs (94%) diff --git a/test/UnitTests/Extensions/ServiceCollectionExtensionsTests.cs b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/ServiceCollectionExtensionsTests.cs similarity index 94% rename from test/UnitTests/Extensions/ServiceCollectionExtensionsTests.cs rename to test/JsonApiDotNetCoreTests/UnitTests/Configuration/ServiceCollectionExtensionsTests.cs index 0cb24d8025..d4002a1932 100644 --- a/test/UnitTests/Extensions/ServiceCollectionExtensionsTests.cs +++ b/test/JsonApiDotNetCoreTests/UnitTests/Configuration/ServiceCollectionExtensionsTests.cs @@ -15,12 +15,12 @@ using TestBuildingBlocks; using Xunit; -namespace UnitTests.Extensions; +namespace JsonApiDotNetCoreTests.UnitTests.Configuration; public sealed class ServiceCollectionExtensionsTests { [Fact] - public void RegisterResource_DeviatingDbContextPropertyName_RegistersCorrectly() + public void Register_resource_from_DbContext_ignores_deviating_DbContext_property_name() { // Arrange var services = new ServiceCollection(); @@ -39,7 +39,7 @@ public void RegisterResource_DeviatingDbContextPropertyName_RegistersCorrectly() } [Fact] - public void AddResourceService_Registers_Service_Interfaces_Of_Int32() + public void Can_register_resource_service_for_Id_type_Int32() { // Arrange var services = new ServiceCollection(); @@ -63,7 +63,7 @@ public void AddResourceService_Registers_Service_Interfaces_Of_Int32() } [Fact] - public void AddResourceService_Registers_Service_Interfaces_Of_Guid() + public void Can_register_resource_service_for_Id_type_Guid() { // Arrange var services = new ServiceCollection(); @@ -87,7 +87,7 @@ public void AddResourceService_Registers_Service_Interfaces_Of_Guid() } [Fact] - public void AddResourceService_Throws_If_Type_Does_Not_Implement_Any_Interfaces() + public void Cannot_register_resource_service_for_type_that_does_not_implement_required_interfaces() { // Arrange var services = new ServiceCollection(); @@ -101,7 +101,7 @@ public void AddResourceService_Throws_If_Type_Does_Not_Implement_Any_Interfaces( } [Fact] - public void AddResourceRepository_Registers_Repository_Interfaces_Of_Int32() + public void Can_register_resource_repository_for_Id_type_Int32() { // Arrange var services = new ServiceCollection(); @@ -118,7 +118,7 @@ public void AddResourceRepository_Registers_Repository_Interfaces_Of_Int32() } [Fact] - public void AddResourceRepository_Registers_Repository_Interfaces_Of_Guid() + public void Can_register_resource_repository_for_Id_type_Guid() { // Arrange var services = new ServiceCollection(); @@ -135,7 +135,7 @@ public void AddResourceRepository_Registers_Repository_Interfaces_Of_Guid() } [Fact] - public void AddResourceDefinition_Registers_Definition_Interface_Of_Int32() + public void Can_register_resource_definition_for_Id_type_Int32() { // Arrange var services = new ServiceCollection(); @@ -150,7 +150,7 @@ public void AddResourceDefinition_Registers_Definition_Interface_Of_Int32() } [Fact] - public void AddResourceDefinition_Registers_Definition_Interface_Of_Guid() + public void Can_register_resource_definition_for_Id_type_Guid() { // Arrange var services = new ServiceCollection(); @@ -164,25 +164,6 @@ public void AddResourceDefinition_Registers_Definition_Interface_Of_Guid() provider.GetRequiredService(typeof(IResourceDefinition)).Should().BeOfType(); } - [Fact] - public void AddJsonApi_With_Context_Uses_Resource_Type_Name_If_NoOtherSpecified() - { - // Arrange - var services = new ServiceCollection(); - services.AddLogging(); - services.AddDbContext(options => options.UseInMemoryDatabase(Guid.NewGuid().ToString())); - - // Act - services.AddJsonApi(); - - // Assert - ServiceProvider provider = services.BuildServiceProvider(); - var resourceGraph = provider.GetRequiredService(); - ResourceType resourceType = resourceGraph.GetResourceType(typeof(ResourceOfInt32)); - - resourceType.PublicName.Should().Be("resourceOfInt32s"); - } - private sealed class ResourceOfInt32 : Identifiable { } @@ -594,7 +575,7 @@ private sealed class TestDbContext : TestableDbContext { public DbSet ResourcesOfInt32 => Set(); public DbSet ResourcesOfGuid => Set(); - public DbSet People => Set(); + public DbSet SetOfPersons => Set(); public TestDbContext(DbContextOptions options) : base(options)