From 92714f2e50c9df81e057a0bc4ae54318dfc36fa2 Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 12 Nov 2024 17:53:53 +0000 Subject: [PATCH 1/6] EHD-1432: Reduce use of interfaces: Move IDbContext into same file as child --- .../GpgDatabaseContext.OnModelCreating.cs | 2 +- GenderPayGap.Database/GpgDatabaseContext.cs | 11 ++++++++++- GenderPayGap.Database/IDbContext.cs | 15 --------------- 3 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 GenderPayGap.Database/IDbContext.cs diff --git a/GenderPayGap.Database/GpgDatabaseContext.OnModelCreating.cs b/GenderPayGap.Database/GpgDatabaseContext.OnModelCreating.cs index 35096f065..e9b569e42 100644 --- a/GenderPayGap.Database/GpgDatabaseContext.OnModelCreating.cs +++ b/GenderPayGap.Database/GpgDatabaseContext.OnModelCreating.cs @@ -3,7 +3,7 @@ namespace GenderPayGap.Database { - public partial class GpgDatabaseContext : DbContext + public partial class GpgDatabaseContext { protected override void OnModelCreating(ModelBuilder modelBuilder) diff --git a/GenderPayGap.Database/GpgDatabaseContext.cs b/GenderPayGap.Database/GpgDatabaseContext.cs index e37c4b0f8..70746fdb0 100644 --- a/GenderPayGap.Database/GpgDatabaseContext.cs +++ b/GenderPayGap.Database/GpgDatabaseContext.cs @@ -8,7 +8,16 @@ namespace GenderPayGap.Database { - public partial class GpgDatabaseContext : IDbContext + public interface IDbContext : IDisposable + { + + DbSet Set() where TEntity : class; + void SaveChanges(); + DatabaseFacade GetDatabase(); + + } + + public partial class GpgDatabaseContext : DbContext, IDbContext { public static string ConnectionString = @"Server=127.0.0.1;Port=5432;Database=GpgDatabase;User Id=gpg_user;Password=local_gpg_database;"; diff --git a/GenderPayGap.Database/IDbContext.cs b/GenderPayGap.Database/IDbContext.cs deleted file mode 100644 index b9dbc6898..000000000 --- a/GenderPayGap.Database/IDbContext.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; - -namespace GenderPayGap.Database -{ - public interface IDbContext : IDisposable - { - - DbSet Set() where TEntity : class; - void SaveChanges(); - DatabaseFacade GetDatabase(); - - } -} From d936febaab3868f0ee38ead450df41f256f04872 Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 12 Nov 2024 17:57:13 +0000 Subject: [PATCH 2/6] EHD-1432: Reduce use of interfaces: IUserRepository --- .../Builders/ControllerBuilder.cs | 3 +-- .../UserRepository/CheckPasswordTests.cs | 4 ++-- .../UserRepository/FindByEmailTests.cs | 4 ++-- .../UserRepository/RetireUserTests.cs | 4 ++-- .../UserRepository/UpdateEmailTests.cs | 4 ++-- .../UserRepository/UpdatePasswordTests.cs | 4 ++-- .../Account/ChangePasswordControllerTests.cs | 4 ++-- .../TestHelpers/UiTestHelpers.cs | 5 ++--- .../Abstractions/IUserRepository.cs | 21 ------------------- .../Account/AccountCreationController.cs | 6 +++--- .../Account/ChangeEmailController.cs | 6 +++--- .../Account/ChangePasswordController.cs | 6 +++--- .../Account/CloseAccountController.cs | 5 ++--- .../Account/PasswordResetController.cs | 6 +++--- .../Admin/AdminImpersonateUserController.cs | 6 +++--- .../Admin/AdminManageAdminUsersController.cs | 6 +++--- .../Controllers/Login/LoginController.cs | 6 +++--- .../Repositories/UserRepository.cs | 3 +-- GenderPayGap.WebUI/Startup.cs | 3 +-- 19 files changed, 40 insertions(+), 66 deletions(-) delete mode 100644 GenderPayGap.WebUI/BusinessLogic/Abstractions/IUserRepository.cs diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Builders/ControllerBuilder.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Builders/ControllerBuilder.cs index a3a103a11..3a257895f 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Builders/ControllerBuilder.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Builders/ControllerBuilder.cs @@ -6,7 +6,6 @@ using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; using GenderPayGap.WebUI.BackgroundJobs; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Cookies; using GenderPayGap.WebUI.ExternalServices; using GenderPayGap.WebUI.Repositories; @@ -165,7 +164,7 @@ private IContainer BuildContainerIocForControllerOfType() builder.RegisterType().As().InstancePerLifetimeScope(); builder.Register(g => new MockGovNotify()).As().InstancePerLifetimeScope(); - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/CheckPasswordTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/CheckPasswordTests.cs index 68b362c76..99e513125 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/CheckPasswordTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/CheckPasswordTests.cs @@ -2,8 +2,8 @@ using GenderPayGap.Core; using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Moq; using NUnit.Framework; @@ -32,7 +32,7 @@ public void BeforeEach() } private Mock mockDataRepo; - private IUserRepository testUserRepo; + private GenderPayGap.WebUI.Repositories.UserRepository testUserRepo; [Test] public void CorrectPasswordShouldResetLoginAttempts() diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/FindByEmailTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/FindByEmailTests.cs index c24ed31d0..185163945 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/FindByEmailTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/FindByEmailTests.cs @@ -5,7 +5,7 @@ using GenderPayGap.Extensions; using GenderPayGap.Tests.Common.Classes; using GenderPayGap.Tests.Common.TestHelpers; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using GenderPayGap.WebUI.Tests.TestHelpers; using Moq; @@ -37,7 +37,7 @@ public void BeforeEach() } private Mock mockDataRepo; - private IUserRepository testUserRepo; + private GenderPayGap.WebUI.Repositories.UserRepository testUserRepo; [TestCase("active1@ad5bda75-e514-491b-b74d-4672542cbd15.com", UserStatuses.Active)] [TestCase("new1@ad5bda75-e514-491b-b74d-4672542cbd15.com", UserStatuses.New, UserStatuses.New)] diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/RetireUserTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/RetireUserTests.cs index 0c0f373f4..642a2a7a3 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/RetireUserTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/RetireUserTests.cs @@ -5,7 +5,7 @@ using GenderPayGap.Extensions; using GenderPayGap.Tests.Common.Classes; using GenderPayGap.Tests.Common.TestHelpers; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using GenderPayGap.WebUI.Tests.TestHelpers; using Moq; @@ -38,7 +38,7 @@ public void BeforeEach() private Mock mockDataRepo; - private IUserRepository testUserRepo; + private GenderPayGap.WebUI.Repositories.UserRepository testUserRepo; [TestCase] public void SavesRetiredStatus() diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdateEmailTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdateEmailTests.cs index ebb7b93bd..ea77be618 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdateEmailTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdateEmailTests.cs @@ -5,7 +5,7 @@ using GenderPayGap.Extensions; using GenderPayGap.Tests.Common.Classes; using GenderPayGap.Tests.Common.TestHelpers; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using GenderPayGap.WebUI.Tests.TestHelpers; using Moq; @@ -38,7 +38,7 @@ public void BeforeEach() private Mock mockDataRepo; - private IUserRepository testUserRepo; + private GenderPayGap.WebUI.Repositories.UserRepository testUserRepo; [TestCase("active1@ad5bda75-e514-491b-b74d-4672542cbd15.com", "active2@ad5bda75-e514-491b-b74d-4672542cbd15.com")] public void SavesExpectedEmailFields(string testCurrentEmail, string testNewEmail) diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdatePasswordTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdatePasswordTests.cs index c28ac4dfc..4ade84c72 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdatePasswordTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Repositories/UserRepository/UpdatePasswordTests.cs @@ -5,8 +5,8 @@ using GenderPayGap.Extensions; using GenderPayGap.Tests.Common.Classes; using GenderPayGap.Tests.Common.TestHelpers; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using GenderPayGap.WebUI.Tests.TestHelpers; using Moq; @@ -39,7 +39,7 @@ public void BeforeEach() private Mock mockDataRepo; - private IUserRepository testUserRepo; + private GenderPayGap.WebUI.Repositories.UserRepository testUserRepo; [TestCase] public void SavesNewPasswordHash() diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Controllers/Account/ChangePasswordControllerTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Controllers/Account/ChangePasswordControllerTests.cs index ba4c36a62..e4adf7d37 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Controllers/Account/ChangePasswordControllerTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Controllers/Account/ChangePasswordControllerTests.cs @@ -6,10 +6,10 @@ using GenderPayGap.Database; using GenderPayGap.Database.Models; using GenderPayGap.Extensions; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Controllers.Account; using GenderPayGap.WebUI.ExternalServices; using GenderPayGap.WebUI.Models.Account; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using GenderPayGap.WebUI.Tests.Builders; using GenderPayGap.WebUI.Tests.TestHelpers; @@ -26,7 +26,7 @@ public class ChangePasswordControllerTests { private Mock mockDataRepo; - private IUserRepository mockUserRepo; + private UserRepository mockUserRepo; [SetUp] public void BeforeEach() diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs index 1bc485b73..3cce33cf6 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -14,7 +14,6 @@ using GenderPayGap.Tests.Common.Classes; using GenderPayGap.Tests.Common.TestHelpers; using GenderPayGap.WebUI.BackgroundJobs; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.BusinessLogic.Services; using GenderPayGap.WebUI.Classes; using GenderPayGap.WebUI.Classes.Presentation; @@ -191,7 +190,7 @@ public static IContainer BuildContainerIoC(params object[] dbObjects) //Create the mock repositories // BL Repository builder.Register(c => new SystemFileRepository()).As().SingleInstance(); - builder.RegisterType().As().SingleInstance(); + builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); diff --git a/GenderPayGap.WebUI/BusinessLogic/Abstractions/IUserRepository.cs b/GenderPayGap.WebUI/BusinessLogic/Abstractions/IUserRepository.cs deleted file mode 100644 index 079d1af50..000000000 --- a/GenderPayGap.WebUI/BusinessLogic/Abstractions/IUserRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using GenderPayGap.Core; -using GenderPayGap.Database; - -namespace GenderPayGap.WebUI.BusinessLogic.Abstractions -{ - - public interface IUserRepository - { - - bool CheckPassword(User user, string password, bool isReset = false); - - User FindByEmail(string email, params UserStatuses[] filterStatuses); - - void UpdateEmail(User userToUpdate, string newEmailAddress); - - void UpdatePassword(User userToUpdate, string newPassword); - - void RetireUser(User userToRetire); - } - -} diff --git a/GenderPayGap.WebUI/Controllers/Account/AccountCreationController.cs b/GenderPayGap.WebUI/Controllers/Account/AccountCreationController.cs index 34fa3138a..bfe13d4cf 100644 --- a/GenderPayGap.WebUI/Controllers/Account/AccountCreationController.cs +++ b/GenderPayGap.WebUI/Controllers/Account/AccountCreationController.cs @@ -4,9 +4,9 @@ using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; using GenderPayGap.Extensions; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.AccountCreation; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Microsoft.AspNetCore.Mvc; @@ -17,12 +17,12 @@ public class AccountCreationController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly EmailSendingService emailSendingService; public AccountCreationController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, EmailSendingService emailSendingService) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Account/ChangeEmailController.cs b/GenderPayGap.WebUI/Controllers/Account/ChangeEmailController.cs index 995bf00d1..4599479a6 100644 --- a/GenderPayGap.WebUI/Controllers/Account/ChangeEmailController.cs +++ b/GenderPayGap.WebUI/Controllers/Account/ChangeEmailController.cs @@ -3,9 +3,9 @@ using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; using GenderPayGap.Extensions; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Account; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -18,12 +18,12 @@ public class ChangeEmailController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly EmailSendingService emailSendingService; public ChangeEmailController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, EmailSendingService emailSendingService) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Account/ChangePasswordController.cs b/GenderPayGap.WebUI/Controllers/Account/ChangePasswordController.cs index 23f552721..85ac17290 100644 --- a/GenderPayGap.WebUI/Controllers/Account/ChangePasswordController.cs +++ b/GenderPayGap.WebUI/Controllers/Account/ChangePasswordController.cs @@ -1,10 +1,10 @@ using GenderPayGap.Core; using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Classes; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Account; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -17,12 +17,12 @@ public class ChangePasswordController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly EmailSendingService emailSendingService; public ChangePasswordController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, EmailSendingService emailSendingService) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Account/CloseAccountController.cs b/GenderPayGap.WebUI/Controllers/Account/CloseAccountController.cs index e792bed0d..eb187cb55 100644 --- a/GenderPayGap.WebUI/Controllers/Account/CloseAccountController.cs +++ b/GenderPayGap.WebUI/Controllers/Account/CloseAccountController.cs @@ -4,7 +4,6 @@ using GenderPayGap.Core.Classes.Logger; using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Classes; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Account; @@ -21,13 +20,13 @@ public class CloseAccountController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly RegistrationRepository registrationRepository; private readonly EmailSendingService emailSendingService; public CloseAccountController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, RegistrationRepository registrationRepository, EmailSendingService emailSendingService) { diff --git a/GenderPayGap.WebUI/Controllers/Account/PasswordResetController.cs b/GenderPayGap.WebUI/Controllers/Account/PasswordResetController.cs index e2c378e1c..c94153f4c 100644 --- a/GenderPayGap.WebUI/Controllers/Account/PasswordResetController.cs +++ b/GenderPayGap.WebUI/Controllers/Account/PasswordResetController.cs @@ -5,10 +5,10 @@ using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; using GenderPayGap.Extensions; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.ErrorHandling; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Account; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Microsoft.AspNetCore.Mvc; @@ -18,12 +18,12 @@ public class PasswordResetController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly EmailSendingService emailSendingService; public PasswordResetController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, EmailSendingService emailSendingService) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminImpersonateUserController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminImpersonateUserController.cs index 45df1fbfc..60e4352e5 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminImpersonateUserController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminImpersonateUserController.cs @@ -2,9 +2,9 @@ using GenderPayGap.Core; using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Admin; +using GenderPayGap.WebUI.Repositories; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -15,10 +15,10 @@ namespace GenderPayGap.WebUI.Controllers.Admin public class AdminImpersonateUserController : Controller { - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly IDataRepository dataRepository; - public AdminImpersonateUserController(IUserRepository userRepository, IDataRepository dataRepository) + public AdminImpersonateUserController(UserRepository userRepository, IDataRepository dataRepository) { this.userRepository = userRepository; this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminManageAdminUsersController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminManageAdminUsersController.cs index 4245cdc30..efcc6d147 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminManageAdminUsersController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminManageAdminUsersController.cs @@ -3,10 +3,10 @@ using GenderPayGap.Core; using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.ErrorHandling; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Admin; +using GenderPayGap.WebUI.Repositories; using GenderPayGap.WebUI.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -19,12 +19,12 @@ public class AdminManageAdminUsersController : Controller { private readonly IDataRepository dataRepository; - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; private readonly AuditLogger auditLogger; public AdminManageAdminUsersController( IDataRepository dataRepository, - IUserRepository userRepository, + UserRepository userRepository, AuditLogger auditLogger) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Login/LoginController.cs b/GenderPayGap.WebUI/Controllers/Login/LoginController.cs index 1dc76a4a0..90e031b65 100644 --- a/GenderPayGap.WebUI/Controllers/Login/LoginController.cs +++ b/GenderPayGap.WebUI/Controllers/Login/LoginController.cs @@ -1,9 +1,9 @@ using System; using GenderPayGap.Core; using GenderPayGap.Database; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Models.Login; +using GenderPayGap.WebUI.Repositories; using Microsoft.AspNetCore.Mvc; namespace GenderPayGap.WebUI.Controllers.Login @@ -11,9 +11,9 @@ namespace GenderPayGap.WebUI.Controllers.Login public class LoginController : Controller { - private readonly IUserRepository userRepository; + private readonly UserRepository userRepository; - public LoginController(IUserRepository userRepository) + public LoginController(UserRepository userRepository) { this.userRepository = userRepository; } diff --git a/GenderPayGap.WebUI/Repositories/UserRepository.cs b/GenderPayGap.WebUI/Repositories/UserRepository.cs index 0a2d976d4..1a6b31f7b 100644 --- a/GenderPayGap.WebUI/Repositories/UserRepository.cs +++ b/GenderPayGap.WebUI/Repositories/UserRepository.cs @@ -5,13 +5,12 @@ using GenderPayGap.Core.Interfaces; using GenderPayGap.Database; using GenderPayGap.Extensions; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.Helpers; using GenderPayGap.WebUI.Services; namespace GenderPayGap.WebUI.Repositories { - public class UserRepository : IUserRepository + public class UserRepository { private readonly IDataRepository dataRepository; private readonly AuditLogger auditLogger; diff --git a/GenderPayGap.WebUI/Startup.cs b/GenderPayGap.WebUI/Startup.cs index 27b343cff..b2a0a15db 100644 --- a/GenderPayGap.WebUI/Startup.cs +++ b/GenderPayGap.WebUI/Startup.cs @@ -11,7 +11,6 @@ using GenderPayGap.Extensions.AspNetCore; using GenderPayGap.WebUI.BackgroundJobs; using GenderPayGap.WebUI.BackgroundJobs.HangfireConfiguration; -using GenderPayGap.WebUI.BusinessLogic.Abstractions; using GenderPayGap.WebUI.BusinessLogic.Services; using GenderPayGap.WebUI.Classes; using GenderPayGap.WebUI.Classes.Presentation; @@ -192,7 +191,7 @@ public IContainer BuildContainerIoC(IServiceCollection services) } // BL Services - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); From b2bb27138e164e1b8b3c9a08c775a5d5bea5477e Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 12 Nov 2024 17:58:30 +0000 Subject: [PATCH 3/6] EHD-1432: Reduce use of interfaces: ICompareViewService --- .../TestHelpers/UiTestHelpers.cs | 2 +- .../Presentation/CompareViewService.cs | 24 +------------------ .../Controllers/CompareEmployersController.cs | 4 ++-- .../Controllers/SearchController.cs | 4 ++-- .../Controllers/ViewReportsController.cs | 4 ++-- GenderPayGap.WebUI/Startup.cs | 2 +- .../AddRemoveEmployerNew.cshtml | 2 +- .../CompareEmployersForYear.cshtml | 2 +- .../ViewReports/ComparisonBasketNew.cshtml | 2 +- 9 files changed, 12 insertions(+), 34 deletions(-) diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs index 3cce33cf6..393dfd8bf 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs @@ -212,7 +212,7 @@ public static IContainer BuildContainerIoC(params object[] dbObjects) builder.RegisterType().As().SingleInstance(); - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().SingleInstance(); builder.RegisterType().As().InstancePerLifetimeScope(); diff --git a/GenderPayGap.WebUI/Classes/Presentation/CompareViewService.cs b/GenderPayGap.WebUI/Classes/Presentation/CompareViewService.cs index a30077935..d14a57b41 100644 --- a/GenderPayGap.WebUI/Classes/Presentation/CompareViewService.cs +++ b/GenderPayGap.WebUI/Classes/Presentation/CompareViewService.cs @@ -8,29 +8,7 @@ namespace GenderPayGap.WebUI.Classes.Presentation { - public interface ICompareViewService - { - - List ComparedEmployers { get; } - - int BasketItemCount { get; } - - void AddToBasket(long organisationId); - - void RemoveFromBasket(long organisationId); - - void ClearBasket(); - - void LoadComparedEmployersFromCookie(); - - void SaveComparedEmployersToCookie(); - void SaveComparedEmployersToCookieIfAnyAreObfuscated(); - - bool BasketContains(long organisationId); - - } - - public class CompareViewService : ICompareViewService + public class CompareViewService { private readonly HttpContext httpContext; diff --git a/GenderPayGap.WebUI/Controllers/CompareEmployersController.cs b/GenderPayGap.WebUI/Controllers/CompareEmployersController.cs index df18182ab..9535ac5fb 100644 --- a/GenderPayGap.WebUI/Controllers/CompareEmployersController.cs +++ b/GenderPayGap.WebUI/Controllers/CompareEmployersController.cs @@ -15,11 +15,11 @@ namespace GenderPayGap.WebUI.Controllers public class CompareEmployersController : Controller { - private readonly ICompareViewService compareViewService; + private readonly CompareViewService compareViewService; private readonly IDataRepository dataRepository; public CompareEmployersController( - ICompareViewService compareViewService, + CompareViewService compareViewService, IDataRepository dataRepository) { this.compareViewService = compareViewService; diff --git a/GenderPayGap.WebUI/Controllers/SearchController.cs b/GenderPayGap.WebUI/Controllers/SearchController.cs index 9f3e4efcf..c0b42ac70 100644 --- a/GenderPayGap.WebUI/Controllers/SearchController.cs +++ b/GenderPayGap.WebUI/Controllers/SearchController.cs @@ -14,13 +14,13 @@ namespace GenderPayGap.WebUI.Controllers public class SearchController : Controller { - private readonly ICompareViewService compareViewService; + private readonly CompareViewService compareViewService; private readonly IDataRepository dataRepository; private readonly ViewingSearchService viewingSearchService; private readonly AutoCompleteSearchService autoCompleteSearchService; public SearchController( - ICompareViewService compareViewService, + CompareViewService compareViewService, IDataRepository dataRepository, ViewingSearchService viewingSearchService, AutoCompleteSearchService autoCompleteSearchService) diff --git a/GenderPayGap.WebUI/Controllers/ViewReportsController.cs b/GenderPayGap.WebUI/Controllers/ViewReportsController.cs index c1da4d226..068da2577 100644 --- a/GenderPayGap.WebUI/Controllers/ViewReportsController.cs +++ b/GenderPayGap.WebUI/Controllers/ViewReportsController.cs @@ -10,11 +10,11 @@ public class ViewReportsController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompareViewService compareViewService; + private readonly CompareViewService compareViewService; public ViewReportsController( IDataRepository dataRepository, - ICompareViewService compareViewService) + CompareViewService compareViewService) { this.dataRepository = dataRepository; this.compareViewService = compareViewService; diff --git a/GenderPayGap.WebUI/Startup.cs b/GenderPayGap.WebUI/Startup.cs index b2a0a15db..dfa9e74a3 100644 --- a/GenderPayGap.WebUI/Startup.cs +++ b/GenderPayGap.WebUI/Startup.cs @@ -203,7 +203,7 @@ public IContainer BuildContainerIoC(IServiceCollection services) // register web ui services builder.RegisterType().As().InstancePerLifetimeScope(); - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); diff --git a/GenderPayGap.WebUI/Views/CompareEmployers/AddRemoveEmployerNew.cshtml b/GenderPayGap.WebUI/Views/CompareEmployers/AddRemoveEmployerNew.cshtml index 82b49cc33..e8bbe4862 100644 --- a/GenderPayGap.WebUI/Views/CompareEmployers/AddRemoveEmployerNew.cshtml +++ b/GenderPayGap.WebUI/Views/CompareEmployers/AddRemoveEmployerNew.cshtml @@ -1,4 +1,4 @@ -@inject ICompareViewService CompareViewService +@inject CompareViewService CompareViewService @model GenderPayGap.Database.Organisation @{ diff --git a/GenderPayGap.WebUI/Views/CompareEmployers/CompareEmployersForYear.cshtml b/GenderPayGap.WebUI/Views/CompareEmployers/CompareEmployersForYear.cshtml index 88cf4175d..fe7c82953 100644 --- a/GenderPayGap.WebUI/Views/CompareEmployers/CompareEmployersForYear.cshtml +++ b/GenderPayGap.WebUI/Views/CompareEmployers/CompareEmployersForYear.cshtml @@ -6,7 +6,7 @@ @using GovUkDesignSystem.GovUkDesignSystemComponents @using Microsoft.AspNetCore.Mvc.TagHelpers @using GenderPayGap.Core -@inject ICompareViewService CompareViewService +@inject CompareViewService CompareViewService @model GenderPayGap.WebUI.Models.Compare.CompareEmployersForYearViewModel @{ diff --git a/GenderPayGap.WebUI/Views/ViewReports/ComparisonBasketNew.cshtml b/GenderPayGap.WebUI/Views/ViewReports/ComparisonBasketNew.cshtml index d90ee414d..51bd533a4 100644 --- a/GenderPayGap.WebUI/Views/ViewReports/ComparisonBasketNew.cshtml +++ b/GenderPayGap.WebUI/Views/ViewReports/ComparisonBasketNew.cshtml @@ -1,4 +1,4 @@ -@inject ICompareViewService CompareViewService +@inject CompareViewService CompareViewService
Date: Tue, 12 Nov 2024 17:59:38 +0000 Subject: [PATCH 4/6] EHD-1432: Reduce use of interfaces: ICompaniesHouseAPI --- .../Services/UpdateFromCompaniesHouseService.cs | 4 ++-- .../AddOrganisation/AddOrganisationFoundController.cs | 4 ++-- .../Admin/AdminOrganisationAddressController.cs | 4 ++-- ...dminOrganisationCompaniesHouseOptInOutController.cs | 4 ++-- .../Admin/AdminOrganisationCompanyNumberController.cs | 4 ++-- .../Admin/AdminOrganisationNameController.cs | 4 ++-- .../Admin/AdminOrganisationSicCodesController.cs | 4 ++-- .../CompaniesHouse/CompaniesHouseAPI.cs | 10 +--------- .../Search/AddOrganisationSearchService.cs | 4 ++-- GenderPayGap.WebUI/Services/OrganisationService.cs | 4 ++-- GenderPayGap.WebUI/Startup.cs | 6 +++--- 11 files changed, 22 insertions(+), 30 deletions(-) diff --git a/GenderPayGap.WebUI/BusinessLogic/Services/UpdateFromCompaniesHouseService.cs b/GenderPayGap.WebUI/BusinessLogic/Services/UpdateFromCompaniesHouseService.cs index d64face2e..37a11f5b2 100644 --- a/GenderPayGap.WebUI/BusinessLogic/Services/UpdateFromCompaniesHouseService.cs +++ b/GenderPayGap.WebUI/BusinessLogic/Services/UpdateFromCompaniesHouseService.cs @@ -18,10 +18,10 @@ public class UpdateFromCompaniesHouseService private const string SourceOfChange = "CoHo"; private const string DetailsOfChange = "Replaced by CoHo"; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly IDataRepository dataRepository; - public UpdateFromCompaniesHouseService(IDataRepository dataRepository, ICompaniesHouseAPI companiesHouseApi) + public UpdateFromCompaniesHouseService(IDataRepository dataRepository, CompaniesHouseAPI companiesHouseApi) { this.dataRepository = dataRepository; this.companiesHouseApi = companiesHouseApi; diff --git a/GenderPayGap.WebUI/Controllers/AddOrganisation/AddOrganisationFoundController.cs b/GenderPayGap.WebUI/Controllers/AddOrganisation/AddOrganisationFoundController.cs index 1bfaded62..13b1405c3 100644 --- a/GenderPayGap.WebUI/Controllers/AddOrganisation/AddOrganisationFoundController.cs +++ b/GenderPayGap.WebUI/Controllers/AddOrganisation/AddOrganisationFoundController.cs @@ -22,13 +22,13 @@ public class AddOrganisationFoundController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly OrganisationService organisationService; private readonly RegistrationRepository registrationRepository; public AddOrganisationFoundController( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, OrganisationService organisationService, RegistrationRepository registrationRepository) { diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationAddressController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationAddressController.cs index 9fccfa4be..10db78eb0 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationAddressController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationAddressController.cs @@ -20,12 +20,12 @@ namespace GenderPayGap.WebUI.Controllers.Admin public class AdminOrganisationAddressController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly AuditLogger auditLogger; public AdminOrganisationAddressController( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, AuditLogger auditLogger) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompaniesHouseOptInOutController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompaniesHouseOptInOutController.cs index 369dfc0d9..39041c01e 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompaniesHouseOptInOutController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompaniesHouseOptInOutController.cs @@ -17,13 +17,13 @@ namespace GenderPayGap.WebUI.Controllers public class AdminOrganisationCompaniesHouseOptInOutController : Controller { private readonly AuditLogger auditLogger; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly IDataRepository dataRepository; private readonly UpdateFromCompaniesHouseService updateFromCompaniesHouseService; public AdminOrganisationCompaniesHouseOptInOutController(IDataRepository dataRepository, AuditLogger auditLogger, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, UpdateFromCompaniesHouseService updateFromCompaniesHouseService) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompanyNumberController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompanyNumberController.cs index a945fed9c..ae7d91334 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompanyNumberController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationCompanyNumberController.cs @@ -19,13 +19,13 @@ public class AdminOrganisationCompanyNumberController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly UpdateFromCompaniesHouseService updateFromCompaniesHouseService; private readonly AuditLogger auditLogger; public AdminOrganisationCompanyNumberController( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, UpdateFromCompaniesHouseService updateFromCompaniesHouseService, AuditLogger auditLogger) { diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationNameController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationNameController.cs index 61c607668..17f008df9 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationNameController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationNameController.cs @@ -19,12 +19,12 @@ namespace GenderPayGap.WebUI.Controllers.Admin public class AdminOrganisationNameController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly AuditLogger auditLogger; public AdminOrganisationNameController( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, AuditLogger auditLogger) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationSicCodesController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationSicCodesController.cs index a27988863..8463035c7 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationSicCodesController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationSicCodesController.cs @@ -20,12 +20,12 @@ namespace GenderPayGap.WebUI.Controllers.Admin public class AdminOrganisationSicCodesController : Controller { private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; private readonly AuditLogger auditLogger; public AdminOrganisationSicCodesController( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, AuditLogger auditLogger) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/ExternalServices/CompaniesHouse/CompaniesHouseAPI.cs b/GenderPayGap.WebUI/ExternalServices/CompaniesHouse/CompaniesHouseAPI.cs index 0ae7c6321..739982924 100644 --- a/GenderPayGap.WebUI/ExternalServices/CompaniesHouse/CompaniesHouseAPI.cs +++ b/GenderPayGap.WebUI/ExternalServices/CompaniesHouse/CompaniesHouseAPI.cs @@ -11,15 +11,7 @@ namespace GenderPayGap.WebUI.ExternalServices.CompaniesHouse { - public interface ICompaniesHouseAPI - { - - CompaniesHouseCompany GetCompany(string companyNumber); - List SearchCompanies(string query); - - } - - public class CompaniesHouseAPI : ICompaniesHouseAPI + public class CompaniesHouseAPI { private static readonly string ApiKey = Global.CompaniesHouseApiKey; diff --git a/GenderPayGap.WebUI/Search/AddOrganisationSearchService.cs b/GenderPayGap.WebUI/Search/AddOrganisationSearchService.cs index 984a6ca45..105bd31e7 100644 --- a/GenderPayGap.WebUI/Search/AddOrganisationSearchService.cs +++ b/GenderPayGap.WebUI/Search/AddOrganisationSearchService.cs @@ -29,11 +29,11 @@ public class AddOrganisationSearchService private const int MaximumNumberOfSearchResults = 100; private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; public AddOrganisationSearchService( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi) + CompaniesHouseAPI companiesHouseApi) { this.dataRepository = dataRepository; this.companiesHouseApi = companiesHouseApi; diff --git a/GenderPayGap.WebUI/Services/OrganisationService.cs b/GenderPayGap.WebUI/Services/OrganisationService.cs index f9ad20e86..1dd9f749e 100644 --- a/GenderPayGap.WebUI/Services/OrganisationService.cs +++ b/GenderPayGap.WebUI/Services/OrganisationService.cs @@ -22,11 +22,11 @@ private enum SourceOfData private readonly AuditLogger auditLogger; private readonly IDataRepository dataRepository; - private readonly ICompaniesHouseAPI companiesHouseApi; + private readonly CompaniesHouseAPI companiesHouseApi; public OrganisationService( IDataRepository dataRepository, - ICompaniesHouseAPI companiesHouseApi, + CompaniesHouseAPI companiesHouseApi, AuditLogger auditLogger) { this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Startup.cs b/GenderPayGap.WebUI/Startup.cs index dfa9e74a3..0fe4e3d3a 100644 --- a/GenderPayGap.WebUI/Startup.cs +++ b/GenderPayGap.WebUI/Startup.cs @@ -68,7 +68,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services) .AddPolicyHandler(GoogleAnalyticsTracker.GetRetryPolicy()); //Add a dedicated httpclient for Companies house API with exponential retry policy - services.AddHttpClient(nameof(ICompaniesHouseAPI), CompaniesHouseAPI.SetupHttpClient) + services.AddHttpClient(nameof(CompaniesHouseAPI), CompaniesHouseAPI.SetupHttpClient) .SetHandlerLifetime(TimeSpan.FromMinutes(10)) .AddPolicyHandler(CompaniesHouseAPI.GetRetryPolicy()); @@ -167,11 +167,11 @@ public IContainer BuildContainerIoC(IServiceCollection services) .InstancePerLifetimeScope(); builder.RegisterType() - .As() + .As() .SingleInstance() .WithParameter( (p, ctx) => p.ParameterType == typeof(HttpClient), - (p, ctx) => ctx.Resolve().CreateClient(nameof(ICompaniesHouseAPI))); + (p, ctx) => ctx.Resolve().CreateClient(nameof(CompaniesHouseAPI))); if (!Config.IsLocal()) { From 928b952e15793b5d0dc9b8cb0398598448dcf755 Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 12 Nov 2024 18:01:07 +0000 Subject: [PATCH 5/6] EHD-1432: Reduce use of interfaces: IScopeBusinessLogic --- .../ScopeBusinessLogic/FillMissingScopesTests.cs | 2 +- .../FindOrgsWhereScopeNotSetTests.cs | 2 +- .../Services/ScopeBusinessLogicTests.cs | 2 +- .../TestHelpers/UiTestHelpers.cs | 8 +------- .../ScheduledJobs/SetPresumedScopesJob.cs | 4 ++-- .../BusinessLogic/Services/ScopeBusinessLogic.cs | 16 +--------------- GenderPayGap.WebUI/Startup.cs | 2 +- 7 files changed, 8 insertions(+), 28 deletions(-) diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FillMissingScopesTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FillMissingScopesTests.cs index 775ea8b2f..b0a9cb912 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FillMissingScopesTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FillMissingScopesTests.cs @@ -31,7 +31,7 @@ public void BeforeEach() private Mock mockDataRepository; // sut - private IScopeBusinessLogic scopeBusinessLogic; + private WebUI.BusinessLogic.Services.ScopeBusinessLogic scopeBusinessLogic; [TestCase(SectorTypes.Private)] [TestCase(SectorTypes.Public)] diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FindOrgsWhereScopeNotSetTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FindOrgsWhereScopeNotSetTests.cs index 0c395ab90..bd3256463 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FindOrgsWhereScopeNotSetTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/BusinessLogicTests/Services/ScopeBusinessLogic/FindOrgsWhereScopeNotSetTests.cs @@ -49,7 +49,7 @@ public void BeforeEach() private List testOrgs; // sut - private IScopeBusinessLogic scopeBusinessLogic; + private WebUI.BusinessLogic.Services.ScopeBusinessLogic scopeBusinessLogic; [TestCase(1)] [TestCase(2)] diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Services/ScopeBusinessLogicTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Services/ScopeBusinessLogicTests.cs index 7669c2fdc..de453d405 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Services/ScopeBusinessLogicTests.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Services/ScopeBusinessLogicTests.cs @@ -24,7 +24,7 @@ public class ScopeBusinessLogicTests : AssertionHelper private IList testOrgData; private IList testOrgScopeData; - public IScopeBusinessLogic testScopeBL; + public ScopeBusinessLogic testScopeBL; #region Test Data diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs index 393dfd8bf..f4dc53b0b 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs @@ -200,13 +200,7 @@ public static IContainer BuildContainerIoC(params object[] dbObjects) builder.RegisterInstance(Config.Configuration); builder.RegisterType().As().InstancePerLifetimeScope(); - builder.Register( - c => c.ResolveAsMock( - false, - typeof(IDataRepository)) - .Object) - .As() - .InstancePerLifetimeScope(); + builder.RegisterType().As().SingleInstance(); builder.Register(g => new MockGovNotify()).As().SingleInstance(); diff --git a/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SetPresumedScopesJob.cs b/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SetPresumedScopesJob.cs index c1ebaf682..43c6ea29f 100644 --- a/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SetPresumedScopesJob.cs +++ b/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SetPresumedScopesJob.cs @@ -5,10 +5,10 @@ namespace GenderPayGap.WebUI.BackgroundJobs.ScheduledJobs public class SetPresumedScopesJob { - private readonly IScopeBusinessLogic scopeBusinessLogic; + private readonly ScopeBusinessLogic scopeBusinessLogic; public SetPresumedScopesJob( - IScopeBusinessLogic scopeBusinessLogic) + ScopeBusinessLogic scopeBusinessLogic) { this.scopeBusinessLogic = scopeBusinessLogic; } diff --git a/GenderPayGap.WebUI/BusinessLogic/Services/ScopeBusinessLogic.cs b/GenderPayGap.WebUI/BusinessLogic/Services/ScopeBusinessLogic.cs index 2908fd15b..868d9e703 100644 --- a/GenderPayGap.WebUI/BusinessLogic/Services/ScopeBusinessLogic.cs +++ b/GenderPayGap.WebUI/BusinessLogic/Services/ScopeBusinessLogic.cs @@ -10,21 +10,7 @@ namespace GenderPayGap.WebUI.BusinessLogic.Services { - public interface IScopeBusinessLogic - { - - OrganisationScope GetLatestScopeBySnapshotYear(long organisationId, int snapshotYear = 0); - - void SetPresumedScopes(); - - HashSet FindOrgsWhereScopeNotSet(); - bool FillMissingScopes(Organisation org); - - void SetScopeStatuses(); - - } - - public class ScopeBusinessLogic : IScopeBusinessLogic + public class ScopeBusinessLogic { public ScopeBusinessLogic(IDataRepository dataRepo) diff --git a/GenderPayGap.WebUI/Startup.cs b/GenderPayGap.WebUI/Startup.cs index 0fe4e3d3a..48f43a474 100644 --- a/GenderPayGap.WebUI/Startup.cs +++ b/GenderPayGap.WebUI/Startup.cs @@ -197,7 +197,7 @@ public IContainer BuildContainerIoC(IServiceCollection services) builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); - builder.RegisterType().As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); builder.RegisterType().As().InstancePerLifetimeScope(); From d1d705dd856e0c2bd9553dbec9b73a627275cbdd Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 12 Nov 2024 18:01:49 +0000 Subject: [PATCH 6/6] EHD-1432: Reduce use of interfaces: IWebTracker --- .../TestHelpers/UiTestHelpers.cs | 4 ++-- .../GenderPayGap.WebUI.Tests/appsettings.json | 3 ++- .../Classes/GoogleAnalyticsTracker.cs | 24 ++++++++----------- .../Controllers/DownloadController.cs | 4 ++-- .../Controllers/RedirectController.cs | 4 ++-- GenderPayGap.WebUI/Startup.cs | 6 ++--- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs index f4dc53b0b..ea30ce929 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/TestHelpers/UiTestHelpers.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -214,7 +214,7 @@ public static IContainer BuildContainerIoC(params object[] dbObjects) //Register WebTracker - builder.Register(c => Mock.Of()).As().InstancePerLifetimeScope(); + builder.RegisterType().As().InstancePerLifetimeScope(); //Register all controllers - this is required to ensure KeyFilter is resolved in constructors builder.RegisterType().InstancePerLifetimeScope(); diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/appsettings.json b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/appsettings.json index 8d87a3fcd..1a27d82f5 100644 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/appsettings.json +++ b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/appsettings.json @@ -1,4 +1,5 @@ { "DefaultEncryptionKey": "", // some unit tests require this key to be empty - "OffsetCurrentDateTimeForSite": "917" + "OffsetCurrentDateTimeForSite": "917", + "GoogleAnalyticsAccountId": null } \ No newline at end of file diff --git a/GenderPayGap.WebUI/Classes/GoogleAnalyticsTracker.cs b/GenderPayGap.WebUI/Classes/GoogleAnalyticsTracker.cs index 6754b4c96..124b83c03 100644 --- a/GenderPayGap.WebUI/Classes/GoogleAnalyticsTracker.cs +++ b/GenderPayGap.WebUI/Classes/GoogleAnalyticsTracker.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Net; using System.Net.Http; +using System.Threading.Tasks; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http.Extensions; using Microsoft.AspNetCore.Mvc; @@ -10,17 +11,11 @@ namespace GenderPayGap.WebUI.Classes { - public interface IWebTracker - { - void TrackPageView(Controller controller, string pageTitle = null, string pageUrl = null); - } - - /// /// Uses open HttpClient see /// https://www.codeproject.com/Articles/1194406/Using-HttpClient-as-it-was-intended-because-you-re /// - public class GoogleAnalyticsTracker : IWebTracker, IDisposable + public class GoogleAnalyticsTracker : IDisposable { public static Uri BaseUri = new Uri("https://www.google-analytics.com"); @@ -28,14 +23,12 @@ public class GoogleAnalyticsTracker : IWebTracker, IDisposable private readonly HttpClient _httpClient; - private readonly IHttpContextAccessor _httpContextAccessor; private readonly string googleTrackingId; // UA-XXXXXXXXX-XX private readonly string googleVersion = "1"; - public GoogleAnalyticsTracker(IHttpContextAccessor httpContextAccessor, HttpClient httpClient, string trackingId) + public GoogleAnalyticsTracker(HttpClient httpClient, string trackingId) { - _httpContextAccessor = httpContextAccessor ?? throw new ArgumentNullException(nameof(httpContextAccessor)); _httpClient = httpClient; googleTrackingId = trackingId; } @@ -46,8 +39,7 @@ public void Dispose() { _httpClient?.Dispose(); } - - + public void TrackPageView(Controller controller, string pageTitle = null, string pageUrl = null) { if (string.IsNullOrWhiteSpace(pageTitle)) @@ -71,10 +63,14 @@ public void TrackPageView(Controller controller, string pageTitle = null, string SendPageViewTracking(pageTitle, pageUrl); } - - + private async void SendPageViewTracking(string title, string url) { + if (googleTrackingId == null) + { + return; + } + if (string.IsNullOrWhiteSpace(title)) { throw new ArgumentNullException(nameof(title)); diff --git a/GenderPayGap.WebUI/Controllers/DownloadController.cs b/GenderPayGap.WebUI/Controllers/DownloadController.cs index fde0ed690..6fed75838 100644 --- a/GenderPayGap.WebUI/Controllers/DownloadController.cs +++ b/GenderPayGap.WebUI/Controllers/DownloadController.cs @@ -16,11 +16,11 @@ public class DownloadController : Controller { private readonly IFileRepository fileRepository; - private readonly IWebTracker webTracker; + private readonly GoogleAnalyticsTracker webTracker; public DownloadController( IFileRepository fileRepository, - IWebTracker webTracker) + GoogleAnalyticsTracker webTracker) { this.fileRepository = fileRepository; this.webTracker = webTracker; diff --git a/GenderPayGap.WebUI/Controllers/RedirectController.cs b/GenderPayGap.WebUI/Controllers/RedirectController.cs index 6fe8fe465..8c9516e45 100644 --- a/GenderPayGap.WebUI/Controllers/RedirectController.cs +++ b/GenderPayGap.WebUI/Controllers/RedirectController.cs @@ -17,10 +17,10 @@ public class RedirectController : Controller // This class contains redirects for outdated URLs // Some of these URLs might appear in emails / printed letters, so we want to redirect to an appropriate page, rather than showing a 404 - private readonly IWebTracker webTracker; + private readonly GoogleAnalyticsTracker webTracker; private readonly IDataRepository dataRepository; - public RedirectController(IWebTracker webTracker, IDataRepository dataRepository) + public RedirectController(GoogleAnalyticsTracker webTracker, IDataRepository dataRepository) { this.webTracker = webTracker; this.dataRepository = dataRepository; diff --git a/GenderPayGap.WebUI/Startup.cs b/GenderPayGap.WebUI/Startup.cs index 48f43a474..0baa8d3ea 100644 --- a/GenderPayGap.WebUI/Startup.cs +++ b/GenderPayGap.WebUI/Startup.cs @@ -63,7 +63,7 @@ public IServiceProvider ConfigureServices(IServiceCollection services) }); //Add a dedicated httpclient for Google Analytics tracking with exponential retry policy - services.AddHttpClient(nameof(IWebTracker), GoogleAnalyticsTracker.SetupHttpClient) + services.AddHttpClient(nameof(GoogleAnalyticsTracker), GoogleAnalyticsTracker.SetupHttpClient) .SetHandlerLifetime(TimeSpan.FromMinutes(10)) .AddPolicyHandler(GoogleAnalyticsTracker.GetRetryPolicy()); @@ -228,11 +228,11 @@ public IContainer BuildContainerIoC(IServiceCollection services) //Register WebTracker builder.RegisterType() - .As() + .As() .SingleInstance() .WithParameter( (p, ctx) => p.ParameterType == typeof(HttpClient), - (p, ctx) => ctx.Resolve().CreateClient(nameof(IWebTracker))) + (p, ctx) => ctx.Resolve().CreateClient(nameof(GoogleAnalyticsTracker))) .WithParameter("trackingId", Global.GoogleAnalyticsAccountId); //TOD: Implement AutoFac modules