mirror of https://github.com/abpframework/abp.git
5 changed files with 20 additions and 170 deletions
@ -1,58 +0,0 @@ |
|||||
using System; |
|
||||
using System.Linq; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Shouldly; |
|
||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.Domain.Repositories; |
|
||||
using Volo.Abp.TestApp.Domain; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.Abp.MemoryDb.DataFilters |
|
||||
{ |
|
||||
public class MemoryDb_SoftDelete_DataFilter_Tests : MemoryDbTestBase |
|
||||
{ |
|
||||
private readonly IRepository<Person, Guid> _personRepository; |
|
||||
private readonly IDataFilter _dataFilter; |
|
||||
|
|
||||
public MemoryDb_SoftDelete_DataFilter_Tests() |
|
||||
{ |
|
||||
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person, Guid>>(); |
|
||||
_dataFilter = GetRequiredService<IDataFilter>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Should_Get_Deleted_Entities_When_Filter_Is_Disabled() |
|
||||
{ |
|
||||
//Soft delete is enabled by default
|
|
||||
var people = _personRepository.ToList(); |
|
||||
people.Any(p => !p.IsDeleted).ShouldBeTrue(); |
|
||||
people.Any(p => p.IsDeleted).ShouldBeFalse(); |
|
||||
|
|
||||
using (_dataFilter.Disable<ISoftDelete>()) |
|
||||
{ |
|
||||
//Soft delete is disabled
|
|
||||
people = _personRepository.ToList(); |
|
||||
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.Any(p => !p.IsDeleted).ShouldBeTrue(); |
|
||||
people.Any(p => p.IsDeleted).ShouldBeFalse(); |
|
||||
} |
|
||||
|
|
||||
//Soft delete is disabled (restored previous state)
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Any(p => !p.IsDeleted).ShouldBeTrue(); |
|
||||
people.Any(p => p.IsDeleted).ShouldBeTrue(); |
|
||||
} |
|
||||
|
|
||||
//Soft delete is enabled (restored previous state)
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Any(p => !p.IsDeleted).ShouldBeTrue(); |
|
||||
people.Any(p => p.IsDeleted).ShouldBeFalse(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,79 +1,9 @@ |
|||||
using System; |
using Volo.Abp.TestApp.Testing; |
||||
using System.Collections.Generic; |
|
||||
using System.Linq; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using NSubstitute; |
|
||||
using Shouldly; |
|
||||
using Volo.Abp.Data; |
|
||||
using Volo.Abp.Domain.Repositories; |
|
||||
using Volo.Abp.MultiTenancy; |
|
||||
using Volo.Abp.TestApp; |
|
||||
using Volo.Abp.TestApp.Domain; |
|
||||
using Xunit; |
|
||||
|
|
||||
namespace Volo.Abp.MemoryDb.DataFilters |
namespace Volo.Abp.MemoryDb.DataFilters |
||||
{ |
{ |
||||
public class MemoryDb_MultiTenant_Filter_Tests : MemoryDbTestBase |
public class MultiTenant_Filter_Tests : MultiTenant_Filter_Tests<AbpMemoryDbTestModule> |
||||
{ |
{ |
||||
private ICurrentTenant _fakeCurrentTenant; |
|
||||
private readonly IRepository<Person, Guid> _personRepository; |
|
||||
private readonly IDataFilter<IMultiTenant> _multiTenantFilter; |
|
||||
|
|
||||
public MemoryDb_MultiTenant_Filter_Tests() |
|
||||
{ |
|
||||
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|
||||
_multiTenantFilter = GetRequiredService<IDataFilter<IMultiTenant>>(); |
|
||||
} |
|
||||
|
|
||||
protected override void AfterAddApplication(IServiceCollection services) |
|
||||
{ |
|
||||
_fakeCurrentTenant = Substitute.For<ICurrentTenant>(); |
|
||||
services.AddSingleton(_fakeCurrentTenant); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Should_Get_Person_For_Current_Tenant() |
|
||||
{ |
|
||||
//TenantId = null
|
|
||||
|
|
||||
_fakeCurrentTenant.Id.Returns((Guid?)null); |
|
||||
|
|
||||
var people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBe(1); |
|
||||
people.Any(p => p.Name == "Douglas").ShouldBeTrue(); |
|
||||
|
|
||||
//TenantId = TestDataBuilder.TenantId1
|
|
||||
|
|
||||
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); |
|
||||
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBe(2); |
|
||||
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person1").ShouldBeTrue(); |
|
||||
people.Any(p => p.Name == TestDataBuilder.TenantId1 + "-Person2").ShouldBeTrue(); |
|
||||
|
|
||||
//TenantId = TestDataBuilder.TenantId2
|
|
||||
|
|
||||
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId2); |
|
||||
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBe(0); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Should_Get_All_People_When_MultiTenant_Filter_Is_Disabled() |
|
||||
{ |
|
||||
List<Person> people; |
|
||||
|
|
||||
using (_multiTenantFilter.Disable()) |
|
||||
{ |
|
||||
//Filter disabled manually
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBe(3); |
|
||||
} |
|
||||
|
|
||||
//Filter re-enabled automatically
|
|
||||
people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBe(1); |
|
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
|
||||
|
namespace Volo.Abp.MemoryDb.DataFilters |
||||
|
{ |
||||
|
public class SoftDelete_Filter_Tests : SoftDelete_Filter_Tests<AbpMemoryDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,40 +0,0 @@ |
|||||
using System; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Shouldly; |
|
||||
using Volo.Abp.Domain.Repositories; |
|
||||
using Volo.Abp.TestApp.Domain; |
|
||||
using Xunit; |
|
||||
using System.Linq; |
|
||||
|
|
||||
namespace Volo.Abp.MemoryDb.Repositories |
|
||||
{ |
|
||||
public class MemoryDb_Basic_Repository_Tests : MemoryDbTestBase |
|
||||
{ |
|
||||
private readonly IRepository<Person, Guid> _personRepository; |
|
||||
|
|
||||
public MemoryDb_Basic_Repository_Tests() |
|
||||
{ |
|
||||
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person, Guid>>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void GetList() |
|
||||
{ |
|
||||
var people = _personRepository.ToList(); |
|
||||
people.Count.ShouldBeGreaterThan(0); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public void Insert() |
|
||||
{ |
|
||||
//Arrange
|
|
||||
var name = Guid.NewGuid().ToString(); |
|
||||
|
|
||||
//Act
|
|
||||
_personRepository.Insert(new Person(Guid.NewGuid(), name, 42)); |
|
||||
|
|
||||
//Assert
|
|
||||
_personRepository.FirstOrDefault(p => p.Name == name).ShouldNotBeNull(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
|
||||
|
namespace Volo.Abp.MemoryDb.Repositories |
||||
|
{ |
||||
|
public class Repository_Basic_Tests : Repository_Basic_Tests<AbpMemoryDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue