diff --git a/.github/workflows/Codecov.yml b/.github/workflows/Codecov.yml
index 5f69aef5b..04240956c 100644
--- a/.github/workflows/Codecov.yml
+++ b/.github/workflows/Codecov.yml
@@ -96,6 +96,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
+ 10.0.x
+ 9.0.x
8.0.x
7.0.x
6.0.x
diff --git a/.github/workflows/ci_test_reports_to_oss.yml b/.github/workflows/ci_test_reports_to_oss.yml
index 4eb76a75d..50fe105ee 100644
--- a/.github/workflows/ci_test_reports_to_oss.yml
+++ b/.github/workflows/ci_test_reports_to_oss.yml
@@ -27,6 +27,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
+ 10.0.x
+ 9.0.x
8.0.x
7.0.x
6.0.x
diff --git a/.github/workflows/package_push_nuget.org.yml b/.github/workflows/package_push_nuget.org.yml
index 65fdf63ec..bb2172908 100644
--- a/.github/workflows/package_push_nuget.org.yml
+++ b/.github/workflows/package_push_nuget.org.yml
@@ -19,6 +19,8 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
+ 10.0.x
+ 9.0.x
8.0.x
7.0.x
6.0.x
diff --git a/.github/workflows/pr_run_test_ci.yml b/.github/workflows/pr_run_test_ci.yml
index 35d4d4457..3de49c06d 100644
--- a/.github/workflows/pr_run_test_ci.yml
+++ b/.github/workflows/pr_run_test_ci.yml
@@ -38,9 +38,11 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
+ 10.0.x
+ 9.0.x
8.0.x
7.0.x
- 6.0.x
+ 6.0.x
include-prerelease: true
@@ -101,7 +103,13 @@ jobs:
run: |
dotnet-sonarscanner begin /k:"masastack_MASA.Framework" /o:"masastack" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io"
dotnet build /p:ContinuousIntegrationBuild=true
- dotnet test --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+
+ dotnet test --framework net6.0 --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+ dotnet test --framework net7.0 --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+ dotnet test --framework net8.0 --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+ dotnet test --framework net9.0 --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+ dotnet test --framework net10.0 --filter FullyQualifiedName!~Masa.Utils --no-build --verbosity normal --collect "Code Coverage" /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Exclude="[*.Tests]*"
+
dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
- name: Build and analyze for outside
env:
diff --git a/Directory.Build.props b/Directory.Build.props
index 4ac25d396..dbd7e279a 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,9 +1,12 @@
- net6.0;net7.0;net8.0
- 6.0.0
- 7.0.0
- 8.0.0
+ net6.0;net7.0;net8.0;net9.0;net10.0;
+ 6.*
+ 7.*
+ 8.*
+ 9.*
+ 10.0.0-preview.*
+
0.13.1
2.2.3
16.9.4
@@ -16,15 +19,11 @@
1.0.4
11.1.0
11.1.2
- 2.2.4
+ 2.8.41
7.17.4
7.5.0
6.0.0
- 1.5.1
- 1.5.0
- 1.0.0-rc9.10
-
$(AssemblyName)
packageIcon.png
MASA Stack
diff --git a/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/DistributedCacheClientTest.cs b/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/DistributedCacheClientTest.cs
index c2fe92854..2f4e183f0 100644
--- a/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/DistributedCacheClientTest.cs
+++ b/src/Contrib/Caching/Distributed/Tests/Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests/DistributedCacheClientTest.cs
@@ -1,4 +1,4 @@
-// Copyright (c) MASA Stack All rights reserved.
+// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
namespace Masa.Contrib.Caching.Distributed.StackExchangeRedis.Tests;
@@ -21,8 +21,8 @@ public void Initialize()
}
[DataTestMethod]
- [DataRow("cache_test", "content")]
- [DataRow("cache_test_2", "")]
+ [DataRow("cache_test_setasync", "content")]
+ [DataRow("cache_test_setasync_1", "aaaa")]
public async Task SetAsync(string key, string value)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -37,7 +37,7 @@ public async Task SetAsync(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test_sync", "content")]
+ [DataRow("cache_test_set", "content")]
public void Set(string key, string value)
{
_distributedCacheClient.Remove(key);
@@ -53,7 +53,7 @@ public void Set(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test_sync", "content")]
+ [DataRow("cache_test_specify_time", "content")]
public void SetAndSpecifyTimeSpan(string key, string value)
{
_distributedCacheClient.Set(key, value, TimeSpan.FromSeconds(30));
@@ -64,7 +64,7 @@ public void SetAndSpecifyTimeSpan(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test", "content")]
+ [DataRow("cache_test_specify_time_async", "content")]
public async Task SetAndSpecifyTimeSpanAsync(string key, string value)
{
await _distributedCacheClient.SetAsync(key, value, TimeSpan.FromSeconds(30));
@@ -73,7 +73,7 @@ public async Task SetAndSpecifyTimeSpanAsync(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test_sync", "content")]
+ [DataRow("cache_test_time", "content")]
public void SetAndSpecifyTime(string key, string value)
{
_distributedCacheClient.Set(key, value, DateTimeOffset.Now.AddMinutes(1));
@@ -82,7 +82,7 @@ public void SetAndSpecifyTime(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test", "content")]
+ [DataRow("cache_test_time_async", "content")]
public async Task SetAndSpecifyTimeAsync(string key, string value)
{
await _distributedCacheClient.SetAsync(key, value, DateTimeOffset.Now.AddMinutes(1));
@@ -91,7 +91,7 @@ public async Task SetAndSpecifyTimeAsync(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test", "content")]
+ [DataRow("cache_test_global_async", "content")]
public async Task SetAndSpecifyTimeAsyncAndUseGlobalOptions(string key, string value)
{
var globalRedisConfigurationOptions = GetConfigurationOptions();
@@ -105,7 +105,7 @@ public async Task SetAndSpecifyTimeAsyncAndUseGlobalOptions(string key, string v
}
[DataTestMethod]
- [DataRow("cache_test", "content")]
+ [DataRow("cache_test_global", "content")]
public void SetAndSpecifyTimeAndUseGlobalOptions(string key, string value)
{
var globalRedisConfigurationOptions = GetConfigurationOptions();
@@ -119,7 +119,7 @@ public void SetAndSpecifyTimeAndUseGlobalOptions(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test_sync", "2022-01-01")]
+ [DataRow("cache_test_datetime", "2022-01-01")]
public void SetByDateTime(string key, string value)
{
var date = DateTime.Parse(value);
@@ -131,7 +131,7 @@ public void SetByDateTime(string key, string value)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_guid")]
public void SetByGuid(string key)
{
var value = Guid.NewGuid();
@@ -143,7 +143,7 @@ public void SetByGuid(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_decimal")]
public void SetByDecimal(string key)
{
var value = 1.2M;
@@ -155,7 +155,7 @@ public void SetByDecimal(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_double")]
public void SetByDouble(string key)
{
var value = 1.2d;
@@ -167,7 +167,7 @@ public void SetByDouble(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_float")]
public void SetByFloat(string key)
{
var value = 1.2f;
@@ -179,7 +179,7 @@ public void SetByFloat(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_int")]
public void SetByInt(string key)
{
var value = 9;
@@ -191,7 +191,7 @@ public void SetByInt(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_long")]
public void SetByLong(string key)
{
var value = 9L;
@@ -203,7 +203,7 @@ public void SetByLong(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_ushort")]
public void SetByUShort(string key)
{
short value = 1;
@@ -215,7 +215,7 @@ public void SetByUShort(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_string_array")]
public void SetByStringArray(string key)
{
string[] values = new[]
@@ -233,7 +233,7 @@ public void SetByStringArray(string key)
}
[DataTestMethod]
- [DataRow("cache_test_sync")]
+ [DataRow("cache_test_string_collection")]
public void SetByStringCollection(string key)
{
List values = new List()
@@ -257,24 +257,24 @@ public void SetList()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetList_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetList_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetList_3", Guid.NewGuid().ToString()
}
};
_distributedCacheClient.SetList(dic!);
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_1"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_2"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_3"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetList_1"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetList_2"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetList_3"));
- _distributedCacheClient.Remove("setlist_1");
- _distributedCacheClient.Remove("setlist_2");
- _distributedCacheClient.Remove("setlist_3");
+ _distributedCacheClient.Remove("SetList_1");
+ _distributedCacheClient.Remove("SetList_2");
+ _distributedCacheClient.Remove("SetList_3");
}
[TestMethod]
@@ -283,24 +283,24 @@ public async Task SetListAsync()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetListAsync_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetListAsync_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetListAsync_3", Guid.NewGuid().ToString()
}
};
await _distributedCacheClient.SetListAsync(dic!);
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_1"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_2"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_3"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAsync_1"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAsync_2"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAsync_3"));
- await _distributedCacheClient.RemoveAsync("setlist_1");
- await _distributedCacheClient.RemoveAsync("setlist_2");
- await _distributedCacheClient.RemoveAsync("setlist_3");
+ await _distributedCacheClient.RemoveAsync("SetListAsync_1");
+ await _distributedCacheClient.RemoveAsync("SetListAsync_2");
+ await _distributedCacheClient.RemoveAsync("SetListAsync_3");
}
[TestMethod]
@@ -309,24 +309,24 @@ public void SetListAndSpecifyTime()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTime_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTime_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTime_3", Guid.NewGuid().ToString()
}
};
_distributedCacheClient.SetList(dic!, DateTimeOffset.Now.AddSeconds(30));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_1"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_2"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_3"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTime_1"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTime_2"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTime_3"));
- _distributedCacheClient.Remove("setlist_1");
- _distributedCacheClient.Remove("setlist_2");
- _distributedCacheClient.Remove("setlist_3");
+ _distributedCacheClient.Remove("SetListAndSpecifyTime_1");
+ _distributedCacheClient.Remove("SetListAndSpecifyTime_2");
+ _distributedCacheClient.Remove("SetListAndSpecifyTime_3");
}
[TestMethod]
@@ -335,24 +335,24 @@ public async Task SetListAndSpecifyTimeAsync()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeAsync_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeAsync_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeAsync_3", Guid.NewGuid().ToString()
}
};
await _distributedCacheClient.SetListAsync(dic!, DateTimeOffset.Now.AddSeconds(30));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_1"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_2"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_3"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeAsync_1"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeAsync_2"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeAsync_3"));
- await _distributedCacheClient.RemoveAsync("setlist_1");
- await _distributedCacheClient.RemoveAsync("setlist_2");
- await _distributedCacheClient.RemoveAsync("setlist_3");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeAsync_1");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeAsync_2");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeAsync_3");
}
[TestMethod]
@@ -361,24 +361,24 @@ public void SetListAndSpecifyTimeSpan()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpan_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpan_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpan_3", Guid.NewGuid().ToString()
}
};
_distributedCacheClient.SetList(dic!, TimeSpan.FromSeconds(30));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_1"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_2"));
- Assert.IsTrue(_distributedCacheClient.Exists("setlist_3"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTimeSpan_1"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTimeSpan_2"));
+ Assert.IsTrue(_distributedCacheClient.Exists("SetListAndSpecifyTimeSpan_3"));
- _distributedCacheClient.Remove("setlist_1");
- _distributedCacheClient.Remove("setlist_2");
- _distributedCacheClient.Remove("setlist_3");
+ _distributedCacheClient.Remove("SetListAndSpecifyTimeSpan_1");
+ _distributedCacheClient.Remove("SetListAndSpecifyTimeSpan_2");
+ _distributedCacheClient.Remove("SetListAndSpecifyTimeSpan_3");
}
[TestMethod]
@@ -387,24 +387,24 @@ public async Task SetListAndSpecifyTimeSpanAsync()
var dic = new Dictionary()
{
{
- "setlist_1", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpanAsync_1", Guid.NewGuid().ToString()
},
{
- "setlist_2", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpanAsync_2", Guid.NewGuid().ToString()
},
{
- "setlist_3", Guid.NewGuid().ToString()
+ "SetListAndSpecifyTimeSpanAsync_3", Guid.NewGuid().ToString()
}
};
await _distributedCacheClient.SetListAsync(dic!, TimeSpan.FromSeconds(30));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_1"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_2"));
- Assert.IsTrue(await _distributedCacheClient.ExistsAsync("setlist_3"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeSpanAsync_1"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeSpanAsync_2"));
+ Assert.IsTrue(await _distributedCacheClient.ExistsAsync("SetListAndSpecifyTimeSpanAsync_3"));
- await _distributedCacheClient.RemoveAsync("setlist_1");
- await _distributedCacheClient.RemoveAsync("setlist_2");
- await _distributedCacheClient.RemoveAsync("setlist_3");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeSpanAsync_1");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeSpanAsync_2");
+ await _distributedCacheClient.RemoveAsync("SetListAndSpecifyTimeSpanAsync_3");
}
[DataTestMethod]
@@ -430,7 +430,7 @@ public async Task TestGetListAsync(params string[] keys)
[DataTestMethod]
[DataRow("test_1", "123")]
[DataRow("test_2", "")]
- [DataRow("test_2", null)]
+ [DataRow("test_3", null)]
public void TestGetOrSet(string key, string? value)
{
var res = _distributedCacheClient.GetOrSet(key, () =>
@@ -452,9 +452,9 @@ public void TestGetOrSet(string key, string? value)
}
[DataTestMethod]
- [DataRow("test_1", "123")]
- [DataRow("test_2", "")]
- [DataRow("test_2", null)]
+ [DataRow("test_1_async", "123_async")]
+ [DataRow("test_2_async", "")]
+ [DataRow("test_3_async", null)]
public async Task TestGetOrSetAsync(string key, string? value)
{
var res = await _distributedCacheClient.GetOrSetAsync(key, () =>
@@ -473,8 +473,8 @@ public async Task TestGetOrSetAsync(string key, string? value)
}
[DataTestMethod]
- [DataRow("test1", "test2")]
- [DataRow("test3")]
+ [DataRow("test1_refresh", "test2_refresh")]
+ [DataRow("test3_refresh")]
public void TestRefresh(params string[] keys)
{
_distributedCacheClient.KeyExpire(keys, new CacheEntryOptions(TimeSpan.FromHours(1))
@@ -494,8 +494,8 @@ public void TestRefresh(params string[] keys)
}
[DataTestMethod]
- [DataRow("test1", "test2")]
- [DataRow("test3")]
+ [DataRow("test1_refresh_async", "test2_refresh_async")]
+ [DataRow("test3_refresh_async")]
public async Task TestRefreshAsync(params string[] keys)
{
await _distributedCacheClient.KeyExpireAsync(keys, new CacheEntryOptions(TimeSpan.FromHours(1))
@@ -584,7 +584,7 @@ public async Task TestGetListByKeyPatternAsync(string keyPattern, int count)
}
[DataTestMethod]
- [DataRow("hash_test", 1)]
+ [DataRow("hash_test_in", 1)]
public async Task TestHashIncrementAsync(string key, int value)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -598,8 +598,8 @@ public async Task TestHashIncrementAsync(string key, int value)
}
[DataTestMethod]
- [DataRow("hash_test", 0)]
- [DataRow("hash_test", -1)]
+ [DataRow("hash_test_in1", 0)]
+ [DataRow("hash_test_in1", -1)]
public async Task TestHashIncrementAndValueLessThan1Async(string key, int value)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -609,8 +609,8 @@ await Assert.ThrowsExceptionAsync(async ()
}
[DataTestMethod]
- [DataRow("hash_test", 1)]
- [DataRow("hash_test", 0)]
+ [DataRow("hash_test_d", 1)]
+ [DataRow("hash_test_d", 0)]
public async Task TestHashDecrementAsync(string key, long minVal)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -624,9 +624,9 @@ public async Task TestHashDecrementAsync(string key, long minVal)
}
[DataTestMethod]
- [DataRow("hash_test", 0)]
- [DataRow("hash_test", -1)]
- [DataRow("hash_test", -2)]
+ [DataRow("hash_test_d1", 0)]
+ [DataRow("hash_test_d1", -1)]
+ [DataRow("hash_test_d1", -2)]
public async Task TestHashDecrementAndValueLessThan1Async(string key, long value)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -636,7 +636,7 @@ await Assert.ThrowsExceptionAsync(async ()
}
[DataTestMethod]
- [DataRow("test_expire")]
+ [DataRow("test_expire_special")]
public void TestKeyExpireAndSpecialTimeSpan(string key)
{
_distributedCacheClient.Set(key, "test_content");
@@ -648,7 +648,7 @@ public void TestKeyExpireAndSpecialTimeSpan(string key)
}
[DataTestMethod]
- [DataRow("test_expire")]
+ [DataRow("test_expire_special_async")]
public async Task TestKeyExpireAndSpecialTimeSpanAsync(string key)
{
await _distributedCacheClient.SetAsync(key, "test_content");
@@ -660,7 +660,7 @@ public async Task TestKeyExpireAndSpecialTimeSpanAsync(string key)
}
[DataTestMethod]
- [DataRow("test_expire")]
+ [DataRow("test_expire_notfound_async")]
public async Task TestKeyExpireAndSpecialTimeSpanAndKeyIsNotFoundAsync(string key)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -670,7 +670,7 @@ public async Task TestKeyExpireAndSpecialTimeSpanAndKeyIsNotFoundAsync(string ke
}
[DataTestMethod]
- [DataRow("test_expire")]
+ [DataRow("test_expire_special_time_async")]
public void TestKeyExpireAndSpecialTime(string key)
{
_distributedCacheClient.Set(key, "test_content");
@@ -682,7 +682,7 @@ public void TestKeyExpireAndSpecialTime(string key)
}
[DataTestMethod]
- [DataRow("test_expire")]
+ [DataRow("test_expire_special_time")]
public async Task TestKeyExpireAndSpecialTimeAsync(string key)
{
await _distributedCacheClient.SetAsync(key, "test_content");
@@ -694,7 +694,7 @@ public async Task TestKeyExpireAndSpecialTimeAsync(string key)
}
[DataTestMethod]
- [DataRow("test_expire", "test_expire2")]
+ [DataRow("m_test_expire_special_time", "m_test_expire2_special_time")]
public void TestMultiKeyExpireAndSpecialTime(string key, string key2)
{
_distributedCacheClient.Set(key, "test_content");
@@ -714,7 +714,7 @@ public void TestMultiKeyExpireAndSpecialTime(string key, string key2)
}
[DataTestMethod]
- [DataRow("test_expire", "test_expire2")]
+ [DataRow("m_test_expire_special_time_async", "m_test_expire2_special_time_async")]
public async Task TestMultiKeyExpireAndSpecialTimeAsync(string key, string key2)
{
await _distributedCacheClient.SetAsync(key, "test_content");
@@ -734,7 +734,7 @@ await _distributedCacheClient.KeyExpireAsync(new[]
}
[DataTestMethod]
- [DataRow("test_expire", "test_expire2")]
+ [DataRow("test_expire_notfound", "test_expire2_notfound")]
public async Task TestMultiKeyExpireAndKeyIsNotFoundAsync(string key, string key2)
{
await _distributedCacheClient.RemoveAsync(key);
@@ -775,19 +775,18 @@ public async Task TestPublishAsyncBySync(string channel, string key, string valu
option.Value = value;
});
- await Task.Delay(1000);
+ await Task.Delay(200);
Assert.IsTrue(timer == 1);
}
[DataTestMethod]
- [DataRow("test_chanel", "test_change_test", "2")]
+ [DataRow("test_chanel_async", "test_change_test_async", "2")]
public async Task TestPublishAsync(string channel, string key, string value)
{
int timer = 0;
await _distributedCacheClient.SubscribeAsync(channel, option =>
{
timer++;
-
Assert.IsTrue(option.IsPublisherClient);
Assert.IsTrue(option.Value == value);
});
@@ -800,7 +799,7 @@ await _distributedCacheClient.PublishAsync(channel, option =>
option.Value = value;
});
- await Task.Delay(1000);
+ await Task.Delay(200);
Assert.IsTrue(timer == 1);
}
@@ -875,7 +874,7 @@ public async Task TestExistsAsync()
CacheKeyType = CacheKeyType.TypeName
};
var distributedCacheClient = new RedisCacheClient(configurationOptions);
- var key = "redis.exist";
+ var key = "redis.exist_async";
await distributedCacheClient.SetAsync(key, "1");
Assert.IsFalse(await distributedCacheClient.ExistsAsync(key));
diff --git a/src/Contrib/Data/IdGenerator/Snowflake/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis/DistributedWorkerProvider.cs b/src/Contrib/Data/IdGenerator/Snowflake/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis/DistributedWorkerProvider.cs
index 8677bacf9..cb319619f 100644
--- a/src/Contrib/Data/IdGenerator/Snowflake/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis/DistributedWorkerProvider.cs
+++ b/src/Contrib/Data/IdGenerator/Snowflake/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis/DistributedWorkerProvider.cs
@@ -19,7 +19,7 @@ public class DistributedWorkerProvider : BaseRedis, IWorkerProvider
private readonly TimeSpan _timeSpan;
private DateTime? _lastTime;
private readonly ILogger? _logger;
- private readonly object _lock = new();
+ private readonly SemaphoreSlim _semaphore = new(1, 1);
private readonly string? _uniquelyIdentifies;
public DistributedWorkerProvider(
@@ -52,33 +52,38 @@ public DistributedWorkerProvider(
});
}
- public Task GetWorkerIdAsync()
+ public async Task GetWorkerIdAsync()
{
if (_workerId.HasValue)
- return Task.FromResult(_workerId.Value);
+ return _workerId.Value;
- if (_lastTime != null && (DateTime.UtcNow - _lastTime.Value).TotalMilliseconds < _workerIdMinInterval)
+ if (_lastTime != null && (DateTime.UtcNow - _lastTime.Value).TotalMilliseconds - _workerIdMinInterval < 0)
{
_logger?.LogDebug("Failed to get WorkerId, please rest for a while and try again");
throw new MasaException("Failed to get WorkerId, please rest for a while and try again");
}
_lastTime = DateTime.UtcNow;
- lock (_lock)
+ await _semaphore.WaitAsync();
+ try
{
if (_workerId.HasValue)
- return Task.FromResult(_workerId.Value);
+ return _workerId.Value;
- _workerId = GetNextWorkerIdAsync().ConfigureAwait(false).GetAwaiter().GetResult();
+ _workerId = await GetNextWorkerIdAsync();
- RefreshAsync().ConfigureAwait(false).GetAwaiter().GetResult();
+ await RefreshAsync();
- DistributedCacheClient.Publish(_channel, options =>
+ await DistributedCacheClient.PublishAsync(_channel, options =>
{
options.Key = _uniquelyIdentifies!;
options.Value = _workerId.Value;
});
- return Task.FromResult(_workerId.Value);
+ return _workerId.Value;
+ }
+ finally
+ {
+ _semaphore.Release();
}
}
@@ -98,16 +103,21 @@ public async Task LogOutAsync()
var workerId = _workerId;
_workerId = null;
- _logger?.LogDebug("----- Logout WorkerId, the current WorkerId: {WorkerId}, currentTime: {CurrentTime}",
- workerId,
- DateTime.UtcNow);
+ if (_logger?.IsEnabled(LogLevel.Debug) == true)
+ {
+ _logger.LogDebug("----- Logout WorkerId, the current WorkerId: {WorkerId}, currentTime: {CurrentTime}",
+ workerId,
+ DateTime.UtcNow);
+ }
await Database.SortedSetAddAsync(_logOutWorkerKey, workerId, GetCurrentTimestamp());
await Database.SortedSetRemoveAsync(_inUseWorkerKey, workerId);
-
- _logger?.LogDebug("----- Logout WorkerId succeeded, the current WorkerId: {WorkerId}, currentTime: {CurrentTime}",
+ if (_logger?.IsEnabled(LogLevel.Debug) == true)
+ {
+ _logger.LogDebug("----- Logout WorkerId succeeded, the current WorkerId: {WorkerId}, currentTime: {CurrentTime}",
workerId,
DateTime.UtcNow);
+ }
}
private async Task GetNextWorkerIdAsync()
@@ -129,9 +139,12 @@ private async Task GetNextWorkerIdAsync()
}
else
{
- _logger?.LogDebug(
+ if (_logger?.IsEnabled(LogLevel.Debug) == true)
+ {
+ _logger.LogDebug(
"----- Failed to obtain WorkerId, failed to obtain distributed lock, the currentTime: {CurrentTime}",
DateTime.UtcNow);
+ }
throw new MasaException("----- Failed to get WorkerId, please try again later");
}
}
@@ -159,8 +172,8 @@ private async Task GetNextWorkerIdByDistributedLockAsync()
protected virtual async Task GetWorkerIdByLogOutAsync()
{
var entries = await Database.SortedSetRangeByScoreWithScoresAsync(_logOutWorkerKey, take: 1);
- if (entries is { Length: > 0 })
- return long.Parse(entries[0].Element);
+ if (entries is { Length: > 0 } && entries[0].Element.HasValue)
+ return long.Parse(entries[0].Element.ToString());
return null;
}
@@ -173,8 +186,8 @@ private async Task GetNextWorkerIdByDistributedLockAsync()
GetCurrentTimestamp(DateTime.UtcNow.AddMilliseconds(-_idleTimeOut)),
take: 1);
- if (entries is { Length: > 0 })
- return long.Parse(entries[0].Element);
+ if (entries is { Length: > 0 } && entries[0].Element.HasValue)
+ return long.Parse(entries[0].Element.ToString());
return null;
}
diff --git a/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/IdGeneratorTest.cs b/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/IdGeneratorTest.cs
index 0b74fd8f7..894b573a4 100644
--- a/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/IdGeneratorTest.cs
+++ b/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/IdGeneratorTest.cs
@@ -17,6 +17,7 @@ public class IdGeneratorTest
private string _inUseWorkerKey;
private string _logOutWorkerKey;
private string _getWorkerIdKey;
+ private string _lastTimestampKey;
[TestInitialize]
public async Task InitRedisDataAsync()
@@ -38,11 +39,7 @@ public async Task InitRedisDataAsync()
_inUseWorkerKey = "snowflake.inuse.workerid";
_logOutWorkerKey = "snowflake.logout.workerid";
_getWorkerIdKey = "snowflake.get.workerid";
-
- _database.KeyDelete(_currentWorkerKey);
- _database.KeyDelete(_inUseWorkerKey);
- _database.KeyDelete(_logOutWorkerKey);
- _database.KeyDelete(_getWorkerIdKey);
+ _lastTimestampKey = "snowflake.last_timestamp";
}
[TestMethod]
@@ -111,10 +108,14 @@ public void TestUseRedisAndNotUseRedisAndSpecialRedisConfigurationOptions3()
public void TestDistributedSnowflake()
{
var services = new ServiceCollection();
- services.AddSnowflake(option => option.UseRedis(null, options =>
+ services.AddSnowflake(option => option.UseRedis(distribute =>
+ {
+ distribute.GetWorkerIdMinInterval = 0;
+ }, options =>
{
options.Password = "";
options.DefaultDatabase = 2;
+
options.Servers = new List()
{
new(REDIS_HOST)
@@ -239,7 +240,6 @@ public async Task TestGetDistributedLockFailedAsync()
var tasks = new ConcurrentBag();
ThreadPool.GetMinThreads(out int workerThreads, out var minIoc);
ThreadPool.SetMinThreads((int)maxWorkerId, minIoc);
-
int laterTime = 0;
try
{
@@ -252,10 +252,15 @@ public async Task TestGetDistributedLockFailedAsync()
catch (Exception ex)
{
if (ex.Message.Contains("please try again later") ||
+ ex.Message.Contains("No WorkerId available") ||
(ex.InnerException != null && ex.InnerException.Message.Contains("please try again later")))
{
laterTime++;
}
+ else
+ {
+ Debug.Write(ex.Message);
+ }
}
Assert.IsTrue(laterTime > 0);
ThreadPool.SetMinThreads(workerThreads, minIoc);
@@ -325,10 +330,10 @@ public void TestTilNextMillis()
Assert.AreEqual(501, result);
var dataBase = ConnectionMultiplexer.Connect(redisConfigurationOptions).GetDatabase(redisConfigurationOptions.DefaultDatabase);
- string lastTimestampKey = "snowflake.last_timestamp";
- Assert.AreEqual(result, dataBase.HashGet(lastTimestampKey, workerId));
- dataBase.HashSet(lastTimestampKey, workerId, 10);
+ Assert.AreEqual(result, dataBase.HashGet(_lastTimestampKey, workerId));
+
+ dataBase.HashSet(_lastTimestampKey, workerId, 10);
distributedIdGeneratorOptions = new DistributedIdGeneratorOptions(new SnowflakeGeneratorOptions(new ServiceCollection())
{
@@ -344,8 +349,8 @@ public void TestTilNextMillis()
);
result = machineClockIdGenerator.TestTilNextMillis(1);
Assert.AreEqual(2, result);
- Assert.AreEqual(10, dataBase.HashGet(lastTimestampKey, workerId));
- dataBase.HashDelete(lastTimestampKey, workerId);
+ Assert.AreEqual(10, dataBase.HashGet(_lastTimestampKey, workerId));
+ dataBase.HashDelete(_lastTimestampKey, workerId);
}
#region private methods
@@ -372,5 +377,14 @@ private static long GetCurrentTimestamp(DateTime? dateTime = null)
#endregion
+ [TestCleanup]
+ public void Cleanup()
+ {
+ _database.KeyDelete(_currentWorkerKey);
+ _database.KeyDelete(_inUseWorkerKey);
+ _database.KeyDelete(_logOutWorkerKey);
+ _database.KeyDelete(_getWorkerIdKey);
+ _database.KeyDelete(_lastTimestampKey);
+ }
}
#pragma warning restore CS0618
diff --git a/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/_Imports.cs b/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/_Imports.cs
index c26768158..0ea3ec2a3 100644
--- a/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/_Imports.cs
+++ b/src/Contrib/Data/IdGenerator/Snowflake/Tests/Masa.Contrib.Data.IdGenerator.Snowflake.Distributed.Redis.Tests/_Imports.cs
@@ -14,6 +14,7 @@
global using System;
global using System.Collections.Concurrent;
global using System.Collections.Generic;
+global using System.Diagnostics;
global using System.Linq;
global using System.Reflection;
global using System.Threading.Tasks;
diff --git a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.MySql/Masa.Contrib.Data.EFCore.MySql.csproj b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.MySql/Masa.Contrib.Data.EFCore.MySql.csproj
index 04e309711..3873904e9 100644
--- a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.MySql/Masa.Contrib.Data.EFCore.MySql.csproj
+++ b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.MySql/Masa.Contrib.Data.EFCore.MySql.csproj
@@ -5,9 +5,18 @@
enable
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Oracle/Masa.Contrib.Data.EFCore.Oracle.csproj b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Oracle/Masa.Contrib.Data.EFCore.Oracle.csproj
index db8444b45..59bb14a95 100644
--- a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Oracle/Masa.Contrib.Data.EFCore.Oracle.csproj
+++ b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Oracle/Masa.Contrib.Data.EFCore.Oracle.csproj
@@ -9,21 +9,16 @@
-
+
-
+
-
+
-
+
-
-
-
-
-
-
+
diff --git a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Pomelo.MySql/Masa.Contrib.Data.EFCore.Pomelo.MySql.csproj b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Pomelo.MySql/Masa.Contrib.Data.EFCore.Pomelo.MySql.csproj
index ddd7aa9d9..d6be3b506 100644
--- a/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Pomelo.MySql/Masa.Contrib.Data.EFCore.Pomelo.MySql.csproj
+++ b/src/Contrib/Data/Orm/EFCore/Masa.Contrib.Data.EFCore.Pomelo.MySql/Masa.Contrib.Data.EFCore.Pomelo.MySql.csproj
@@ -5,12 +5,28 @@
enable
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/DefaultIntegrationEventDaprProviderTest.cs b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/DefaultIntegrationEventDaprProviderTest.cs
index c39d14c15..a7deb3675 100644
--- a/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/DefaultIntegrationEventDaprProviderTest.cs
+++ b/src/Contrib/Dispatcher/IntegrationEvents/Tests/Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests/DefaultIntegrationEventDaprProviderTest.cs
@@ -1,4 +1,4 @@
-// Copyright (c) MASA Stack All rights reserved.
+// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
namespace Masa.Contrib.Dispatcher.IntegrationEvents.Dapr.Tests;
@@ -34,7 +34,7 @@ public void TestGetDaprAppIdBySetDaprAppId(string? daprAppId, string appIdByGlob
Environment.SetEnvironmentVariable(DaprStarterConstant.DEFAULT_DAPR_APPID, "masa-env");
var actualAppId = _provider.GetDaprAppId(daprAppId, appIdByGlobal);
Assert.AreEqual(exceptedDaprAppId, actualAppId);
- Environment.SetEnvironmentVariable(DaprStarterConstant.DEFAULT_DAPR_APPID, "");
+ Environment.SetEnvironmentVariable(DaprStarterConstant.DEFAULT_DAPR_APPID, null);
});
}
diff --git a/src/Contrib/RulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine.csproj b/src/Contrib/RulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine.csproj
index cb9e04923..ff962a5bc 100644
--- a/src/Contrib/RulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine.csproj
+++ b/src/Contrib/RulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine/Masa.Contrib.RulesEngine.MicrosoftRulesEngine.csproj
@@ -11,8 +11,9 @@
+
-
+
diff --git a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/DefaultCallerProvider.cs b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/DefaultCallerProvider.cs
index 828667dcf..b10567406 100644
--- a/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/DefaultCallerProvider.cs
+++ b/src/Contrib/Service/Caller/Masa.Contrib.Service.Caller.DaprClient/DefaultCallerProvider.cs
@@ -1,4 +1,4 @@
-// Copyright (c) MASA Stack All rights reserved.
+// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
namespace Masa.Contrib.Service.Caller.DaprClient;
diff --git a/src/Contrib/Service/Caller/Tests/Masa.Contrib.Service.Caller.DaprClient.Tests/CallerTest.cs b/src/Contrib/Service/Caller/Tests/Masa.Contrib.Service.Caller.DaprClient.Tests/CallerTest.cs
index 532e486ae..d4e1c4932 100644
--- a/src/Contrib/Service/Caller/Tests/Masa.Contrib.Service.Caller.DaprClient.Tests/CallerTest.cs
+++ b/src/Contrib/Service/Caller/Tests/Masa.Contrib.Service.Caller.DaprClient.Tests/CallerTest.cs
@@ -1,4 +1,4 @@
-// Copyright (c) MASA Stack All rights reserved.
+// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
namespace Masa.Contrib.Service.Caller.DaprClient.Tests;
@@ -65,7 +65,7 @@ public void TestAppIdByUseDaprAndAlwaysGetNewestDaprClient()
Assert.AreEqual(expectedAppId, GetAppId(caller));
- Environment.SetEnvironmentVariable(key, string.Empty);
+ Environment.SetEnvironmentVariable(key, null);
}
[TestMethod]
@@ -111,7 +111,7 @@ public void TestAppIdByUseDaprAndSetEnvironmentAndUseJsonConfig()
Assert.IsNotNull(caller);
Assert.AreEqual(APP_ID_BY_JSON_CONFIG, GetAppId(caller));
- Environment.SetEnvironmentVariable(DEFAULT_APP_ID, string.Empty);
+ Environment.SetEnvironmentVariable(DEFAULT_APP_ID, null);
}
[TestMethod]
diff --git a/src/Contrib/Service/Caller/Tests/Scenes/Masa.Contrib.Service.Caller.DaprClient.Tests.Scenes.MasaConfiguration/DefaultCallerProviderTest.cs b/src/Contrib/Service/Caller/Tests/Scenes/Masa.Contrib.Service.Caller.DaprClient.Tests.Scenes.MasaConfiguration/DefaultCallerProviderTest.cs
index 32ed92f7b..5b7482721 100644
--- a/src/Contrib/Service/Caller/Tests/Scenes/Masa.Contrib.Service.Caller.DaprClient.Tests.Scenes.MasaConfiguration/DefaultCallerProviderTest.cs
+++ b/src/Contrib/Service/Caller/Tests/Scenes/Masa.Contrib.Service.Caller.DaprClient.Tests.Scenes.MasaConfiguration/DefaultCallerProviderTest.cs
@@ -1,6 +1,8 @@
-// Copyright (c) MASA Stack All rights reserved.
+// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+using Microsoft.Extensions.Configuration;
+
namespace Masa.Contrib.Service.Caller.DaprClient.Tests.Scenes.MasaConfiguration;
[TestClass]
@@ -11,7 +13,7 @@ public class DefaultCallerProviderTest
[TestInitialize]
public void InitializeData()
{
- Environment.SetEnvironmentVariable($"{APPID}-suffix", "");
+ Environment.SetEnvironmentVariable($"{APPID}-suffix", null);
}
[TestMethod]
diff --git a/src/Utils/Ldap/Masa.Utils.Ldap.Novell/LdapProvider.cs b/src/Utils/Ldap/Masa.Utils.Ldap.Novell/LdapProvider.cs
index 3eea657b4..63b7ee3d5 100644
--- a/src/Utils/Ldap/Masa.Utils.Ldap.Novell/LdapProvider.cs
+++ b/src/Utils/Ldap/Masa.Utils.Ldap.Novell/LdapProvider.cs
@@ -1,6 +1,8 @@
// Copyright (c) MASA Stack All rights reserved.
// Licensed under the MIT License. See LICENSE.txt in the project root for license information.
+using System.Collections.Generic;
+
namespace Masa.Utils.Ldap.Novell;
public class LdapProvider : ILdapProvider, IDisposable
@@ -128,14 +130,14 @@ public async Task> GetPagingUserAsync(int pageSize)
public async Task GetUserByUserNameAsync(string userName)
{
var filter = $"(&(objectClass=user)(sAMAccountName={userName}))";
- var user = await GetFilterLdapEntryAsync(_ldapOptions.UserSearchBaseDn, filter).FirstOrDefaultAsync();
+ var user = await FirstOrDefaultAsync(GetFilterLdapEntryAsync(_ldapOptions.UserSearchBaseDn, filter));
return user == null ? null : CreateUser(user.Dn, user.GetAttributeSet());
}
public async Task GetUsersByEmailAddressAsync(string emailAddress)
{
var filter = $"(&(objectClass=user)(mail={emailAddress}))";
- var user = await GetFilterLdapEntryAsync(_ldapOptions.UserSearchBaseDn, filter).FirstOrDefaultAsync();
+ var user = await FirstOrDefaultAsync(GetFilterLdapEntryAsync(_ldapOptions.UserSearchBaseDn, filter));
return user == null ? null : CreateUser(user.Dn, user.GetAttributeSet());
}
@@ -154,6 +156,19 @@ private async IAsyncEnumerable GetFilterLdapEntryAsync(string baseDn,
}
}
+ private static async Task FirstOrDefaultAsync(IAsyncEnumerable enumerable)
+ {
+#if NET10_0
+ return await enumerable.FirstOrDefaultAsync();
+#else
+ var users = enumerable.GetAsyncEnumerator();
+ if (await users.MoveNextAsync())
+ return users.Current;
+ return null;
+#endif
+
+ }
+
public async IAsyncEnumerable GetUsersInGroupAsync(string groupName)
{
var group = await GetGroupAsync(groupName);
@@ -173,8 +188,7 @@ public async IAsyncEnumerable GetUsersInGroupAsync(string groupName)
public async Task GetGroupAsync(string groupName)
{
var filter = $"(&(objectCategory=group)(objectClass=group)(cn={groupName}))";
- return await GetFilterLdapEntryAsync(_ldapOptions.GroupSearchBaseDn, filter)
- .FirstOrDefaultAsync();
+ return await FirstOrDefaultAsync(GetFilterLdapEntryAsync(_ldapOptions.UserSearchBaseDn, filter));
}
public void Dispose()
diff --git a/src/Utils/Ldap/Masa.Utils.Ldap.Novell/Masa.Utils.Ldap.Novell.csproj b/src/Utils/Ldap/Masa.Utils.Ldap.Novell/Masa.Utils.Ldap.Novell.csproj
index d3695fff5..7805b876e 100644
--- a/src/Utils/Ldap/Masa.Utils.Ldap.Novell/Masa.Utils.Ldap.Novell.csproj
+++ b/src/Utils/Ldap/Masa.Utils.Ldap.Novell/Masa.Utils.Ldap.Novell.csproj
@@ -7,7 +7,7 @@
-
+
diff --git a/src/Utils/Ldap/Tests/Masa.Utils.Ldap.Novell.Tests/LdapTest.cs b/src/Utils/Ldap/Tests/Masa.Utils.Ldap.Novell.Tests/LdapTest.cs
index 993db77aa..8240106fe 100644
--- a/src/Utils/Ldap/Tests/Masa.Utils.Ldap.Novell.Tests/LdapTest.cs
+++ b/src/Utils/Ldap/Tests/Masa.Utils.Ldap.Novell.Tests/LdapTest.cs
@@ -44,8 +44,9 @@ public void CreateLdapProvider()
[TestMethod]
public async Task GetAllUser()
{
- var allUsers = await ldapProvider.GetAllUserAsync().ToListAsync(); ;
- Assert.IsTrue(allUsers.Count > 0);
+ var allUsers = ldapProvider.GetAllUserAsync().GetAsyncEnumerator();
+ await allUsers.MoveNextAsync();
+ Assert.IsNotNull(allUsers.Current);
}
[TestMethod]
@@ -79,7 +80,8 @@ public async Task GetGroupAsync()
[TestMethod]
public async Task GetUsersInGroupAsync()
{
- var users = await ldapProvider.GetUsersInGroupAsync("杭州产品研发部").ToListAsync();
- Assert.IsTrue(users.Count > 0);
+ var users = ldapProvider.GetUsersInGroupAsync("杭州产品研发部").GetAsyncEnumerator();
+ await users.MoveNextAsync();
+ Assert.IsNotNull(users.Current);
}
}