-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using SnowflakeId.Core; | ||
using SnowflakeId.DependencyInjection; | ||
|
||
namespace SnowflakeId.Tests | ||
{ | ||
public class SnowflakeIdServiceTest | ||
{ | ||
[Fact] | ||
public void Can_Genertate_UniqueId() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddSnowflakeUniqueId(s => s.DataCenterId = 1); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
var snowflakeService = serviceProvider.GetRequiredService<ISnowflakeService>(); | ||
|
||
var id = snowflakeService.GenerateSnowflakeId(); | ||
var idLength = id.ToString().Length == 19; | ||
|
||
Assert.IsType<long>(id); | ||
Assert.True(idLength); | ||
} | ||
|
||
[Fact] | ||
public void Can_Find_Data_CenterId_From_Generated_UniqueId() | ||
{ | ||
var services = new ServiceCollection(); | ||
services.AddSnowflakeUniqueId(s => s.DataCenterId = 17); | ||
|
||
var serviceProvider = services.BuildServiceProvider(); | ||
var snowflakeService = serviceProvider.GetRequiredService<ISnowflakeService>(); | ||
|
||
var id = snowflakeService.GenerateSnowflakeId(); | ||
var dataCenterId = snowflakeService.GetDataCenterIdBySnowflakId(id); | ||
Assert.IsType<int>(dataCenterId); | ||
Assert.Equal(17, dataCenterId); | ||
|
||
} | ||
|
||
} | ||
} |