77 lines
1.5 KiB
C#
77 lines
1.5 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Identity.Client;
|
|
using System.Net.Http.Headers;
|
|
|
|
namespace Shogi.AcceptanceTests.TestSetup
|
|
{
|
|
/// <summary>
|
|
/// Acceptance Test fixture for tests which assert features for Microsoft accounts.
|
|
/// </summary>
|
|
public class GuestTestFixture : IAsyncLifetime, IDisposable
|
|
{
|
|
private bool disposedValue;
|
|
private readonly IConfidentialClientApplication app;
|
|
|
|
public GuestTestFixture()
|
|
{
|
|
Configuration = new ConfigurationBuilder()
|
|
.AddJsonFile("appsettings.json")
|
|
//.AddEnvironmentVariables()
|
|
.Build();
|
|
|
|
Service = new HttpClient
|
|
{
|
|
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();
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
if (!disposedValue)
|
|
{
|
|
if (disposing)
|
|
{
|
|
Service.Dispose();
|
|
}
|
|
|
|
disposedValue = true;
|
|
}
|
|
}
|
|
|
|
public Task DisposeAsync()
|
|
{
|
|
Dispose(true);
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
}
|
|
}
|