Skip to content

Commit f796495

Browse files
committed
test: 增加单元测试
1 parent 403ff5d commit f796495

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
namespace UnitTest.Services;
7+
8+
public class TotpServiceTest
9+
{
10+
[Fact]
11+
public void TotpService_Ok()
12+
{
13+
var serviceCollection = new ServiceCollection();
14+
serviceCollection.AddBootstrapBlazor();
15+
16+
var provider = serviceCollection.BuildServiceProvider();
17+
var service = provider.GetRequiredService<ITotpService>();
18+
var data = service.GenerateSecretKey();
19+
Assert.Equal("OMM2LVLFX6QJHMYI", data);
20+
Assert.Equal("123456", service.Compute("OMM2LVLFX6QJHMYI"));
21+
Assert.Equal("otpauth://totp/BootstrapBlazor?secret=OMM2LVLFX6QJHMYI&issuer=Simulator", service.GenerateOtpUri());
22+
Assert.Empty(service.GetSecretKeyBytes(""));
23+
Assert.Equal(30, service.GetRemainingSeconds());
24+
Assert.False(service.Verify("123456"));
25+
Assert.Equal(30, service.Instance.GetRemainingSeconds());
26+
Assert.False(service.Instance.Verify("123456"));
27+
}
28+
}

0 commit comments

Comments
 (0)