mirror of https://github.com/abpframework/abp.git
8 changed files with 264 additions and 2 deletions
@ -0,0 +1,68 @@ |
|||||
|
// <auto-generated />
|
||||
|
using Microsoft.EntityFrameworkCore; |
||||
|
using Microsoft.EntityFrameworkCore.Infrastructure; |
||||
|
using Microsoft.EntityFrameworkCore.Metadata; |
||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
using Microsoft.EntityFrameworkCore.Storage; |
||||
|
using Microsoft.EntityFrameworkCore.Storage.Internal; |
||||
|
using System; |
||||
|
using Volo.Abp.TestApp.Domain; |
||||
|
using Volo.Abp.TestApp.EntityFrameworkCore; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.Tests.Migrations |
||||
|
{ |
||||
|
[DbContext(typeof(TestAppDbContext))] |
||||
|
[Migration("20171026084129_Added_TenantId_To_Person")] |
||||
|
partial class Added_TenantId_To_Person |
||||
|
{ |
||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder) |
||||
|
{ |
||||
|
#pragma warning disable 612, 618
|
||||
|
modelBuilder |
||||
|
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452"); |
||||
|
|
||||
|
modelBuilder.Entity("Volo.Abp.TestApp.Domain.Person", b => |
||||
|
{ |
||||
|
b.Property<Guid>("Id") |
||||
|
.ValueGeneratedOnAdd(); |
||||
|
|
||||
|
b.Property<int>("Age"); |
||||
|
|
||||
|
b.Property<string>("Name"); |
||||
|
|
||||
|
b.Property<Guid?>("TenantId"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
b.ToTable("People"); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => |
||||
|
{ |
||||
|
b.Property<long>("Id") |
||||
|
.ValueGeneratedOnAdd(); |
||||
|
|
||||
|
b.Property<string>("Number"); |
||||
|
|
||||
|
b.Property<Guid>("PersonId"); |
||||
|
|
||||
|
b.Property<int>("Type"); |
||||
|
|
||||
|
b.HasKey("Id"); |
||||
|
|
||||
|
b.HasIndex("PersonId"); |
||||
|
|
||||
|
b.ToTable("AppPhones"); |
||||
|
}); |
||||
|
|
||||
|
modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => |
||||
|
{ |
||||
|
b.HasOne("Volo.Abp.TestApp.Domain.Person") |
||||
|
.WithMany("Phones") |
||||
|
.HasForeignKey("PersonId") |
||||
|
.OnDelete(DeleteBehavior.Cascade); |
||||
|
}); |
||||
|
#pragma warning restore 612, 618
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,25 @@ |
|||||
|
using Microsoft.EntityFrameworkCore.Migrations; |
||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.Tests.Migrations |
||||
|
{ |
||||
|
public partial class Added_TenantId_To_Person : Migration |
||||
|
{ |
||||
|
protected override void Up(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.AddColumn<Guid>( |
||||
|
name: "TenantId", |
||||
|
table: "People", |
||||
|
type: "BLOB", |
||||
|
nullable: true); |
||||
|
} |
||||
|
|
||||
|
protected override void Down(MigrationBuilder migrationBuilder) |
||||
|
{ |
||||
|
migrationBuilder.DropColumn( |
||||
|
name: "TenantId", |
||||
|
table: "People"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,59 @@ |
|||||
|
using System; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using NSubstitute; |
||||
|
using Shouldly; |
||||
|
using Volo.Abp.Domain.Repositories; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.TestApp; |
||||
|
using Volo.Abp.TestApp.Domain; |
||||
|
using Xunit; |
||||
|
|
||||
|
namespace Volo.Abp.EntityFrameworkCore.Repositories |
||||
|
{ |
||||
|
public class MultiTenant_Filter_Tests : EntityFrameworkCoreTestBase |
||||
|
{ |
||||
|
private ICurrentTenant _fakeCurrentTenant; |
||||
|
private readonly IRepository<Person> _personRepository; |
||||
|
|
||||
|
public MultiTenant_Filter_Tests() |
||||
|
{ |
||||
|
_personRepository = GetRequiredService<IRepository<Person>>(); |
||||
|
} |
||||
|
|
||||
|
protected override void AfterAddApplication(IServiceCollection services) |
||||
|
{ |
||||
|
_fakeCurrentTenant = Substitute.For<ICurrentTenant>(); |
||||
|
services.AddSingleton(_fakeCurrentTenant); |
||||
|
} |
||||
|
|
||||
|
[Fact] |
||||
|
public async Task Should_Get_Person_For_Current_Tenant() |
||||
|
{ |
||||
|
//TenantId = null
|
||||
|
|
||||
|
_fakeCurrentTenant.Id.Returns((Guid?)null); |
||||
|
|
||||
|
var people = await _personRepository.GetListAsync(); |
||||
|
people.Count.ShouldBe(1); |
||||
|
people.Any(p => p.Name == "Douglas").ShouldBeTrue(); |
||||
|
|
||||
|
//TenantId = TestDataBuilder.TenantId1
|
||||
|
|
||||
|
_fakeCurrentTenant.Id.Returns(TestDataBuilder.TenantId1); |
||||
|
|
||||
|
people = await _personRepository.GetListAsync(); |
||||
|
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 = await _personRepository.GetListAsync(); |
||||
|
people.Count.ShouldBe(0); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue