From 38b17003993fa44b5125d0c24c6c45f804124b20 Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 15:59:23 +0100 Subject: [PATCH 1/4] Replace CommitmentsReadonlyDbContext and ICommitmentsReadOnlyDbContext with ProviderCommitmentsDbContext and IProviderCommitmentsDbContext --- .../GetApprenticeshipPerformanceTests.cs | 4 +- .../WhenGettingEmployerApprenticeships.cs | 8 +- .../WhenGettingProviderApprenticeships.cs | 14 ++-- .../SearchTests/WhenDownloadingApprentices.cs | 6 +- .../WhenGettingSortedApprenticeships.cs | 32 +++---- .../WhenGettingUnsortedApprenticeships.cs | 28 +++---- .../MoqExtensions.cs | 20 ----- .../Services/ApprenticeshipSearchService.cs | 4 +- .../OrderedApprenticeshipSearchService.cs | 4 +- ...verseOrderedApprenticeshipSearchService.cs | 4 +- .../Data/CommitmentsReadonlyDbContext.cs | 83 ------------------- .../Data/DbReadOnlyContextFactory.cs | 6 +- .../Data/IDbReadOnlyContextFactory.cs | 2 +- .../Data/IProviderCommitmentsDbContext.cs | 5 -- .../DependencyResolution/DataRegistry.cs | 4 +- 15 files changed, 58 insertions(+), 166 deletions(-) delete mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/CommitmentsReadonlyDbContext.cs diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipPerformanceTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipPerformanceTests.cs index ddcd869e0e..4fb8246257 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipPerformanceTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipPerformanceTests.cs @@ -19,7 +19,7 @@ public class GetApprenticeshipPerformanceTests : SearchParameterServiceTestBase [Test, RecursiveMoqAutoData] public async Task Then_Will_Not_Search_For_Apprenticeships_That_Will_Not_Be_Used_On_Current_Page( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, ApprenticeshipSearchService service) { @@ -46,7 +46,7 @@ public async Task Then_Will_Not_Search_For_Apprenticeships_That_Will_Not_Be_Used [Test, RecursiveMoqAutoData] public async Task Then_Will_Not_Search_For_Apprenticeships_That_Will_Be_Skipped( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, ApprenticeshipSearchService service) { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingEmployerApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingEmployerApprenticeships.cs index 3e6ef0072b..b4dc866ee1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingEmployerApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingEmployerApprenticeships.cs @@ -21,7 +21,7 @@ public async Task ThenQueriesApprenticeshipsWithEmployerIdWhenNotOrdering( List apprenticeships, [Frozen]GetApprenticeshipsQuery query, [Frozen] Mock mockSearch, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) { @@ -53,7 +53,7 @@ public async Task ThenQueriesApprenticeshipsWithEmployerIdWhenOrdering( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock mockSearch, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) @@ -88,7 +88,7 @@ public async Task ThenQueriesApprenticeshipsWithEmployerIdWhenOrderingInReverse( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock mockSearch, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) @@ -121,7 +121,7 @@ public async Task ThenWillReturnCurrentSelectedPage( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, ApprenticeshipSearchResult searchResult, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock mockSearch, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingProviderApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingProviderApprenticeships.cs index 0f234af1ae..10ef31a2bc 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingProviderApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/GetApprenticeshipsHandlerTests/WhenGettingProviderApprenticeships.cs @@ -23,7 +23,7 @@ public async Task ThenReturnUnsortedApprenticeshipsWhenNotOrdering( List apprenticeships, [Frozen]GetApprenticeshipsQuery query, [Frozen] Mock mockSearch, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) { @@ -58,7 +58,7 @@ public async Task ThenReturnsOrderedApprenticeshipsWhenOrdering( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock mockSearch, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) @@ -95,7 +95,7 @@ public async Task ThenReturnReverseOrderedApprenticeshipsWhenOrderingInReverse( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock mockSearch, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) @@ -132,7 +132,7 @@ public async Task ThenReturnsMappedApprenticeships( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, [Frozen]GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock search, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) @@ -171,7 +171,7 @@ public async Task ThenReturnsApprenticeshipsData( GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails, [Frozen]GetApprenticeshipsQuery query, [Frozen] Mock search, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) { @@ -210,7 +210,7 @@ public async Task ThenReturnsPageNumber( [Frozen]GetApprenticeshipsQuery query, List apprenticeships, ApprenticeshipSearchResult searchResult, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock search, GetApprenticeshipsQueryHandler handler) { @@ -239,7 +239,7 @@ public async Task ThenIsSetToBeFromProvider( GetApprenticeshipsQueryResult.ApprenticeshipDetails apprenticeshipDetails, [Frozen]GetApprenticeshipsQuery query, [Frozen] Mock search, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, [Frozen] Mock> mockMapper, GetApprenticeshipsQueryHandler handler) { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenDownloadingApprentices.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenDownloadingApprentices.cs index 96fcc01c69..91c6467587 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenDownloadingApprentices.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenDownloadingApprentices.cs @@ -18,7 +18,7 @@ public class WhenDownloadingApprentices : SearchParameterServiceTestBase [Test, MoqAutoData] public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_for_Default_Search( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -49,7 +49,7 @@ public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_for_Default_Sea [Test, MoqAutoData] public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_Normal_Sort( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); @@ -81,7 +81,7 @@ public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_Normal_Sort( [Test, MoqAutoData] public async Task Then_Downloads_Are_Restricted_To_Twelve_Months_For_Reverse_Sort( ReverseOrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingSortedApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingSortedApprenticeships.cs index 46da0c2666..def890d92b 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingSortedApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingSortedApprenticeships.cs @@ -20,7 +20,7 @@ public class WhenGettingSortedApprenticeships : SearchParameterServiceTestBase [Test, MoqAutoData] public async Task Then_Sorted_Apprentices_For_Provider_Are_Return( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); @@ -54,7 +54,7 @@ public async Task Then_Sorted_Apprentices_For_Provider_Are_Return( [Test, MoqAutoData] public async Task Then_Sorted_Apprentices_For_Employer_Are_Return( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); @@ -88,7 +88,7 @@ public async Task Then_Sorted_Apprentices_For_Employer_Are_Return( [Test, MoqAutoData] public async Task Then_Sorted_Apprentices_Are_Return_Per_Page( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); @@ -117,7 +117,7 @@ public async Task Then_Sorted_Apprentices_Are_Return_Per_Page( [Test, MoqAutoData] public async Task Then_Sorted_With_Alerts_Total_Found_Are_Return_With_Page_Data( OrderedApprenticeshipSearchParameters searchParams, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParams.FieldName = nameof(Apprenticeship.FirstName); @@ -144,7 +144,7 @@ public async Task Then_Sorted_With_Alerts_Total_Found_Are_Return_With_Page_Data( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_Name( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -226,7 +226,7 @@ public async Task Then_Apprentices_Are_Sorted_Name( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Uln( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -290,7 +290,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Uln( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Employer_Name( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -354,7 +354,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Employer_Name( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Course_Name( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -418,7 +418,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Course_Name( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Planned_Start_Date( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -485,7 +485,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Planned_Start_Date( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Planned_End_Date( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -552,7 +552,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Planned_End_Date( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Apprenticeship_Status( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -622,7 +622,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Apprenticeship_Status( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Sorted_By_Provider_Name( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -692,7 +692,7 @@ public async Task Then_Apprentices_Are_Sorted_By_Provider_Name( [Test, MoqAutoData] public async Task Then_Apprentices_Are_First_Sorted_By_Alerts( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -761,7 +761,7 @@ public async Task Then_Apprentices_Are_First_Sorted_By_Alerts( [Test, MoqAutoData] public async Task Then_Will_Return_Total_Apprenticeships_For_Provider( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { searchParameters.ReverseSort = false; searchParameters.Filters = new ApprenticeshipSearchFilters(); @@ -788,7 +788,7 @@ public async Task Then_Will_Return_Total_Apprenticeships_For_Provider( [Test, MoqAutoData] public async Task Then_Will_Return_Total_Apprenticeships_For_Employer( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); @@ -819,7 +819,7 @@ public async Task Then_Will_Return_Total_Apprenticeships_For_Employer( [Test, MoqAutoData] public async Task Then_Will_Return_Page_Number_Of_One_If_Only_Page( OrderedApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.FieldName = nameof(Apprenticeship.FirstName); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingUnsortedApprenticeships.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingUnsortedApprenticeships.cs index c274824204..88af0d7522 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingUnsortedApprenticeships.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Application/Queries/GetApprenticeships/SearchTests/WhenGettingUnsortedApprenticeships.cs @@ -22,7 +22,7 @@ public class WhenGettingUnsortedApprenticeships : SearchParameterServiceTestBase public async Task Then_Returns_Provider_Apprenticeships( ApprenticeshipSearchParameters searchParameters, List apprenticeships, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, ApprenticeshipSearchService service) { searchParameters.PageNumber = 1; @@ -53,7 +53,7 @@ public async Task Then_Returns_Provider_Apprenticeships( public async Task Then_Returns_Employer_Apprenticeships( ApprenticeshipSearchParameters searchParameters, List apprenticeships, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, ApprenticeshipSearchService service) { searchParameters.PageNumber = 1; @@ -84,7 +84,7 @@ public async Task Then_Returns_Employer_Apprenticeships( public async Task Then_Returns_Apprenticeships_Total_Found( ApprenticeshipSearchParameters searchParameters, List apprenticeships, - [Frozen] Mock mockContext, + [Frozen] Mock mockContext, ApprenticeshipSearchService service) { searchParameters.PageNumber = 1; @@ -107,7 +107,7 @@ public async Task Then_Returns_Apprenticeships_Total_Found( [Test, MoqAutoData] public async Task And_No_Sort_Term_Then_Apprentices_Are_Default_Sorted( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange @@ -217,7 +217,7 @@ public async Task And_No_Sort_Term_Then_Apprentices_Are_Default_Sorted( [Test, MoqAutoData] public async Task Then_Apprentices_Are_Return_Per_Page( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 2; @@ -245,7 +245,7 @@ public async Task Then_Apprentices_Are_Return_Per_Page( [Test, MoqAutoData] public async Task Then_Apprentices_Total_Found_Are_Return_With_Page_Data( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 2; @@ -270,7 +270,7 @@ public async Task Then_Apprentices_Total_Found_Are_Return_With_Page_Data( [Test, MoqAutoData] public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Provider_When_Getting_Paged_Results( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 2; @@ -298,7 +298,7 @@ public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Provider_W [Test, MoqAutoData] public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Employer_When_Getting_Paged_Results( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 2; @@ -326,7 +326,7 @@ public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Employer_W [Test, MoqAutoData] public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Provider_When_Getting_All_Results( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -354,7 +354,7 @@ public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Provider_W [Test, MoqAutoData] public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Employer_When_Getting_All_Results( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -383,7 +383,7 @@ public async Task Then_Total_Apprentices_Available_Will_Be_Return_For_Employer_W [Test, MoqAutoData] public async Task Then_Apprentices_With_Alerts_Total_Found_Are_Return_With_Page_Data( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 2; @@ -409,7 +409,7 @@ public async Task Then_Apprentices_With_Alerts_Total_Found_Are_Return_With_Page_ [Test, MoqAutoData] public async Task And_No_Sort_Term_And_Is_And_There_Are_ApprenticeshipUpdates_These_Appear_First( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 0; @@ -492,7 +492,7 @@ public async Task And_No_Sort_Term_And_Is_And_There_Are_ApprenticeshipUpdates_Th [Test, MoqAutoData] public async Task Then_Will_Return_The_Last_Page_Number_If_Page_Number_Exceeds_Limit( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.PageNumber = 10; @@ -521,7 +521,7 @@ public async Task Then_Will_Return_The_Last_Page_Number_If_Page_Number_Exceeds_L [Test, MoqAutoData] public async Task Then_Will_Return_Page_Number_If_All_Apprenticeships_Are_With_Alerts( ApprenticeshipSearchParameters searchParameters, - [Frozen] Mock mockContext) + [Frozen] Mock mockContext) { //Arrange searchParameters.ReverseSort = false; diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/MoqExtensions.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/MoqExtensions.cs index 263d317efa..2129347069 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/MoqExtensions.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/MoqExtensions.cs @@ -29,25 +29,5 @@ public static IReturnsResult ReturnsDbSet ReturnsDbSet(this ISetup> setupResult, IEnumerable entities) where TEntity : class - { - var entitiesAsQueryable = entities.AsQueryable(); - var dbSetMock = new Mock>(); - - dbSetMock.As>() - .Setup(m => m.GetEnumerator()) - .Returns(new InMemoryDbAsyncEnumerator(entitiesAsQueryable.GetEnumerator())); - - dbSetMock.As>() - .Setup(m => m.Provider) - .Returns(new InMemoryAsyncQueryProvider(entitiesAsQueryable.Provider)); - - dbSetMock.As>().Setup(m => m.Expression).Returns(entitiesAsQueryable.Expression); - dbSetMock.As>().Setup(m => m.ElementType).Returns(entitiesAsQueryable.ElementType); - dbSetMock.As>().Setup(m => m.GetEnumerator()).Returns(entitiesAsQueryable.GetEnumerator()); - - return setupResult.Returns(dbSetMock.Object); - } } } \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs index 909b951ee8..71e7cc2d9a 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ApprenticeshipSearchService.cs @@ -13,9 +13,9 @@ namespace SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Se { public class ApprenticeshipSearchService : IApprenticeshipSearchService { - private readonly ICommitmentsReadOnlyDbContext _dbContext; + private readonly IProviderCommitmentsDbContext _dbContext; - public ApprenticeshipSearchService(ICommitmentsReadOnlyDbContext dbContext) + public ApprenticeshipSearchService(IProviderCommitmentsDbContext dbContext) { _dbContext = dbContext; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs index f14a7ea701..17dd1c383e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/OrderedApprenticeshipSearchService.cs @@ -9,9 +9,9 @@ namespace SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Se { public class OrderedApprenticeshipSearchService : OrderedApprenticeshipSearchBaseService, IApprenticeshipSearchService { - private readonly ICommitmentsReadOnlyDbContext _dbContext; + private readonly IProviderCommitmentsDbContext _dbContext; - public OrderedApprenticeshipSearchService(ICommitmentsReadOnlyDbContext dbContext) + public OrderedApprenticeshipSearchService(IProviderCommitmentsDbContext dbContext) { _dbContext = dbContext; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs index ca1af9bda2..bd89a2c20e 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Application/Queries/GetApprenticeships/Search/Services/ReverseOrderedApprenticeshipSearchService.cs @@ -9,9 +9,9 @@ namespace SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships.Search.Se { public class ReverseOrderedApprenticeshipSearchService : OrderedApprenticeshipSearchBaseService, IApprenticeshipSearchService { - private readonly ICommitmentsReadOnlyDbContext _dbContext; + private readonly IProviderCommitmentsDbContext _dbContext; - public ReverseOrderedApprenticeshipSearchService(ICommitmentsReadOnlyDbContext dbContext) + public ReverseOrderedApprenticeshipSearchService(IProviderCommitmentsDbContext dbContext) { _dbContext = dbContext; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/CommitmentsReadonlyDbContext.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/CommitmentsReadonlyDbContext.cs deleted file mode 100644 index e8295bd9b0..0000000000 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/CommitmentsReadonlyDbContext.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using SFA.DAS.CommitmentsV2.Data.Configuration; -using SFA.DAS.CommitmentsV2.Models; - -namespace SFA.DAS.CommitmentsV2.Data -{ - public class CommitmentsReadOnlyDbContext : DbContext, ICommitmentsReadOnlyDbContext - { - protected CommitmentsReadOnlyDbContext() - { - } - public CommitmentsReadOnlyDbContext(DbContextOptions options) : base(options) - { - } - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - - } - public override int SaveChanges() - { - throw new InvalidOperationException("Read only context"); - } - - public override Task SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken()) - { - throw new InvalidOperationException("Read only context"); - } - - public override Task SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = new CancellationToken()) - { - throw new InvalidOperationException("Read only context"); - } - - public DbSet Accounts { get; set; } - public DbSet AccountLegalEntities { get; set; } - public DbSet DraftApprenticeships { get; set; } - public DbSet Apprenticeships { get; set; } - public DbSet ApprenticeshipUpdates { get; set; } - public DbSet AssessmentOrganisations { get; set; } - public DbSet BulkUploads { get; set; } - public DbSet Cohorts { get; set; } - public DbSet CustomProviderPaymentPriorities { get; set; } - public DbSet DataLocks { get; set; } - public DbSet History { get; set; } - public DbSet IntegrationTestIds { get; set; } - public DbSet JobProgress { get; set; } - public DbSet Messages { get; set; } - public DbSet Providers { get; set; } - public DbSet PriceHistory { get; set; } - public DbSet TransferRequests { get; set; } - public virtual DbSet ChangeOfPartyRequests { get; set; } - - public Task ExecuteSqlCommandAsync(string sql, params object[] parameters) - { - return Database.ExecuteSqlCommandAsync(sql, parameters); - } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - modelBuilder.ApplyConfiguration(new AccountConfiguration()); - modelBuilder.ApplyConfiguration(new AccountLegalEntityConfiguration()); - modelBuilder.ApplyConfiguration(new ApprenticeshipBaseConfiguration()); - modelBuilder.ApplyConfiguration(new ApprenticeshipUpdateConfiguration()); - modelBuilder.ApplyConfiguration(new AssessmentOrganisationConfiguration()); - modelBuilder.ApplyConfiguration(new BulkUploadConfiguration()); - modelBuilder.ApplyConfiguration(new CohortConfiguration()); - modelBuilder.ApplyConfiguration(new ApprenticeshipConfiguration()); - modelBuilder.ApplyConfiguration(new CustomProviderPaymentPriorityConfiguration()); - modelBuilder.ApplyConfiguration(new DataLockStatusConfiguration()); - modelBuilder.ApplyConfiguration(new DraftApprenticeshipConfiguration()); - modelBuilder.ApplyConfiguration(new HistoryConfiguration()); - modelBuilder.ApplyConfiguration(new JobProgressConfiguration()); - modelBuilder.ApplyConfiguration(new MessageConfiguration()); - modelBuilder.ApplyConfiguration(new PriceHistoryConfiguration()); - modelBuilder.ApplyConfiguration(new ProviderConfiguration()); - modelBuilder.ApplyConfiguration(new TransferRequestConfiguration()); - modelBuilder.ApplyConfiguration(new ChangeOfPartyRequestConfiguration()); - } - } -} \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs index 16aef469fd..5ce75c0136 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs @@ -18,14 +18,14 @@ public DbReadOnlyContextFactory(CommitmentsV2Configuration configuration, ILogge _loggerFactory = loggerFactory; } - public CommitmentsReadOnlyDbContext CreateDbContext() + public ProviderCommitmentsDbContext CreateDbContext() { - var optionsBuilder = new DbContextOptionsBuilder() + var optionsBuilder = new DbContextOptionsBuilder() .UseSqlServer(_connectionString) .UseLoggerFactory(_loggerFactory) .ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning)); - var dbContext = new CommitmentsReadOnlyDbContext(optionsBuilder.Options); + var dbContext = new ProviderCommitmentsDbContext(optionsBuilder.Options); return dbContext; } diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs index 2613eddca6..2c301ad83c 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs @@ -2,6 +2,6 @@ { public interface IDbReadOnlyContextFactory { - CommitmentsReadOnlyDbContext CreateDbContext(); + ProviderCommitmentsDbContext CreateDbContext(); } } \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IProviderCommitmentsDbContext.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IProviderCommitmentsDbContext.cs index b292cb5bd0..577a70f3e6 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IProviderCommitmentsDbContext.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IProviderCommitmentsDbContext.cs @@ -4,11 +4,6 @@ namespace SFA.DAS.CommitmentsV2.Data { - public interface ICommitmentsReadOnlyDbContext : IProviderCommitmentsDbContext - { - - } - public interface IProviderCommitmentsDbContext : ICommitmentsDbContext { diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs index 0d0de26838..dd2b0104b6 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs @@ -21,8 +21,8 @@ public class ReadOnlyDataRegistry : Registry public ReadOnlyDataRegistry() { For().Use(); - For().Use(c => c.GetInstance().CreateDbContext()); - For().Use(c => c.GetInstance().CreateDbContext()); + For().Use(c => c.GetInstance().CreateDbContext()); + For().Use(c => c.GetInstance().CreateDbContext()); } } } \ No newline at end of file From 85b26d1b1ef0bff01ce04949c991a0937fb6c84a Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Wed, 22 Apr 2020 16:29:55 +0100 Subject: [PATCH 2/4] fixed (?) intermittanlty failing test --- .../Domain/Extensions/AlertsExtensionTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs index 8405a29aaa..0672e3c035 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs @@ -192,7 +192,8 @@ public async Task And_Has_PendingUpdateOriginator_Null_Then_No_Alert( source.PendingUpdateOriginator = null; source.ApprenticeshipUpdate = null; source.DataLockStatus = new List{dataLockStatus}; - + source.PriceHistory = new List { priceHistory }; + var result = await mapper.Map(source); result.Alerts.Should().BeEmpty(); From 752e194af710e9d868868cf932e5af944ef0635e Mon Sep 17 00:00:00 2001 From: Peter Williams Date: Thu, 23 Apr 2020 13:39:12 +0100 Subject: [PATCH 3/4] Removed DbReadOnlyContextFactory --- .../DependencyResolution/IoC.cs | 1 - .../Data/DbReadOnlyContextFactory.cs | 34 ------------------- .../Data/IDbReadOnlyContextFactory.cs | 7 ---- .../DependencyResolution/DataRegistry.cs | 9 ----- 4 files changed, 51 deletions(-) delete mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs delete mode 100644 src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/DependencyResolution/IoC.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/DependencyResolution/IoC.cs index a3c5a62caf..fde464912f 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/DependencyResolution/IoC.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.Api/DependencyResolution/IoC.cs @@ -25,7 +25,6 @@ public static void Initialize(Registry registry) registry.IncludeRegistry(); registry.IncludeRegistry(); registry.IncludeRegistry(); - registry.IncludeRegistry(); registry.IncludeRegistry(); registry.IncludeRegistry>(); registry.IncludeRegistry(); diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs deleted file mode 100644 index 5ce75c0136..0000000000 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/DbReadOnlyContextFactory.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Data; -using System.Data.Common; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Diagnostics; -using Microsoft.Extensions.Logging; -using SFA.DAS.CommitmentsV2.Configuration; - -namespace SFA.DAS.CommitmentsV2.Data -{ - public class DbReadOnlyContextFactory : IDbReadOnlyContextFactory - { - private readonly string _connectionString; - private readonly ILoggerFactory _loggerFactory; - - public DbReadOnlyContextFactory(CommitmentsV2Configuration configuration, ILoggerFactory loggerFactory) - { - _connectionString = configuration.ReadOnlyDatabaseConnectionString; - _loggerFactory = loggerFactory; - } - - public ProviderCommitmentsDbContext CreateDbContext() - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseSqlServer(_connectionString) - .UseLoggerFactory(_loggerFactory) - .ConfigureWarnings(w => w.Throw(RelationalEventId.QueryClientEvaluationWarning)); - - var dbContext = new ProviderCommitmentsDbContext(optionsBuilder.Options); - - return dbContext; - } - } - -} \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs deleted file mode 100644 index 2c301ad83c..0000000000 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/Data/IDbReadOnlyContextFactory.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace SFA.DAS.CommitmentsV2.Data -{ - public interface IDbReadOnlyContextFactory - { - ProviderCommitmentsDbContext CreateDbContext(); - } -} \ No newline at end of file diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs index dd2b0104b6..3488391655 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2/DependencyResolution/DataRegistry.cs @@ -16,13 +16,4 @@ public DataRegistry() For().Use(c => c.GetInstance().CreateDbContext()); } } - public class ReadOnlyDataRegistry : Registry - { - public ReadOnlyDataRegistry() - { - For().Use(); - For().Use(c => c.GetInstance().CreateDbContext()); - For().Use(c => c.GetInstance().CreateDbContext()); - } - } } \ No newline at end of file From c9b13ebe0de810b3fef18bb420b6523f5280d7d4 Mon Sep 17 00:00:00 2001 From: Daniel Ashton Date: Tue, 28 Apr 2020 09:51:35 +0100 Subject: [PATCH 4/4] Fix failing test --- .../Domain/Extensions/AlertsExtensionTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs index 0672e3c035..b93285bdb1 100644 --- a/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs +++ b/src/CommitmentsV2/SFA.DAS.CommitmentsV2.UnitTests/Domain/Extensions/AlertsExtensionTests.cs @@ -77,6 +77,7 @@ public async Task And_Has_ErrorCode_DLock07_And_TriageStatus_Unknown_Then_ILR_Da dataLockStatus.ErrorCode = DataLockErrorCode.Dlock07; dataLockStatus.TriageStatus = TriageStatus.Unknown; dataLockStatus.IsResolved = false; + source.PriceHistory = new List { priceHistory }; source.DataLockStatus = new List{dataLockStatus}; source.PendingUpdateOriginator = null;