public void TestInterfaceConversion() { var expression = new Filterer <MyEntity>().Filter(); var predicate = expression.RemapTo <DbEntry <MyEntity>, MyEntity, bool>(x => x.Original); var list = new List <DbEntry <MyEntity> > { new DbEntry <MyEntity>(new MyEntity { CreatedDate = new DateTime(2017, 01, 01) }, new DefaultAnalyzer()), new DbEntry <MyEntity>(new MyEntity { CreatedDate = new DateTime(2019, 01, 01) }, new DefaultAnalyzer()) }; var result = list.AsQueryable().Where(predicate); Assert.Contains(result, x => x.Original.CreatedDate.Year == 2017); Assert.DoesNotContain(result, x => x.Original.CreatedDate.Year == 2019); }
public void MultipleLevelsShouldReturnExpectedResult() { var now = DateTime.UtcNow; var expression = new Filterer <Entity>(now).Filter(); var predicate = expression.RemapTo <NestingEntityWrapper <Entity>, Entity, bool>(x => x.InnerWrapper.Entity); var list = new List <NestingEntityWrapper <Entity> > { new NestingEntityWrapper <Entity>(new Entity { Title = "ShouldBeFound", CreatedDate = now.AddMonths(-1) }), new NestingEntityWrapper <Entity>(new Entity { Title = "ShouldNotBeFound", CreatedDate = now.AddDays(1) }) }; var result = list.AsQueryable().Where(predicate); Assert.Contains(result, x => x.InnerWrapper.Entity.Title == "ShouldBeFound"); Assert.DoesNotContain(result, x => x.InnerWrapper.Entity.Title == "ShouldNotBeFound"); }