mirror of
https://github.com/ldqk/Masuit.Tools.git
synced 2026-10-20 15:51:30 +08:00
36 lines
1.0 KiB
C#
36 lines
1.0 KiB
C#
using Masuit.Tools.Core.Linq;
|
|
using System;
|
|
using System.Linq.Expressions;
|
|
using Xunit;
|
|
|
|
namespace Masuit.Tools.UnitTest
|
|
{
|
|
public class LinqExtensionTest
|
|
{
|
|
[Fact]
|
|
public void And_TwoBoolExpression()
|
|
{
|
|
//arrange
|
|
Expression<Func<string, bool>> where1 = s => s.StartsWith("a");
|
|
Expression<Func<string, bool>> where2 = s => s.Length > 10;
|
|
Func<string, bool> func = where1.And(where2).Compile();
|
|
|
|
//act assert
|
|
Assert.False(func("abc"));
|
|
Assert.True(func("abcd12345678"));
|
|
}
|
|
[Fact]
|
|
public void Or_TwoBoolExpression()
|
|
{
|
|
//arrange
|
|
Expression<Func<string, bool>> where1 = s => s.StartsWith("a");
|
|
Expression<Func<string, bool>> where2 = s => s.Length > 10;
|
|
Func<string, bool> func = where1.Or(where2).Compile();
|
|
|
|
//act assert
|
|
Assert.True(func("abc"));
|
|
Assert.True(func("abcd12345678"));
|
|
Assert.False(func("cbcd12348"));
|
|
}
|
|
}
|
|
} |