1. 程式人生 > >應用程式框架實戰二十三:基礎查詢擴充套件

應用程式框架實戰二十三:基礎查詢擴充套件

using System.Linq; using Microsoft.VisualStudio.TestTools.UnitTesting; using Util.Datas.Ef.Tests.Repositories; using Util.Datas.Ef.Tests.Samples; namespace Util.Datas.Ef.Tests.QueryTests { /// <summary> /// 過濾測試 /// </summary> [TestClass] public class FilterTest {
/// <summary> /// 測試初始化 /// </summary> [TestInitialize] public void TestInit() { EmployeeRepository repository = GetEmployeeRepository(); repository.Clear(); repository.Add( Employee.GetEmployee() ); repository.Add( Employee.GetEmployee2() ); }
/// <summary> /// 獲取員工倉儲 /// </summary> private EmployeeRepository GetEmployeeRepository() { return new EmployeeRepository( new TestUnitOfWork() ); } /// <summary> /// 測試Filter過濾 /// </summary> [TestMethod]
public void TestFilter() { EmployeeRepository repository = GetEmployeeRepository(); //用where查詢 var result = repository.Find().Where( t => t.Name == "" ); Assert.AreEqual( 0, result.Count() ); //用Fileter查詢 result = repository.Find().Filter( t => t.Name == "" ); Assert.AreEqual( 2, result.Count() ); Assert.AreEqual( Employee.GetEmployee().Name, result.ToList()[0].Name ); Assert.AreEqual( Employee.GetEmployee2().Name, result.ToList()[1].Name ); } } }