public void AuthorSpecification_UseSpec() { var helper = new TestHelper(); var mockAuthors = helper.GetMockAuthors().AsQueryable(); var spec = new AuthorSpecification("William"); var result = mockAuthors.FirstOrDefault(spec.Criteria); Assert.NotNull(result); Assert.Equal("William", result.FirstName); Assert.Equal("Shakespear", result.LastName); }
static void Main(string[] args) { var spec1 = new ShortbookSpecification(); var spec2 = new AuthorSpecification("Author1"); using (var ctx = new BookContext()) { var repository = new AudioBookRepository(ctx); var spec2Converted = FilterConverter.ConvertSpecification <Book, AudioBook>(spec2); var results = repository.List(spec2Converted); } }
public async Task <PagedList <Author> > Handle(GetAuthorsListQuery query) { IReadOnlyList <Author> items; int count; if (!string.IsNullOrWhiteSpace(query.MainCategory)) { var countSpec = new AuthorSpecification(query.MainCategory); var listSpec = new AuthorSpecification(query.MainCategory, query.PageNumber, query.PageSize); count = await _unitOfWork.AuthorRepository.CountAsync(countSpec); items = await _unitOfWork.AuthorRepository.ListAsync(listSpec); } else { var listSpec = new AuthorSpecification(query.PageNumber, query.PageSize); count = (await _unitOfWork.AuthorRepository.ListAllAsync()).Count; items = await _unitOfWork.AuthorRepository.ListAsync(listSpec); } return(PagedList <Author> .Create(count, items.ToList(), query.PageNumber, query.PageSize)); }
public async Task <IReadOnlyList <Authors> > GetAuthorsAsync(bool includeBookInformation, List <long> authorsId) { var authorSpec = new AuthorSpecification(includeBookInformation, authorsId); return(await GetListAsync(authorSpec)); }
public async Task <Authors> GetAuthorByIdAsync(long authorId, bool includeBookInformation) { var authorSpec = new AuthorSpecification(authorId, includeBookInformation); return(await GetItemByIdAsync(authorSpec)); }