Skip to content

Commit

Permalink
Feat #422 CDP4-SDK upgraded to 26.6.0 and httpclient from blazor used…
Browse files Browse the repository at this point in the history
… into the CDP4ServicesDal (#535)

* sdk version updated and blazor httpclient is now added to CdpServicesDal constructor

* sdk version upgraded to 26.6.0
  • Loading branch information
joao4all authored Mar 14, 2024
1 parent c39cec5 commit 5b459bc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void VerifyServerRegistration()
var serviceCollection = new ServiceCollection();
var configuration = new Mock<IConfiguration>();
serviceCollection.AddSingleton(configuration.Object);
serviceCollection.AddScoped(_ => new HttpClient());
serviceCollection.AddLogging();
serviceCollection.RegisterCdp4CometCommonServices(globalOptions: _ => { });
var serviceProvider = serviceCollection.BuildServiceProvider();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class AuthenticationServiceTestFixture
private AuthenticationDto authenticationDto;
private Person person;
private CDPMessageBus messageBus;
private HttpClient httpClient;

[SetUp]
public void SetUp()
Expand All @@ -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();

Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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<bool>())).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
{
Expand All @@ -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<bool>())).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);

Expand All @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/COMET.Web.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AsyncEnumerator" Version="4.0.2" />
<PackageReference Include="CDP4ServicesDal-CE" Version="26.3.0" />
<PackageReference Include="CDP4ServicesDal-CE" Version="26.6.0" />
<PackageReference Include="DevExpress.Blazor" Version="23.2.3" />
<PackageReference Include="FluentResults" Version="3.15.2" />
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="8.0.2" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class AuthenticationService : IAuthenticationService
/// </summary>
private readonly ICDPMessageBus messageBus;

/// <summary>
/// The <see cref="HttpClient" /> used to retrieve data
/// </summary>
private readonly HttpClient httpClient;

/// <summary>
/// Initializes a new instance of the <see cref="AuthenticationService" /> class.
/// </summary>
Expand All @@ -67,11 +72,13 @@ public class AuthenticationService : IAuthenticationService
/// The (injected) <see cref="AuthenticationStateProvider" />
/// </param>
/// <param name="messageBus">The <see cref="ICDPMessageBus"/></param>
public AuthenticationService(ISessionService sessionService, AuthenticationStateProvider authenticationStateProvider, ICDPMessageBus messageBus)
/// <param name="httpClient">The <see cref="HttpClient"/></param>
public AuthenticationService(ISessionService sessionService, AuthenticationStateProvider authenticationStateProvider, ICDPMessageBus messageBus, HttpClient httpClient)
{
this.messageBus = messageBus;
this.authStateProvider = authenticationStateProvider;
this.sessionService = sessionService;
this.httpClient = httpClient;
}

/// <summary>
Expand All @@ -88,7 +95,7 @@ public async Task<AuthenticationStateKind> 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);
Expand Down

0 comments on commit 5b459bc

Please sign in to comment.