Viyi.Util.Test/Linq/TestForEach.cs
(完整代码) 1KBusing Viyi.Util.Linq;
using Xunit;
using Xunit.Abstractions;
namespace Viyi.Util.Test.Linq;
public class TestForEach {
readonly ITestOutputHelper output;
public TestForEach(ITestOutputHelper output) {
this.output = output;
}
[Fact]
public void TestAction() {
Enumerable.Range(0, 10)
.Select(n => n * n)
.ForEach(n => output.WriteLine(n.ToString()));
}
[Fact]
public void TestFunc() {
Enumerable.Range(10, 10).ForEach(n => n * 10);
}
[Fact]
public void TestException() {
#pragma warning disable CS8600 // Converting null literal or possible null value to non-nullable type.
Assert.Throws<NullReferenceException>(
() => {
IEnumerable<string> source = null;
#pragma warning disable CS8604 // Possible null reference argument.
source.ForEach(t => t);
#pragma warning restore CS8604 // Possible null reference argument.
}
);
Assert.Throws<NullReferenceException>(
() => {
IEnumerable<string> source = new string[1];
#pragma warning disable CS8625 // Cannot convert null literal to non-nullable reference type.
source.ForEach((Action<string>) null);
#pragma warning restore CS8625 // Cannot convert null literal to non-nullable reference type.
}
);
#pragma warning restore CS8600 // Converting null literal or possible null value to non-nullable type.
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
