Added a sample unit test to share same table between 2 dbcontextes.

pull/115/head
Halil İbrahim Kalkan 8 years ago
parent d992036159
commit c7780f993c

@ -1,8 +0,0 @@
using System;
namespace Volo.Abp.EntityFrameworkCore.Tests.SecondContext
{
public class Class1
{
}
}

@ -0,0 +1,49 @@
// <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.EntityFrameworkCore.TestApp.SecondContext;
namespace Volo.Abp.EntityFrameworkCore.Tests.SecondContext.Migrations
{
[DbContext(typeof(SecondDbContext))]
[Migration("20170927100405_Added_PhoneInSecondDbContext")]
partial class Added_PhoneInSecondDbContext
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "2.0.0-rtm-26452");
modelBuilder.Entity("Volo.Abp.EntityFrameworkCore.TestApp.SecondContext.BookInSecondDbContext", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Name");
b.HasKey("Id");
b.ToTable("Books");
});
modelBuilder.Entity("Volo.Abp.EntityFrameworkCore.TestApp.SecondContext.PhoneInSecondDbContext", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Number");
b.HasKey("Id");
b.ToTable("AppPhones");
});
#pragma warning restore 612, 618
}
}
}

@ -0,0 +1,20 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
using System.Collections.Generic;
namespace Volo.Abp.EntityFrameworkCore.Tests.SecondContext.Migrations
{
public partial class Added_PhoneInSecondDbContext : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
/* SecondDbContext depends on TestAppDbContext,
so no need to add migration for phones since TestAppDbContext already contains it */
}
protected override void Down(MigrationBuilder migrationBuilder)
{
}
}
}

@ -30,6 +30,18 @@ namespace Volo.Abp.EntityFrameworkCore.Tests.SecondContext.Migrations
b.ToTable("Books");
});
modelBuilder.Entity("Volo.Abp.EntityFrameworkCore.TestApp.SecondContext.PhoneInSecondDbContext", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd();
b.Property<string>("Number");
b.HasKey("Id");
b.ToTable("AppPhones");
});
#pragma warning restore 612, 618
}
}

@ -0,0 +1,11 @@
using System.ComponentModel.DataAnnotations.Schema;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext
{
[Table("AppPhones")]
public class PhoneInSecondDbContext : AggregateRoot<long>
{
public virtual string Number { get; set; }
}
}

@ -6,6 +6,8 @@ namespace Volo.Abp.EntityFrameworkCore.TestApp.SecondContext
{
public DbSet<BookInSecondDbContext> Books { get; set; }
public DbSet<PhoneInSecondDbContext> Phones { get; set; }
public SecondDbContext(DbContextOptions<SecondDbContext> options)
: base(options)
{

@ -14,11 +14,13 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
{
private readonly IRepository<Person> _personRepository;
private readonly IRepository<BookInSecondDbContext> _bookRepository;
private readonly IRepository<PhoneInSecondDbContext, long> _phoneInSecondDbContextRepository;
public Basic_Repository_Tests()
{
_personRepository = ServiceProvider.GetRequiredService<IRepository<Person>>();
_bookRepository = ServiceProvider.GetRequiredService<IRepository<BookInSecondDbContext>>();
_phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService<IRepository<PhoneInSecondDbContext, long>>();
}
[Fact]
@ -32,6 +34,12 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories
{
_bookRepository.GetList().Any().ShouldBeTrue();
}
[Fact]
public void GetPhoneInSecondDbContextList()
{
_phoneInSecondDbContextRepository.GetList().Any().ShouldBeTrue();
}
[Fact]
public async Task InsertAsync()

Loading…
Cancel
Save