|
| 1 | +// Licensed to the .NET Foundation under one or more agreements. |
| 2 | +// The .NET Foundation licenses this file to you under the Apache 2.0 License |
| 3 | +// See the LICENSE file in the project root for more information. |
| 4 | +// Maintainer: Argo Zhang([email protected]) Website: https://www.blazor.zone |
| 5 | + |
| 6 | +using Microsoft.Extensions.Configuration; |
| 7 | +using Microsoft.Extensions.Options; |
| 8 | + |
| 9 | +namespace UnitTest.Options; |
| 10 | + |
| 11 | +public class OtpOptionsTest |
| 12 | +{ |
| 13 | + [Fact] |
| 14 | + public void OtpOptions_Ok() |
| 15 | + { |
| 16 | + var serviceCollection = new ServiceCollection(); |
| 17 | + serviceCollection.AddBootstrapBlazor(); |
| 18 | + AddOptions(serviceCollection); |
| 19 | + |
| 20 | + var provider = serviceCollection.BuildServiceProvider(); |
| 21 | + var options = provider.GetRequiredService<IOptions<OtpOptions>>().Value; |
| 22 | + Assert.Equal("OMM2LVLFX6QJHMYI", options.SecretKey); |
| 23 | + Assert.Equal("Simulator", options.IssuerName); |
| 24 | + Assert.Equal("BootstrapBlazor", options.AccountName); |
| 25 | + Assert.Equal("BootstrapBlazor", options.UserName); |
| 26 | + Assert.Equal(OtpHashMode.Sha1, options.Algorithm); |
| 27 | + Assert.Equal(OtpType.Totp, options.Type); |
| 28 | + Assert.Equal(6, options.Digits); |
| 29 | + Assert.Equal(30, options.Period); |
| 30 | + Assert.Equal(0, options.Counter); |
| 31 | + } |
| 32 | + |
| 33 | + private static void AddOptions(ServiceCollection serviceCollection) |
| 34 | + { |
| 35 | + var builder = new ConfigurationBuilder(); |
| 36 | + builder.AddInMemoryCollection(new Dictionary<string, string?>() |
| 37 | + { |
| 38 | + { "OtpOptions:SecretKey", "OMM2LVLFX6QJHMYI" }, |
| 39 | + { "OtpOptions:IssuerName", "Simulator" }, |
| 40 | + { "OtpOptions:AccountName", "BootstrapBlazor" }, |
| 41 | + { "OtpOptions:UserName", "BootstrapBlazor" }, |
| 42 | + { "OtpOptions:Algorithm", OtpHashMode.Sha1.ToString() }, |
| 43 | + { "OtpOptions:Type", OtpType.Totp.ToString() }, |
| 44 | + { "OtpOptions:Digits", "6" }, |
| 45 | + { "OtpOptions:Period", "30" }, |
| 46 | + { "OtpOptions:Counter", "0" } |
| 47 | + }); |
| 48 | + var config = builder.Build(); |
| 49 | + serviceCollection.AddSingleton<IConfiguration>(config); |
| 50 | + } |
| 51 | +} |
0 commit comments