|
| 1 | +using Microsoft.AspNetCore.Authentication.WsFederation; |
| 2 | +using Microsoft.AspNetCore.Builder; |
| 3 | +using Microsoft.Extensions.DependencyInjection; |
| 4 | +using Moq; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Linq; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace Aguacongas.AspNetCore.Authentication.Test |
| 10 | +{ |
| 11 | + public class ApplicationBuilderExtensionsTest |
| 12 | + { |
| 13 | + [Fact] |
| 14 | + public void LoadDynamicAuthenticationConfiguration_should_load_WsFederationOptions() |
| 15 | + { |
| 16 | + var serializer = new AuthenticationSchemeOptionsSerializer(); |
| 17 | + var serialized = serializer.SerializeOptions(new WsFederationOptions |
| 18 | + { |
| 19 | + RequireHttpsMetadata = false, |
| 20 | + MetadataAddress = "http://localhost:5000/wsfederation", |
| 21 | + Wtrealm = "urm:aspnetcorerp" |
| 22 | + }, typeof(WsFederationOptions)); |
| 23 | + var storeMock = new Mock<IDynamicProviderStore<SchemeDefinition>>(); |
| 24 | + storeMock.Setup(m => m.SchemeDefinitions).Returns(new List<string> |
| 25 | + { |
| 26 | + serialized |
| 27 | + }.Select(s => new SchemeDefinition |
| 28 | + { |
| 29 | + DisplayName = "test", |
| 30 | + HandlerType = typeof(WsFederationHandler), |
| 31 | + Options = serializer.DeserializeOptions(s, typeof(WsFederationOptions)), |
| 32 | + Scheme = "test" |
| 33 | + }).AsQueryable()); |
| 34 | + var services = new ServiceCollection().AddTransient(p => storeMock.Object); |
| 35 | + |
| 36 | + services.AddAuthentication() |
| 37 | + .AddDynamic<SchemeDefinition>() |
| 38 | + .AddWsFederation(); |
| 39 | + |
| 40 | + var provider = services.BuildServiceProvider(); |
| 41 | + var applicationBuilderMock = new Mock<IApplicationBuilder>(); |
| 42 | + applicationBuilderMock.SetupGet(m => m.ApplicationServices).Returns(provider); |
| 43 | + |
| 44 | + applicationBuilderMock.Object.LoadDynamicAuthenticationConfiguration<SchemeDefinition>(); |
| 45 | + |
| 46 | + Assert.True(true); |
| 47 | + } |
| 48 | + |
| 49 | + public class SchemeDefinition : SchemeDefinitionBase |
| 50 | + { |
| 51 | + |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments