test(core-tests): 收敛选项与扩展测试的基础 warning

- 更新 OptionTests 中的 culture-sensitive 转换与 TryParse 写法
- 修正 AsyncExtensionsTests 与 CollectionExtensionsTests 的低风险异步和字符串比较写法
This commit is contained in:
gewuyou 2026-04-25 10:12:35 +08:00
parent b7560fcc08
commit b45e551fa8
3 changed files with 11 additions and 10 deletions

View File

@ -236,11 +236,11 @@ public class AsyncExtensionsTests
};
// Act & Assert
Assert.ThrowsAsync<AggregateException>(async () =>
await taskFactory.WithRetryAsync(3, TimeSpan.FromMilliseconds(10),
Assert.ThrowsAsync<AggregateException>(() =>
taskFactory.WithRetryAsync(3, TimeSpan.FromMilliseconds(10),
ex => ex is not ArgumentException));
await Task.Delay(50); // 等待任务完成
await Task.Delay(50).ConfigureAwait(false); // 等待任务完成
Assert.That(attemptCount, Is.EqualTo(1)); // 不应该重试
}
@ -330,4 +330,4 @@ public class AsyncExtensionsTests
// Assert
Assert.That(capturedEx, Is.SameAs(expectedException));
}
}
}

View File

@ -173,7 +173,7 @@ public class CollectionExtensionsTests
{
var method = typeof(GFramework.Core.Extensions.CollectionExtensions)
.GetMethods()
.Single(static method => method.Name == nameof(GFramework.Core.Extensions.CollectionExtensions.ToDictionarySafe));
.Single(static method => string.Equals(method.Name, nameof(GFramework.Core.Extensions.CollectionExtensions.ToDictionarySafe), StringComparison.Ordinal));
var methodGenericArguments = method.GetGenericArguments();
var returnTypeGenericArguments = method.ReturnType.GetGenericArguments();

View File

@ -11,6 +11,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
using System.Globalization;
using GFramework.Core.Functional;
using NUnit.Framework;
@ -122,7 +123,7 @@ public class OptionTests
public void Map_WithSome_Should_Map_Value()
{
var option = Option<int>.Some(42);
var mapped = option.Map(x => x.ToString());
var mapped = option.Map(x => x.ToString(CultureInfo.InvariantCulture));
Assert.That(mapped.IsSome, Is.True);
Assert.That(mapped.GetOrElse(""), Is.EqualTo("42"));
}
@ -134,7 +135,7 @@ public class OptionTests
public void Map_WithNone_Should_Return_None()
{
var option = Option<int>.None;
var mapped = option.Map(x => x.ToString());
var mapped = option.Map(x => x.ToString(CultureInfo.InvariantCulture));
Assert.That(mapped.IsNone, Is.True);
}
@ -155,7 +156,7 @@ public class OptionTests
public void Bind_WithSome_Should_Bind_Value()
{
var option = Option<string>.Some("42");
var bound = option.Bind(s => int.TryParse(s, out var i)
var bound = option.Bind(s => int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i)
? Option<int>.Some(i)
: Option<int>.None);
@ -170,7 +171,7 @@ public class OptionTests
public void Bind_WithSome_Can_Return_None()
{
var option = Option<string>.Some("invalid");
var bound = option.Bind(s => int.TryParse(s, out var i)
var bound = option.Bind(s => int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out var i)
? Option<int>.Some(i)
: Option<int>.None);
@ -505,4 +506,4 @@ public class OptionTests
var result = option.ToString();
Assert.That(result, Is.EqualTo("None"));
}
}
}