Merge pull request #10136 from abpframework/liangshiwei/iqueryable

Make IRepository not inherit from IQueryable
pull/10172/head^2
Halil İbrahim Kalkan 4 years ago committed by GitHub
commit b6ee15d9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -153,19 +153,6 @@ namespace Volo.Abp.Application.Services
return query;
}
/// <summary>
/// This method should create <see cref="IQueryable{TEntity}"/> based on given input.
/// It should filter query if needed, but should not do sorting or paging.
/// Sorting should be done in <see cref="ApplySorting"/> and paging should be done in <see cref="ApplyPaging"/>
/// methods.
/// </summary>
/// <param name="input">The input.</param>
[Obsolete("Override the CreateFilteredQueryAsync method instead.")]
protected virtual IQueryable<TEntity> CreateFilteredQuery(TGetListInput input)
{
return ReadOnlyRepository;
}
/// <summary>
/// This method should create <see cref="IQueryable{TEntity}"/> based on given input.
/// It should filter query if needed, but should not do sorting or paging.
@ -175,17 +162,6 @@ namespace Volo.Abp.Application.Services
/// <param name="input">The input.</param>
protected virtual async Task<IQueryable<TEntity>> CreateFilteredQueryAsync(TGetListInput input)
{
/* If user has overridden the CreateFilteredQuery method,
* we don't want to make breaking change in this point.
*/
#pragma warning disable 618
var query = CreateFilteredQuery(input);
#pragma warning restore 618
if (!ReferenceEquals(query, ReadOnlyRepository))
{
return query;
}
return await ReadOnlyRepository.GetQueryableAsync();
}

@ -10,7 +10,7 @@ using Volo.Abp.Linq;
namespace Volo.Abp.Domain.Repositories
{
public interface IReadOnlyRepository<TEntity> : IQueryable<TEntity>, IReadOnlyBasicRepository<TEntity>
public interface IReadOnlyRepository<TEntity>: IReadOnlyBasicRepository<TEntity>
where TEntity : class, IEntity
{
IAsyncQueryableExecuter AsyncExecuter { get; }
@ -26,7 +26,7 @@ namespace Volo.Abp.Domain.Repositories
Task<IQueryable<TEntity>> WithDetailsAsync(params Expression<Func<TEntity, object>>[] propertySelectors); //TODO: CancellationToken
Task<IQueryable<TEntity>> GetQueryableAsync(); //TODO: CancellationToken
/// <summary>
/// Gets a list of entities by the given <paramref name="predicate"/>.
/// </summary>

@ -1,6 +1,5 @@
using JetBrains.Annotations;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
@ -15,15 +14,6 @@ namespace Volo.Abp.Domain.Repositories
public abstract class RepositoryBase<TEntity> : BasicRepositoryBase<TEntity>, IRepository<TEntity>, IUnitOfWorkManagerAccessor
where TEntity : class, IEntity
{
[Obsolete("This method will be removed in future versions.")]
public virtual Type ElementType => GetQueryable().ElementType;
[Obsolete("This method will be removed in future versions.")]
public virtual Expression Expression => GetQueryable().Expression;
[Obsolete("This method will be removed in future versions.")]
public virtual IQueryProvider Provider => GetQueryable().Provider;
[Obsolete("Use WithDetailsAsync method.")]
public virtual IQueryable<TEntity> WithDetails()
{
@ -46,18 +36,6 @@ namespace Volo.Abp.Domain.Repositories
return GetQueryableAsync();
}
[Obsolete("This method will be removed in future versions.")]
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
[Obsolete("This method will be removed in future versions.")]
public IEnumerator<TEntity> GetEnumerator()
{
return GetQueryable().GetEnumerator();
}
[Obsolete("Use GetQueryableAsync method.")]
protected abstract IQueryable<TEntity> GetQueryable();

@ -17,7 +17,7 @@ using Volo.Abp.MultiTenancy;
namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
{
public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IEfCoreRepository<TEntity>, IAsyncEnumerable<TEntity>
public class EfCoreRepository<TDbContext, TEntity> : RepositoryBase<TEntity>, IEfCoreRepository<TEntity>
where TDbContext : IEfCoreDbContext
where TEntity : class, IEntity
{
@ -381,12 +381,6 @@ namespace Volo.Abp.Domain.Repositories.EntityFrameworkCore
return query;
}
[Obsolete("This method will be deleted in future versions.")]
public IAsyncEnumerator<TEntity> GetAsyncEnumerator(CancellationToken cancellationToken = default)
{
return DbSet.AsAsyncEnumerable().GetAsyncEnumerator(cancellationToken);
}
protected virtual void CheckAndSetId(TEntity entity)
{
if (entity is IEntity<Guid> entityWithGuidId)

@ -2,6 +2,7 @@ using JetBrains.Annotations;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
@ -23,8 +24,7 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
{
public class MongoDbRepository<TMongoDbContext, TEntity>
: RepositoryBase<TEntity>,
IMongoDbRepository<TEntity>,
IMongoQueryable<TEntity>
IMongoDbRepository<TEntity>
where TMongoDbContext : IAbpMongoDbContext
where TEntity : class, IEntity
{
@ -721,24 +721,6 @@ namespace Volo.Abp.Domain.Repositories.MongoDB
return aggregate;
}
[Obsolete("This method will be removed in future versions.")]
public QueryableExecutionModel GetExecutionModel()
{
return GetMongoQueryable().GetExecutionModel();
}
[Obsolete("This method will be removed in future versions.")]
public IAsyncCursor<TEntity> ToCursor(CancellationToken cancellationToken = new CancellationToken())
{
return GetMongoQueryable().ToCursor(GetCancellationToken(cancellationToken));
}
[Obsolete("This method will be removed in future versions.")]
public Task<IAsyncCursor<TEntity>> ToCursorAsync(CancellationToken cancellationToken = new CancellationToken())
{
return GetMongoQueryable().ToCursorAsync(GetCancellationToken(cancellationToken));
}
}
public class MongoDbRepository<TMongoDbContext, TEntity, TKey>

@ -24,28 +24,31 @@ namespace Volo.Abp.EntityFrameworkCore
}
[Fact]
public void Should_Accept_EfCore_Related_Queries()
public async Task Should_Accept_EfCore_Related_Queries()
{
var query = _personRepository.Where(p => p.Age > 0);
_efCoreAsyncQueryableProvider.CanExecute(query).ShouldBeTrue();
using ( _ = _unitOfWorkManager.Begin())
{
var query = (await _personRepository.GetQueryableAsync()).Where(p => p.Age > 0);
_efCoreAsyncQueryableProvider.CanExecute(query).ShouldBeTrue();
}
}
[Fact]
public void Should_Not_Accept_Other_Providers()
{
var query = new[] {1, 2, 3}.AsQueryable().Where(x => x > 0);
_efCoreAsyncQueryableProvider.CanExecute(query).ShouldBeFalse();
}
[Fact]
public async Task Should_Execute_Queries()
{
using (var uow = _unitOfWorkManager.Begin())
{
var query = _personRepository.Where(p => p.Age > 0);
var query = (await _personRepository.GetQueryableAsync()).Where(p => p.Age > 0);
(await _efCoreAsyncQueryableProvider.CountAsync(query) > 0).ShouldBeTrue();
(await _efCoreAsyncQueryableProvider.FirstOrDefaultAsync(query)).ShouldNotBeNull();
(await _efCoreAsyncQueryableProvider.ToListAsync(query)).Count.ShouldBeGreaterThan(0);
@ -54,4 +57,4 @@ namespace Volo.Abp.EntityFrameworkCore
}
}
}
}
}

@ -1,6 +1,7 @@
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Shouldly;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.TestApp.Testing;
using Xunit;

@ -26,9 +26,9 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
[Fact]
public async Task GetBookList()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
_bookRepository.Any().ShouldBeTrue();
(await _bookRepository.AnyAsync()).ShouldBeTrue();
return Task.CompletedTask;
});
}
@ -36,9 +36,9 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
[Fact]
public async Task GetPhoneInSecondDbContextList()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
_phoneInSecondDbContextRepository.Any().ShouldBeTrue();
(await _phoneInSecondDbContextRepository.AnyAsync()).ShouldBeTrue();
return Task.CompletedTask;
});
}
@ -46,9 +46,9 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
[Fact]
public async Task EfCore_Include_Extension()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
var person = PersonRepository.Include(p => p.Phones).Single(p => p.Id == TestDataBuilder.UserDouglasId);
var person = await (await PersonRepository.GetDbSetAsync()).Include(p => p.Phones).SingleAsync(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
person.Phones.Count.ShouldBe(2);
return Task.CompletedTask;

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.TestApp.Domain;

@ -24,10 +24,10 @@ namespace Volo.Abp.MongoDB
}
[Fact]
public void Should_Accept_MongoDb_Related_Queries()
public async Task Should_Accept_MongoDb_Related_Queries()
{
var query = _personRepository.Where(p => p.Age > 0);
var query = (await _personRepository.GetQueryableAsync()).Where(p => p.Age > 0);
_mongoDbAsyncQueryableProvider.CanExecute(query).ShouldBeTrue();
}
@ -35,17 +35,17 @@ namespace Volo.Abp.MongoDB
public void Should_Not_Accept_Other_Providers()
{
var query = new[] {1, 2, 3}.AsQueryable().Where(x => x > 0);
_mongoDbAsyncQueryableProvider.CanExecute(query).ShouldBeFalse();
}
[Fact]
public async Task Should_Execute_Queries()
{
using (var uow = _unitOfWorkManager.Begin())
{
var query = _personRepository.Where(p => p.Age > 0).OrderBy(p => p.Name);
var query = (await _personRepository.GetQueryableAsync()).Where(p => p.Age > 0).OrderBy(p => p.Name);
(await _mongoDbAsyncQueryableProvider.CountAsync(query) > 0).ShouldBeTrue();
(await _mongoDbAsyncQueryableProvider.FirstOrDefaultAsync(query)).ShouldNotBeNull();
(await _mongoDbAsyncQueryableProvider.ToListAsync(query)).Count.ShouldBeGreaterThan(0);
@ -54,4 +54,4 @@ namespace Volo.Abp.MongoDB
}
}
}
}
}

@ -27,7 +27,7 @@ namespace Volo.Abp.MongoDB.Repositories
[Fact]
public async Task CanExecuteAsync()
{
_mongoDbAsyncQueryableProvider.CanExecute(_personRepository).ShouldBeTrue();
_mongoDbAsyncQueryableProvider.CanExecute(await _personRepository.GetQueryableAsync()).ShouldBeTrue();
_mongoDbAsyncQueryableProvider.CanExecute(await _personRepository.WithDetailsAsync()).ShouldBeTrue();
}
@ -36,7 +36,7 @@ namespace Volo.Abp.MongoDB.Repositories
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.FirstOrDefaultAsync(_personRepository.Where(p => p.Name == "Douglas"))).ShouldNotBeNull();
(await _mongoDbAsyncQueryableProvider.FirstOrDefaultAsync((await _personRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas"))).ShouldNotBeNull();
await uow.CompleteAsync();
}
}
@ -46,7 +46,7 @@ namespace Volo.Abp.MongoDB.Repositories
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.AnyAsync(_personRepository, p => p.Name == "Douglas")).ShouldBeTrue();
(await _mongoDbAsyncQueryableProvider.AnyAsync(await _personRepository.GetQueryableAsync(), p => p.Name == "Douglas")).ShouldBeTrue();
await uow.CompleteAsync();
}
}
@ -56,7 +56,7 @@ namespace Volo.Abp.MongoDB.Repositories
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.CountAsync(_personRepository.Where(p => p.Name == "Douglas"))).ShouldBeGreaterThan(0);
(await _mongoDbAsyncQueryableProvider.CountAsync((await _personRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas"))).ShouldBeGreaterThan(0);
await uow.CompleteAsync();
}
}
@ -66,7 +66,7 @@ namespace Volo.Abp.MongoDB.Repositories
{
using (var uow = _unitOfWorkManager.Begin())
{
(await _mongoDbAsyncQueryableProvider.LongCountAsync(_personRepository)).ShouldBeGreaterThan(0);
(await _mongoDbAsyncQueryableProvider.LongCountAsync(await _personRepository.GetQueryableAsync())).ShouldBeGreaterThan(0);
await uow.CompleteAsync();
}
}

@ -14,21 +14,21 @@ namespace Volo.Abp.MongoDB.Repositories
public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMongoDbTestModule>
{
[Fact]
public void ToMongoQueryable_Test()
public async Task ToMongoQueryable_Test()
{
((IMongoQueryable<Person>) PersonRepository).ShouldNotBeNull();
PersonRepository.As<IMongoQueryable<Person>>().ShouldNotBeNull();
((IMongoQueryable<Person>) PersonRepository.Where(p => p.Name == "Douglas")).ShouldNotBeNull();
PersonRepository.Where(p => p.Name == "Douglas").As<IMongoQueryable<Person>>().ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).As<IMongoQueryable<Person>>().ShouldNotBeNull();
((IMongoQueryable<Person>)(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas")).ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).Where(p => p.Name == "Douglas").As<IMongoQueryable<Person>>().ShouldNotBeNull();
}
[Fact]
public async Task Linq_Queries()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
PersonRepository.Count().ShouldBeGreaterThan(0);
(await PersonRepository.GetQueryableAsync()).FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull();
(await PersonRepository.GetQueryableAsync()).Count().ShouldBeGreaterThan(0);
return Task.CompletedTask;
});
}

@ -10,7 +10,7 @@ namespace Volo.Abp.TestApp.Application
//This is especially used to test the AbstractKeyCrudAppService
public class DistrictAppService : AbstractKeyCrudAppService<District, DistrictDto, DistrictKey>
{
public DistrictAppService(IRepository<District> repository)
public DistrictAppService(IRepository<District> repository)
: base(repository)
{
}
@ -23,7 +23,7 @@ namespace Volo.Abp.TestApp.Application
protected override async Task<District> GetEntityByIdAsync(DistrictKey id)
{
return await AsyncExecuter.FirstOrDefaultAsync(
Repository.Where(d => d.CityId == id.CityId && d.Name == id.Name)
(await Repository.GetQueryableAsync()).Where(d => d.CityId == id.CityId && d.Name == id.Name)
);
}
}

@ -13,7 +13,7 @@ using Xunit;
namespace Volo.Abp.TestApp.Testing
{
public abstract class DomainEvents_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
public abstract class DomainEvents_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
protected readonly IRepository<Person, Guid> PersonRepository;
@ -35,7 +35,7 @@ namespace Volo.Abp.TestApp.Testing
bool douglesNameChangeHandled = false;
bool customEventHandled = false;
bool customEvent2Handled = false;
LocalEventBus.Subscribe<EntityCreatedEventData<Person>>(data =>
{
data.Entity.Name.ShouldBe("TestPerson1");
@ -46,7 +46,7 @@ namespace Volo.Abp.TestApp.Testing
customEvent2Handled.ShouldBeFalse();
return Task.CompletedTask;
});
LocalEventBus.Subscribe<MyCustomEventData>(data =>
{
data.Value.ShouldBe("42");
@ -57,7 +57,7 @@ namespace Volo.Abp.TestApp.Testing
customEvent2Handled.ShouldBeFalse();
return Task.CompletedTask;
});
LocalEventBus.Subscribe<PersonNameChangedEvent>(data =>
{
data.OldName.ShouldBe("Douglas");
@ -69,7 +69,7 @@ namespace Volo.Abp.TestApp.Testing
customEvent2Handled.ShouldBeFalse();
return Task.CompletedTask;
});
LocalEventBus.Subscribe<EntityUpdatedEventData<Person>>(data =>
{
data.Entity.Name.ShouldBe("Douglas-Updated");
@ -80,7 +80,7 @@ namespace Volo.Abp.TestApp.Testing
customEvent2Handled.ShouldBeFalse();
return Task.CompletedTask;
});
LocalEventBus.Subscribe<MyCustomEventData2>(data =>
{
data.Value.ShouldBe("44");
@ -97,13 +97,13 @@ namespace Volo.Abp.TestApp.Testing
await PersonRepository.InsertAsync(
new Person(Guid.NewGuid(), "TestPerson1", 42)
);
await LocalEventBus.PublishAsync(new MyCustomEventData { Value = "42" });
var douglas = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId);
douglas.ChangeName("Douglas-Updated");
await PersonRepository.UpdateAsync(douglas);
await LocalEventBus.PublishAsync(new MyCustomEventData2 { Value = "44" });
});
}
@ -112,7 +112,7 @@ namespace Volo.Abp.TestApp.Testing
public virtual async Task Should_Rollback_Uow_If_Event_Handler_Throws_Exception()
{
(await PersonRepository.FindAsync(x => x.Name == "TestPerson1")).ShouldBeNull();
LocalEventBus.Subscribe<EntityCreatedEventData<Person>>(data =>
{
data.Entity.Name.ShouldBe("TestPerson1");
@ -128,7 +128,7 @@ namespace Volo.Abp.TestApp.Testing
);
});
});
exception.Message.ShouldBe("Just to rollback the UOW");
(await PersonRepository.FindAsync(x => x.Name == "TestPerson1")).ShouldBeNull();
@ -162,7 +162,7 @@ namespace Volo.Abp.TestApp.Testing
await WithUnitOfWorkAsync(async () =>
{
var dougles = PersonRepository.Single(b => b.Name == "Douglas");
var dougles = await PersonRepository.SingleAsync(b => b.Name == "Douglas");
dougles.ChangeName("Douglas-Changed");
await PersonRepository.UpdateAsync(dougles);
});
@ -172,15 +172,15 @@ namespace Volo.Abp.TestApp.Testing
isLocalEventTriggered.ShouldBeTrue();
isDistributedEventTriggered.ShouldBeTrue();
}
private class MyCustomEventData
{
public string Value { get; set; }
}
private class MyCustomEventData2
{
public string Value { get; set; }
}
}
}
}

@ -14,7 +14,7 @@ using Xunit;
namespace Volo.Abp.TestApp.Testing
{
public abstract class MultiTenant_Filter_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
public abstract class MultiTenant_Filter_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
private ICurrentTenant _fakeCurrentTenant;
@ -36,13 +36,13 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Should_Get_Person_For_Current_Tenant()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
//TenantId = null
_fakeCurrentTenant.Id.Returns((Guid?)null);
var people = _personRepository.ToList();
var people = await _personRepository.ToListAsync();
people.Count.ShouldBe(1);
people.Any(p => p.Name == "Douglas").ShouldBeTrue();
@ -50,7 +50,7 @@ namespace Volo.Abp.TestApp.Testing
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1);
people = _personRepository.ToList();
people = await _personRepository.ToListAsync();
people.Count.ShouldBe(2);
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue();
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue();
@ -59,7 +59,7 @@ namespace Volo.Abp.TestApp.Testing
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2);
people = _personRepository.ToList();
people = await _personRepository.ToListAsync();
people.Count.ShouldBe(0);
return Task.CompletedTask;
@ -69,19 +69,19 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
List<Person> people;
using (_multiTenantFilter.Disable())
{
//Filter disabled manually
people = _personRepository.ToList();
people = await _personRepository.ToListAsync();
people.Count.ShouldBe(3);
}
//Filter re-enabled automatically
people = _personRepository.ToList();
people = await _personRepository.ToListAsync();
people.Count.ShouldBe(1);
return Task.CompletedTask;

@ -22,9 +22,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public virtual async Task FirstOrDefault()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
var entity = EntityWithIntPkRepository.FirstOrDefault(e => e.Name == "Entity1");
var entity = await EntityWithIntPkRepository.FirstOrDefaultAsync(e => e.Name == "Entity1");
entity.ShouldNotBeNull();
entity.Name.ShouldBe("Entity1");
return Task.CompletedTask;

@ -23,9 +23,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Any()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
PersonRepository.Any().ShouldBeTrue();
(await PersonRepository.AnyAsync()).ShouldBeTrue();
return Task.CompletedTask;
});
}
@ -33,9 +33,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Single()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
var person = PersonRepository.Single(p => p.Id == TestDataBuilder.UserDouglasId);
var person = await PersonRepository.SingleAsync(p => p.Id == TestDataBuilder.UserDouglasId);
person.Name.ShouldBe("Douglas");
return Task.CompletedTask;
});

@ -24,9 +24,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task SpecificationWithRepository_Test()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
CityRepository.Count(new CitySpecification().ToExpression()).ShouldBe(1);
(await CityRepository.CountAsync(new CitySpecification().ToExpression())).ShouldBe(1);
return Task.CompletedTask;
});
}
@ -39,4 +39,4 @@ namespace Volo.Abp.TestApp.Testing
return city => city.Name == "Istanbul";
}
}
}
}

@ -10,7 +10,7 @@ using Xunit;
namespace Volo.Abp.TestApp.Testing
{
public abstract class SoftDelete_Filter_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
public abstract class SoftDelete_Filter_Tests<TStartupModule> : TestAppTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
protected readonly IRepository<Person, Guid> PersonRepository;
@ -25,9 +25,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Should_Not_Get_Deleted_Entities_Linq()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
var person = PersonRepository.FirstOrDefault(p => p.Name == "John-Deleted");
var person = await PersonRepository.FirstOrDefaultAsync(p => p.Name == "John-Deleted");
person.ShouldBeNull();
return Task.CompletedTask;
});
@ -46,9 +46,9 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Should_Not_Get_Deleted_Entities_By_Default_ToList()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
var people = PersonRepository.ToList();
var people = await PersonRepository.ToListAsync();
people.Count.ShouldBe(1);
people.Any(p => p.Name == "Douglas").ShouldBeTrue();
return Task.CompletedTask;
@ -58,36 +58,36 @@ namespace Volo.Abp.TestApp.Testing
[Fact]
public async Task Should_Get_Deleted_Entities_When_Filter_Is_Disabled()
{
await WithUnitOfWorkAsync(() =>
await WithUnitOfWorkAsync(async () =>
{
//Soft delete is enabled by default
var people = PersonRepository.ToList();
var people = await PersonRepository.ToListAsync();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();
using (DataFilter.Disable<ISoftDelete>())
{
//Soft delete is disabled
people = PersonRepository.ToList();
people = await PersonRepository.ToListAsync();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeTrue();
using (DataFilter.Enable<ISoftDelete>())
{
//Soft delete is enabled again
people = PersonRepository.ToList();
people = await PersonRepository.ToListAsync();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();
}
//Soft delete is disabled (restored previous state)
people = PersonRepository.ToList();
people = await PersonRepository.ToListAsync();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeTrue();
}
//Soft delete is enabled (restored previous state)
people = PersonRepository.ToList();
people = await PersonRepository.ToListAsync();
people.Any(p => !p.IsDeleted).ShouldBeTrue();
people.Any(p => p.IsDeleted).ShouldBeFalse();

@ -69,7 +69,7 @@ namespace Volo.Abp.TenantManagement.EntityFrameworkCore
public virtual async Task<long> GetCountAsync(string filter = null, CancellationToken cancellationToken = default)
{
return await this
return await (await GetQueryableAsync())
.WhereIf(
!filter.IsNullOrWhiteSpace(),
u =>

@ -22,7 +22,7 @@ namespace Volo.Abp.Users.EntityFrameworkCore
public async Task<TUser> FindByUserNameAsync(string userName, CancellationToken cancellationToken = default)
{
return await this.OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
return await (await GetDbSetAsync()).OrderBy(x => x.Id).FirstOrDefaultAsync(u => u.UserName == userName, GetCancellationToken(cancellationToken));
}
public virtual async Task<List<TUser>> GetListAsync(IEnumerable<Guid> ids, CancellationToken cancellationToken = default)

Loading…
Cancel
Save