瀏覽代碼

修复默认流水号生成器未自增问题

tags/v2.6.2
yedajiang44 2 年之前
父節點
當前提交
8d2bb4324c
共有 2 個檔案被更改,包括 10 行新增9 行删除
  1. +8
    -7
      src/JT808.Protocol.Test/Internal/JT808MsgSNDistributedTest.cs
  2. +2
    -2
      src/JT808.Protocol/Internal/DefaultMsgSNDistributedImpl.cs

+ 8
- 7
src/JT808.Protocol.Test/Internal/JT808MsgSNDistributedTest.cs 查看文件

@@ -1,8 +1,8 @@
using JT808.Protocol.Interfaces;
using JT808.Protocol.Internal;
using System;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using JT808.Protocol.Interfaces;
using JT808.Protocol.Internal;
using Xunit; using Xunit;


namespace JT808.Protocol.Test.Internal namespace JT808.Protocol.Test.Internal
@@ -13,10 +13,11 @@ namespace JT808.Protocol.Test.Internal
public void Test1() public void Test1()
{ {
IJT808MsgSNDistributed JT808MsgSNDistributed = new DefaultMsgSNDistributedImpl(); IJT808MsgSNDistributed JT808MsgSNDistributed = new DefaultMsgSNDistributedImpl();
var a=JT808MsgSNDistributed.Increment("1234");
Assert.Equal(0, a);
var a1 = JT808MsgSNDistributed.Increment("1234");
Assert.Equal(1, a1);
for (int i = 0; i < 10; i++)
{
var a = JT808MsgSNDistributed.Increment("1234");
Assert.Equal(i, a);
}
} }
} }
} }

+ 2
- 2
src/JT808.Protocol/Internal/DefaultMsgSNDistributedImpl.cs 查看文件

@@ -14,8 +14,8 @@ namespace JT808.Protocol.Internal
{ {
if (counterDict.TryGetValue(terminalPhoneNo, out ushort value)) if (counterDict.TryGetValue(terminalPhoneNo, out ushort value))
{ {
ushort newValue = ++value;
counterDict.TryUpdate(terminalPhoneNo, newValue, value);
ushort newValue = value;
counterDict.TryUpdate(terminalPhoneNo, ++newValue, value);
return newValue; return newValue;
} }
else else


Loading…
取消
儲存