2021-03-13 16:21:56 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
|
|
namespace Infrastructure.Test
|
|
|
|
|
{
|
|
|
|
|
class TestSnowflake
|
|
|
|
|
{
|
|
|
|
|
[Test]
|
|
|
|
|
public void Generate()
|
|
|
|
|
{
|
|
|
|
|
// 全局初始化设置WorkerId,默认最大2^16-1。(初始化过程全局只需一次,且必须最先设置)
|
2021-03-29 23:35:02 +08:00
|
|
|
|
var options = new IdGeneratorOptions()
|
|
|
|
|
{
|
|
|
|
|
Method = 1,
|
|
|
|
|
WorkerId = 1
|
|
|
|
|
};
|
2021-03-13 16:21:56 +08:00
|
|
|
|
|
2021-03-29 23:35:02 +08:00
|
|
|
|
YitIdHelper.SetIdGenerator(options);
|
|
|
|
|
long newId = YitIdHelper.NextId();
|
|
|
|
|
Console.WriteLine("=====================================");
|
|
|
|
|
Console.WriteLine("生成的 Id:" + newId);
|
2021-03-13 16:21:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|