public async Task <CrudSearchResult <TEntity> > Search(CrudSearchOptions searchOptions) { // TODO: Convert search options into query paramaters return(await Send <CrudSearchResult <TEntity> >(new HttpRequestMessage { Method = HttpMethod.Get, RequestUri = Url($"/api/{typeof(TEntity).Name}"), })); }
public Task <CrudSearchResult <T> > Search(CrudSearchOptions options) { var result = new CrudSearchResult <T> { Skip = options.Skip, Take = options.Take, }; var query = Table.Values.AsQueryable(); if (!string.IsNullOrWhiteSpace(options.SearchQuery)) { Expression?condition = null; var paramater = Parameter(typeof(T), "x"); // TODO: Configureable in Entity Defintion foreach (var property in typeof(T).GetProperties()) { if (property.PropertyType.IsAssignableTo(typeof(string))) { // TODO: I'd hate to make people conform to this paradigm when implementing their own repos // Maybe there is a way for the expressions to be build when the entity definition is built // Then they can just use a where clause in their repo. var match = Call( Property(paramater, property), typeof(string).GetMethod("Contains", new [] { typeof(string), typeof(StringComparison) }), new Expression[] { Constant(options.SearchQuery, typeof(string)), Constant(StringComparison.InvariantCultureIgnoreCase, typeof(StringComparison)) }); condition = condition == null ? match : Or(condition, match); } } if (condition != null) { query = query.Where((Expression <Func <T, bool> >)Lambda(condition, "WhereClause", new [] { paramater })); } } result.Count = query.Count(); if (options.Skip > 0) { query = query.Skip(options.Skip); } if (options.Take > 0) { query = query.Take(options.Take); } result.Results = query.ToAsyncEnumerable(); return(Task.FromResult(result)); }
public async Task Search_RetrievesEntitiesFromRepositoryUsingSearchOptions() { // Arrange var searchOptions = new CrudSearchOptions(); var expected = new CrudSearchResult <BlankEntity>(); repository.Setup(x => x.Search(searchOptions)).ReturnsAsync(expected); // Act var response = await service.Search(searchOptions); // Assert Assert.Equal(expected, response); }
public async Task <CrudSearchResult <T> > Search(CrudSearchOptions options) { return(await repository.Search(options)); }
public async Task <CrudSearchResult <TEntity> > Search(CrudSearchOptions searchOptions) { return(await service.Search(searchOptions)); }