mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
test(core-tests): 收敛选项与扩展测试的基础 warning
- 更新 OptionTests 中的 culture-sensitive 转换与 TryParse 写法 - 修正 AsyncExtensionsTests 与 CollectionExtensionsTests 的低风险异步和字符串比较写法
This commit is contained in:
parent
b7560fcc08
commit
b45e551fa8
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user