diff --git a/test/DotNetCore.CAP.Test/SnowflakeIdTest.cs b/test/DotNetCore.CAP.Test/SnowflakeIdTest.cs new file mode 100644 index 0000000..46553cf --- /dev/null +++ b/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(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); + } + + } +}