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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
using System ;
using System.Collections.Generic ;
using System.Text ;
using System.Linq ;
using System.Linq.Expressions ;
using Xunit ;
namespace LinqStudy.Test.LinqToObject
{
/// <summary>
/// where操作符: 过滤查询条件
/// </summary>
public class WhereTest
{
[Fact]
public void Where_Test ( )
{
var Persons = new List < Person > ( )
{
new Person ( ) { Id = 1 , Name = "zhangsan" , Age = 2 } ,
new Person ( ) { Id = 2 , Name = "lishi" , Age = 33 }
} ;
var query = Persons . Where ( p = > p . Name . StartsWith ( "zhang" ) ) ;
var age = query . FirstOrDefault ( ) ? . Age ;
Assert . Equal ( 2 , age ) ;
}
[Fact]
public void Where_Argm_Test ( )
{
List < Person > Persons = null ;
Action act = ( ) = > { Persons . Where ( p = > p . Name . StartsWith ( "zhang" ) ) ; } ;
Assert . Throws < ArgumentNullException > ( act ) ;
}
}
}