-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test the service registrations in the composition root for the applic…
…ation tier (#53) * test the service registrations in the composition root for the application tier * warnings
- Loading branch information
Showing
7 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
Dfe.Data.SearchPrototype/Tests/Integration/CompositionRootTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Dfe.Data.SearchPrototype.Common.CleanArchitecture.Application.UseCase; | ||
using Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase; | ||
using Dfe.Data.SearchPrototype.Tests.Integration.TestHarness; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Xunit; | ||
|
||
namespace Dfe.Data.SearchPrototype.Tests.Integration; | ||
|
||
public class CompositionRootTests : IClassFixture<CompositionRootServiceProvider>, IClassFixture<ConfigBuilder> | ||
{ | ||
private Dictionary<string, string?> InMemoryConfig => new() { | ||
{ "SearchByKeywordCriteria:SearchFields:0", "ESTABLISHMENTNAME" }, | ||
{ "SearchByKeywordCriteria:Facets:0", "FACET1"} | ||
}; | ||
private readonly IConfiguration _config; | ||
private readonly IServiceProvider _compositionRootServiceProvider; | ||
|
||
public CompositionRootTests(CompositionRootServiceProvider serviceProvider, ConfigBuilder configBuilder) | ||
{ | ||
_config = configBuilder.SetupConfiguration(InMemoryConfig); | ||
_compositionRootServiceProvider = serviceProvider.SetUpServiceProvider(_config); | ||
} | ||
|
||
[Fact] | ||
public async Task AddSearchForEstablishmentServices_CanCreateUsecase() | ||
{ | ||
var usecase = _compositionRootServiceProvider.GetRequiredService<IUseCase<SearchByKeywordRequest, SearchByKeywordResponse>>(); | ||
|
||
var response = await usecase.HandleRequest(new SearchByKeywordRequest("searchkeyword")); | ||
|
||
response.Should().NotBeNull(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Dfe.Data.SearchPrototype/Tests/Integration/TestHarness/CompositionRootServiceProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Dfe.Data.SearchPrototype.Infrastructure; | ||
using Dfe.Data.SearchPrototype.Infrastructure.DataTransferObjects; | ||
using Dfe.Data.SearchPrototype.SearchForEstablishments; | ||
using Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.ServiceAdapters; | ||
using Dfe.Data.SearchPrototype.Tests.SearchForEstablishments.ByKeyword.TestDoubles; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Moq; | ||
|
||
namespace Dfe.Data.SearchPrototype.Tests.Integration.TestHarness; | ||
|
||
public class CompositionRootServiceProvider | ||
{ | ||
public IServiceProvider SetUpServiceProvider(IConfiguration config) | ||
{ | ||
IServiceCollection services = new ServiceCollection(); | ||
services.AddSingleton<IConfiguration>(config); | ||
|
||
services.AddSearchForEstablishmentServices(config); | ||
|
||
services.AddScoped<ISearchServiceAdapter>(provider => SearchServiceAdapterTestDouble.MockFor(SearchResultsTestDouble.CreateWithNoResults())); | ||
return services.BuildServiceProvider(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
Dfe.Data.SearchPrototype/Tests/Integration/TestHarness/ConfigBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace Dfe.Data.SearchPrototype.Tests.Integration.TestHarness; | ||
|
||
public class ConfigBuilder | ||
{ | ||
public IConfiguration SetupConfiguration(Dictionary<string, string?> options) | ||
{ | ||
var configBuilder = new ConfigurationBuilder(); | ||
|
||
configBuilder.AddInMemoryCollection(options); | ||
return configBuilder.Build(); | ||
} | ||
} |