|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System.Linq; |
| 5 | +using Microsoft.AspNetCore.Builder; |
| 6 | +using Microsoft.Extensions.DependencyInjection; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace Microsoft.Identity.Web.Test |
| 10 | +{ |
| 11 | + public class TestTokenAcquisitionHost |
| 12 | + { |
| 13 | + [Fact] |
| 14 | + public void TestTokenAcquisitionHostNotAspNetCore() |
| 15 | + { |
| 16 | + // When not adding Services.AddAuthentication, the host should be |
| 17 | + TokenAcquirerFactory tokenAcquirerFactory = TokenAcquirerFactory.GetDefaultInstance(); |
| 18 | + var host = tokenAcquirerFactory.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); |
| 19 | + Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.Hosts.DefaultTokenAcquisitionHost"); |
| 20 | + } |
| 21 | + |
| 22 | + [Fact] |
| 23 | + public void TestTokenAcquisitionAspNetCoreBuilderNoAuth() |
| 24 | + { |
| 25 | + // When not adding Services.AddAuthentication, the host should be |
| 26 | + var builder = WebApplication.CreateBuilder(); |
| 27 | + builder.Services.AddTokenAcquisition(); |
| 28 | + var host = builder.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); |
| 29 | + Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.Hosts.DefaultTokenAcquisitionHost"); |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + [Fact] |
| 34 | + public void TestTokenAcquisitionAspNetCoreBuilderAuth() |
| 35 | + { |
| 36 | + // When not adding Services.AddAuthentication, the host should be |
| 37 | + var builder = WebApplication.CreateBuilder(); |
| 38 | + builder.Services.AddAuthentication() |
| 39 | + .AddMicrosoftIdentityWebApi(builder.Configuration) |
| 40 | + .EnableTokenAcquisitionToCallDownstreamApi(); |
| 41 | + |
| 42 | + var host = builder.Services.First(s => s.ServiceType.FullName == "Microsoft.Identity.Web.ITokenAcquisitionHost"); |
| 43 | + Assert.True(host.ImplementationType!.FullName == "Microsoft.Identity.Web.TokenAcquisitionAspnetCoreHost"); |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments