-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
LogtoUtilsTests.cs
44 lines (39 loc) · 1.25 KB
/
LogtoUtilsTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
namespace Logto.AspNetCore.Authentication.Tests;
public class LogtoUtilsTests_GetExpiresAt
{
[Fact]
public void ShouldReturnFutureDate()
{
// Add 1 second to the current time, should be in the future since tests are fast
var expiresAtString = LogtoUtils.GetExpiresAt(1);
var expiresAt = DateTimeOffset.Parse(expiresAtString);
var now = DateTimeOffset.UtcNow;
Assert.True(expiresAt > now);
}
}
public class LogtoUtilsTests_IsExpired
{
[Fact]
public void ShouldReturnTrueIfTimeStringIsNullOrEmpty()
{
Assert.True(LogtoUtils.IsExpired(null));
Assert.True(LogtoUtils.IsExpired(string.Empty));
}
[Fact]
public void ShouldReturnTrueIfTimeStringIsNotParsable()
{
Assert.True(LogtoUtils.IsExpired("foo"));
}
[Fact]
public void ShouldReturnTrueIfTimeStringIsExpired()
{
var expiresAt = DateTimeOffset.UtcNow.AddSeconds(-1);
Assert.True(LogtoUtils.IsExpired(expiresAt.ToString("o")));
}
[Fact]
public void ShouldReturnFalseIfTimeStringIsNotExpired()
{
var expiresAt = DateTimeOffset.UtcNow.AddSeconds(1);
Assert.False(LogtoUtils.IsExpired(expiresAt.ToString("o")));
}
}