mirror of https://github.com/abpframework/abp.git
committed by
GitHub
9 changed files with 164 additions and 19 deletions
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.DataFiltering |
||||
|
{ |
||||
|
public class MultiTenant_Creation_Tests : MultiTenant_Creation_Tests<AbpEntityFrameworkCoreTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
|
||||
|
namespace Volo.Abp.MemoryDb.DataFilters |
||||
|
{ |
||||
|
public class MultiTenant_Creation_Tests : MultiTenant_Creation_Tests<AbpMemoryDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
using Volo.Abp.TestApp.Testing; |
||||
|
|
||||
|
namespace Volo.Abp.MongoDB.DataFiltering |
||||
|
{ |
||||
|
public class MultiTenant_Creation_Tests : MultiTenant_Creation_Tests<AbpMongoDbTestModule> |
||||
|
{ |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -1,12 +1,15 @@ |
|||||
using System; |
using System; |
||||
using Volo.Abp.Application.Dtos; |
using Volo.Abp.Application.Dtos; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
|
||||
namespace Volo.Abp.TestApp.Application.Dto |
namespace Volo.Abp.TestApp.Application.Dto |
||||
{ |
{ |
||||
public class PersonDto : EntityDto<Guid> |
public class PersonDto : EntityDto<Guid>, IMultiTenant |
||||
{ |
{ |
||||
public string Name { get; set; } |
public string Name { get; set; } |
||||
|
|
||||
public int Age { get; set; } |
public int Age { get; set; } |
||||
|
|
||||
|
public Guid? TenantId { get; set; } |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,77 @@ |
|||||
|
using System; |
||||
|
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.Modularity; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.TestApp.Application; |
||||
|
using Volo.Abp.TestApp.Application.Dto; |
||||
|
using Volo.Abp.TestApp.Domain; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.TestApp.Testing |
||||
|
{ |
||||
|
public abstract class MultiTenant_Creation_Tests<TStartupModule> : TestAppTestBase<TStartupModule> |
||||
|
where TStartupModule : IAbpModule |
||||
|
{ |
||||
|
private ICurrentTenant _fakeCurrentTenant; |
||||
|
private readonly IRepository<Person, Guid> _personRepository; |
||||
|
private readonly IPeopleAppService _peopleAppService; |
||||
|
|
||||
|
protected MultiTenant_Creation_Tests() |
||||
|
{ |
||||
|
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); |
||||
|
_peopleAppService = GetRequiredService<IPeopleAppService>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
_fakeCurrentTenant = Substitute.For<ICurrentTenant>(); |
||||
|
services.AddSingleton(_fakeCurrentTenant); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async void Should_Set_TenantId_For_New_Person() |
||||
|
{ |
||||
|
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); |
||||
|
|
||||
|
var personId = Guid.NewGuid(); |
||||
|
await _peopleAppService.CreateAsync(new PersonDto |
||||
|
{ |
||||
|
Id = personId, |
||||
|
Name = "Person1", |
||||
|
Age = 21 |
||||
|
}); |
||||
|
|
||||
|
var person = await _personRepository.FindAsync(personId); |
||||
|
|
||||
|
person.ShouldNotBeNull(); |
||||
|
person.TenantId.ShouldNotBeNull(); |
||||
|
person.TenantId.ShouldNotBe(Guid.Empty); |
||||
|
person.TenantId.ShouldBe(TestDataBuilder.TenantId1); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async void Should_Set_Null_TenantId_For_Host_Tenant() |
||||
|
{ |
||||
|
_fakeCurrentTenant.Id.Returns((Guid?)null); |
||||
|
|
||||
|
var personId = Guid.NewGuid(); |
||||
|
await _peopleAppService.CreateAsync(new PersonDto |
||||
|
{ |
||||
|
Id = personId, |
||||
|
Name = "Person1", |
||||
|
Age = 21 |
||||
|
}); |
||||
|
|
||||
|
var person = await _personRepository.FindAsync(personId); |
||||
|
|
||||
|
person.ShouldNotBeNull(); |
||||
|
person.TenantId.ShouldBeNull(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue