public void SpecLinquery_Default_ReturnsAll() { //Arrange const int numOfAuthors = 20; using (var uow = Stub.CreateMemoryUoW(typeof(Author))) { uow.AddAuthors(numOfAuthors); var linqProviderFactoryStub = new Mock <ILinqProviderFactory>(); linqProviderFactoryStub.Setup(a => a.Create(It.IsAny <String>(), It.IsAny <String>())).Returns(uow.Linq); var handler = new LinqRequestHandler(linqProviderFactoryStub.Object); IQuery <IQriteria, IEnumerable <AuthorDto> > query = new SpecLinqQuery <IQriteria, Author, IEnumerable <AuthorDto> >( LinqSpec <Author> .All(), handler, serviceLocator.GetInstance <IEnumLinqConvertor <AuthorDto> >() ); //Act var actual = query.Ask(new NameQriteria()); //Assert Assert.AreEqual(numOfAuthors, actual.Count()); } }
public void QueryForPageQriteria_Returns_Page() { //Arrange const int authorCount = 25; using (var UoWStub = Stub.CreateMemoryUoW(typeof(Author)) .Add( authorCount, (i) => new Author(i, "A" + (i % 2 == 0 ? "_" : "-") + Convert.ToString(i).PadLeft(2, '0')) )) { var linqProviderFactoryStub = UoWStub.LinqProviderFactory(); var handler = new LinqRequestHandler(linqProviderFactoryStub); var convertor = serviceLocator.GetInstance <IPageConvertor <AuthorDto> >(); var projector = serviceLocator.GetInstance <IProjector>(); var qrit = new PageQriteria <AuthorDto> { PageNo = 3, PageSize = 5, OrderBy = "Name", Subject = new AuthorDto { Name = "A" } }; var query = new ConventionPagedQuery <AuthorDto, AuthorDto>(handler, convertor); var expected = linqProviderFactoryStub.Create() .Query <Author>() .Where(a => a.Name.StartsWith(qrit.Subject.Name)) .OrderBy(a => a.Name) .Skip((qrit.PageNo - 1) * qrit.PageSize) .Take(qrit.PageSize) .Project <AuthorDto>(projector) .ToArray(); //Act var actual = query.Ask(qrit); //Assert CollectionAssert.AreEqual(expected, actual.Members.ToArray(), new AuthorDtoComparer()); } }