-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
FilterQueryable
method to IMongoDbRepositoryFilterer
.
Resolve #17203
- Loading branch information
Showing
4 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
.../Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/DataFiltering/MongoDbRepositoryFilterer_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Shouldly; | ||
using Volo.Abp.Data; | ||
using Volo.Abp.Domain.Repositories; | ||
using Volo.Abp.Domain.Repositories.MongoDB; | ||
using Volo.Abp.MultiTenancy; | ||
using Volo.Abp.TestApp.Domain; | ||
using Xunit; | ||
|
||
namespace Volo.Abp.MongoDB.DataFiltering; | ||
|
||
[Collection(MongoTestCollection.Name)] | ||
public class MongoDbAsyncQueryableProvider_Tests : MongoDbTestBase | ||
{ | ||
private readonly IRepository<City, Guid> _personRepository; | ||
|
||
protected override void AfterAddApplication(IServiceCollection services) | ||
{ | ||
services.AddTransient<IMongoDbRepositoryFilterer<City, Guid>, TestFilterQueryable>(); | ||
base.AfterAddApplication(services); | ||
} | ||
|
||
public MongoDbAsyncQueryableProvider_Tests() | ||
{ | ||
_personRepository = GetRequiredService<IRepository<City, Guid>>(); | ||
} | ||
|
||
[Fact] | ||
public async Task Test() | ||
{ | ||
var cities = await _personRepository.GetListAsync(); | ||
cities.Count.ShouldBe(1); | ||
cities[0].Name.ShouldBe("Istanbul"); | ||
} | ||
} | ||
|
||
public class TestFilterQueryable : MongoDbRepositoryFilterer<City, Guid> | ||
{ | ||
public TestFilterQueryable( | ||
IDataFilter dataFilter, | ||
ICurrentTenant currentTenant) : | ||
base(dataFilter, currentTenant) | ||
{ | ||
} | ||
|
||
public override TQueryable FilterQueryable<TQueryable>(TQueryable query) | ||
{ | ||
return (TQueryable)query.Where(p => p.Name == "Istanbul"); | ||
} | ||
} |