You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
169 lines
4.4 KiB
169 lines
4.4 KiB
using OT.COM.LogisticsUtil;
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using Xunit;
|
|
|
|
namespace TestUnit.OT.COM.LogisticsUtil
|
|
{
|
|
public class Test_Util
|
|
{
|
|
public class A
|
|
{
|
|
public string S { get; set; } = null;
|
|
public int? N { get; set; } = null;
|
|
}
|
|
|
|
[Fact]
|
|
public async void DeepClone()
|
|
{
|
|
A a1 = new () { N = 9, S = "AAAA" };
|
|
A a2 = await Util.DeepClone(a1);
|
|
|
|
a2.S = "888";
|
|
|
|
Assert.True(a1.S != a2.S, "Clone value fail");
|
|
Assert.True(a1 != a2, "Clone fail");
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public void GetDefaultTempPath()
|
|
{
|
|
Assert.NotNull(Util.GetDefaultTempPath());
|
|
}
|
|
|
|
[Fact]
|
|
public void GetProcessName()
|
|
{
|
|
Assert.NotNull(Util.GetProcessName());
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("KEY_EXIST", "AAA", "9")]
|
|
[InlineData("KEY_NOTEXOST", null, null)]
|
|
[InlineData("KEY_NOTEXOST", "3", "3")]
|
|
public string GetSettingString(string i_sKey, string i_nDefault, string i_nRealResult)
|
|
{
|
|
string sMsg = null;
|
|
string sResult = null;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
ConcurrentDictionary<string, string> cd = new ConcurrentDictionary<string, string>();
|
|
cd.TryAdd("KEY_EXIST", "9");
|
|
Util.SetSetting(cd);
|
|
sMsg = Util.GetSettingString(out sResult, i_sKey, i_nDefault);
|
|
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(GetSettingString)} exception.";
|
|
#if DEBUG
|
|
sMsg += Util.GetLastExceptionMsg(ex);
|
|
#endif
|
|
}
|
|
#if DEBUG
|
|
if (sMsg != null)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
}
|
|
#endif
|
|
Assert.True(sMsg == null, sMsg);
|
|
Assert.True(i_nRealResult == sResult, sMsg);
|
|
|
|
|
|
return sMsg;
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("KEY_EXIST", 1, 9)]
|
|
[InlineData("KEY_NOTEXOST", 2, 2)]
|
|
[InlineData("KEY_NOTEXOST", 3, 3)]
|
|
public string GetSettingInt(string i_sKey, int i_nDefault, int i_nRealResult)
|
|
{
|
|
string sMsg = null;
|
|
int nResult = -10;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
ConcurrentDictionary<string, string> cd = new ConcurrentDictionary<string, string>();
|
|
cd.TryAdd("KEY_EXIST", "9");
|
|
Util.SetSetting(cd);
|
|
sMsg = Util.GetSettingInt(out nResult, i_sKey, i_nDefault);
|
|
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(GetSettingInt)} exception.";
|
|
#if DEBUG
|
|
sMsg += Util.GetLastExceptionMsg(ex);
|
|
#endif
|
|
}
|
|
#if DEBUG
|
|
if (sMsg != null)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
}
|
|
#endif
|
|
Assert.True(sMsg == null, sMsg);
|
|
Assert.True(i_nRealResult == nResult, sMsg);
|
|
|
|
|
|
return sMsg;
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("KEY_EXIST", true, true)]
|
|
[InlineData("KEY_NOTEXOST", true, true)]
|
|
[InlineData("KEY_NOTEXOST", false, false)]
|
|
public string GetSettingBoolean(string i_sKey, bool i_bDefault, bool i_bRealResult)
|
|
{
|
|
string sMsg = null;
|
|
bool bResult = false;
|
|
|
|
try
|
|
{
|
|
do
|
|
{
|
|
ConcurrentDictionary<string, string> cd = new ConcurrentDictionary<string, string>();
|
|
cd.TryAdd("KEY_EXIST", "True");
|
|
Util.SetSetting(cd);
|
|
sMsg = Util.GetSettingBoolean(out bResult, i_sKey, i_bDefault);
|
|
|
|
}
|
|
while (false);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
sMsg = $"{nameof(GetSettingBoolean)} exception.";
|
|
#if DEBUG
|
|
sMsg += Util.GetLastExceptionMsg(ex);
|
|
#endif
|
|
}
|
|
#if DEBUG
|
|
if (sMsg != null)
|
|
{
|
|
System.Diagnostics.Debug.WriteLine(sMsg);
|
|
}
|
|
#endif
|
|
Assert.True(sMsg == null, sMsg);
|
|
Assert.True(i_bRealResult == bResult, sMsg);
|
|
|
|
|
|
return sMsg;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|