LinqExtensionTest.cs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using Masuit.Tools.Core.Linq;
  2. using System;
  3. using System.Linq.Expressions;
  4. using Xunit;
  5. namespace Masuit.Tools.UnitTest
  6. {
  7. public class LinqExtensionTest
  8. {
  9. [Fact]
  10. public void And_TwoBoolExpression()
  11. {
  12. //arrange
  13. Expression<Func<string, bool>> where1 = s => s.StartsWith("a");
  14. Expression<Func<string, bool>> where2 = s => s.Length > 10;
  15. Func<string, bool> func = where1.And(where2).Compile();
  16. //act assert
  17. Assert.False(func("abc"));
  18. Assert.True(func("abcd12345678"));
  19. }
  20. [Fact]
  21. public void Or_TwoBoolExpression()
  22. {
  23. //arrange
  24. Expression<Func<string, bool>> where1 = s => s.StartsWith("a");
  25. Expression<Func<string, bool>> where2 = s => s.Length > 10;
  26. Func<string, bool> func = where1.Or(where2).Compile();
  27. //act assert
  28. Assert.True(func("abc"));
  29. Assert.True(func("abcd12345678"));
  30. Assert.False(func("cbcd12348"));
  31. }
  32. }
  33. }