瀏覽代碼

add SnowflakeId unit tests

master
Savorboard 6 年之前
父節點
當前提交
7644344d0f
共有 1 個檔案被更改,包括 35 行新增0 行删除
  1. +35
    -0
      test/DotNetCore.CAP.Test/SnowflakeIdTest.cs

+ 35
- 0
test/DotNetCore.CAP.Test/SnowflakeIdTest.cs 查看文件

@@ -0,0 +1,35 @@
using System.Linq;
using System.Threading.Tasks;
using DotNetCore.CAP.Infrastructure;
using Xunit;

namespace DotNetCore.CAP.Test
{
public class SnowflakeIdTest
{
[Fact]
public void NextIdTest()
{
var result = SnowflakeId.Default().NextId();

Assert.IsType<long>(result);
Assert.True(result > 0);
Assert.True(result.ToString().Length == long.MaxValue.ToString().Length);
}

[Fact]
public void ConcurrentNextIdTest()
{
var array = new long[1000];

Parallel.For(0, 1000, i =>
{
var id = SnowflakeId.Default().NextId();
array[i] = id;
});

Assert.True(array.Distinct().Count() == 1000);
}

}
}

Loading…
取消
儲存