This commit is contained in:
2022-10-30 12:47:39 -05:00
parent 93027e8c57
commit b8ac227199
6 changed files with 28 additions and 29 deletions

View File

@@ -1,6 +1,4 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Identity.Client;
using System.Net.Http.Headers;
namespace Shogi.AcceptanceTests.TestSetup
{
@@ -10,7 +8,6 @@ namespace Shogi.AcceptanceTests.TestSetup
public class GuestTestFixture : IAsyncLifetime, IDisposable
{
private bool disposedValue;
private readonly IConfidentialClientApplication app;
public GuestTestFixture()
{
@@ -24,28 +21,17 @@ namespace Shogi.AcceptanceTests.TestSetup
BaseAddress = new Uri(Configuration["ServiceUrl"], UriKind.Absolute)
};
publicApp = PublicClientApplicationBuilder
.Create(azure["ClientId"])
.WithTenantId("common")
.Build();
}
public IConfiguration Configuration { get; private set; }
public HttpClient Service { get; }
public async Task InitializeAsync()
{
var scopes = Configuration.GetSection("Auth:Scopes").Get<string[]>();
var authResult = await app
.AcquireTokenForClient(scopes)
.ExecuteAsync();
authResult.Should().NotBeNull();
authResult.AccessToken.Should().NotBeNullOrEmpty();
// Log in as a guest account.
var loginResponse = await Service.GetAsync(new Uri("User/LoginAsGuest", UriKind.Relative));
loginResponse.EnsureSuccessStatusCode();
}
protected virtual void Dispose(bool disposing)