diff --git a/COMET.Web.Common.Tests/Extensions/ServiceCollectionExtensionsTestFixture.cs b/COMET.Web.Common.Tests/Extensions/ServiceCollectionExtensionsTestFixture.cs index 11785022..bd3102f0 100644 --- a/COMET.Web.Common.Tests/Extensions/ServiceCollectionExtensionsTestFixture.cs +++ b/COMET.Web.Common.Tests/Extensions/ServiceCollectionExtensionsTestFixture.cs @@ -46,6 +46,7 @@ public void VerifyServerRegistration() var serviceCollection = new ServiceCollection(); var configuration = new Mock(); serviceCollection.AddSingleton(configuration.Object); + serviceCollection.AddScoped(_ => new HttpClient()); serviceCollection.AddLogging(); serviceCollection.RegisterCdp4CometCommonServices(globalOptions: _ => { }); var serviceProvider = serviceCollection.BuildServiceProvider(); diff --git a/COMET.Web.Common.Tests/Services/SessionManagement/AuthenticationServiceTestFixture.cs b/COMET.Web.Common.Tests/Services/SessionManagement/AuthenticationServiceTestFixture.cs index e5d3e154..a8f59de4 100644 --- a/COMET.Web.Common.Tests/Services/SessionManagement/AuthenticationServiceTestFixture.cs +++ b/COMET.Web.Common.Tests/Services/SessionManagement/AuthenticationServiceTestFixture.cs @@ -47,6 +47,7 @@ public class AuthenticationServiceTestFixture private AuthenticationDto authenticationDto; private Person person; private CDPMessageBus messageBus; + private HttpClient httpClient; [SetUp] public void SetUp() @@ -73,18 +74,20 @@ public void SetUp() }; this.messageBus = new CDPMessageBus(); + this.httpClient = new HttpClient(); } [TearDown] public void Teardown() { + this.httpClient.Dispose(); this.messageBus.ClearSubscriptions(); } [Test] public async Task Verify_that_a_logged_in_user_can_logout() { - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); await authenticationService.Logout(); @@ -98,7 +101,7 @@ public async Task Verify_that_a_nonauthorized_user_cannot_login() this.sessionService.Setup(x => x.GetSiteDirectory()).Returns((SiteDirectory)null); - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); var loginResult = await authenticationService.Login(this.authenticationDto); @@ -114,7 +117,7 @@ public async Task Verify_that_an_authorized_user_can_login() this.sessionService.Setup(x => x.GetSiteDirectory()).Returns(siteDirectory); - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); var loginResult = await authenticationService.Login(this.authenticationDto); @@ -126,7 +129,7 @@ public async Task Verify_that_when_the_server_cannot_be_reached_the_login_fails( { this.session.Setup(x => x.Open(It.IsAny())).Throws(new DalReadException()); - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); var authentication = new AuthenticationDto { @@ -145,7 +148,7 @@ public async Task Verify_that_when_the_server_returns_an_error_the_login_fails() { this.session.Setup(x => x.Open(It.IsAny())).Throws(new DalReadException()); - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); var loginResult = await authenticationService.Login(this.authenticationDto); @@ -157,7 +160,7 @@ public async Task Verify_that_when_the_source_address_is_null_authentication_fai { this.authenticationDto.SourceAddress = null; - var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus); + var authenticationService = new AuthenticationService(this.sessionService.Object, this.cometWebAuthStateProvider, this.messageBus, this.httpClient); var loginResult = await authenticationService.Login(this.authenticationDto); diff --git a/COMET.Web.Common/COMET.Web.Common.csproj b/COMET.Web.Common/COMET.Web.Common.csproj index 91616508..c716486b 100644 --- a/COMET.Web.Common/COMET.Web.Common.csproj +++ b/COMET.Web.Common/COMET.Web.Common.csproj @@ -29,7 +29,7 @@ - + diff --git a/COMET.Web.Common/Services/SessionManagement/AuthenticationService.cs b/COMET.Web.Common/Services/SessionManagement/AuthenticationService.cs index 5898f402..29a9da50 100644 --- a/COMET.Web.Common/Services/SessionManagement/AuthenticationService.cs +++ b/COMET.Web.Common/Services/SessionManagement/AuthenticationService.cs @@ -57,6 +57,11 @@ public class AuthenticationService : IAuthenticationService /// private readonly ICDPMessageBus messageBus; + /// + /// The used to retrieve data + /// + private readonly HttpClient httpClient; + /// /// Initializes a new instance of the class. /// @@ -67,11 +72,13 @@ public class AuthenticationService : IAuthenticationService /// The (injected) /// /// The - public AuthenticationService(ISessionService sessionService, AuthenticationStateProvider authenticationStateProvider, ICDPMessageBus messageBus) + /// The + public AuthenticationService(ISessionService sessionService, AuthenticationStateProvider authenticationStateProvider, ICDPMessageBus messageBus, HttpClient httpClient) { this.messageBus = messageBus; this.authStateProvider = authenticationStateProvider; this.sessionService = sessionService; + this.httpClient = httpClient; } /// @@ -88,7 +95,7 @@ public async Task Login(AuthenticationDto authenticatio if (authenticationDto.SourceAddress != null) { var uri = new Uri(authenticationDto.SourceAddress); - var dal = new CdpServicesDal(); + var dal = new CdpServicesDal(this.httpClient); var credentials = new Credentials(authenticationDto.UserName, authenticationDto.Password, uri); this.sessionService.Session = new Session(dal, credentials, this.messageBus);