You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace LinqStudy.Test.LinqToObject
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 基本项测试
|
|
|
|
|
/// 异常、空值等项
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class LinqTest
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Null_Test()
|
|
|
|
|
{
|
|
|
|
|
List<Person> person = null;
|
|
|
|
|
|
|
|
|
|
//对Linq操作符而言,基本上数据源为Null时,将引发异常。
|
|
|
|
|
Assert.ThrowsAny<ArgumentNullException>(() =>
|
|
|
|
|
{
|
|
|
|
|
var query = person.Where(p => p == null);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void Count_0_Test()
|
|
|
|
|
{
|
|
|
|
|
List<Person> person = new List<Person>();
|
|
|
|
|
|
|
|
|
|
//数据源为没有任何内容项时,即 Count=0,不会引发异常。
|
|
|
|
|
Action action = () =>
|
|
|
|
|
{
|
|
|
|
|
//查不到任何数据,不返回null,而是返回 Count=0的对象。
|
|
|
|
|
person.Where(p => p == null).ToList();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
action.Should().NotThrow();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|