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.

46 lines
1.1 KiB
C#

6 years ago
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();
}
}
}