Browse Source

Remove Migration from ef core test project. add city to test domain and implement in ef core and mongodb.

pull/272/head
Halil İbrahim Kalkan 8 years ago
parent
commit
1a65039fa3
  1. 11
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs
  2. 10
      src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs
  3. 66
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs
  4. 59
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs
  5. 68
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs
  6. 24
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs
  7. 70
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs
  8. 24
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs
  9. 69
      test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs
  10. 21
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs
  11. 22
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs
  12. 2
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs
  13. 2
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs
  14. 23
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs
  15. 11
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs
  16. 21
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs
  17. 13
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs
  18. 22
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs

11
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs

@ -21,5 +21,16 @@ namespace Volo.Abp.Domain.Entities
public virtual ICollection<object> DomainEvents => _domainEvents ?? (_domainEvents = new Collection<object>());
private ICollection<object> _domainEvents;
protected AggregateRoot()
{
}
protected AggregateRoot(TKey id)
: base(id)
{
}
}
}

10
src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs

@ -22,6 +22,16 @@ namespace Volo.Abp.Domain.Entities
/// <inheritdoc/>
public virtual TKey Id { get; set; }
protected Entity()
{
}
protected Entity(TKey id)
{
Id = id;
}
/// <inheritdoc/>
public override bool Equals(object obj)
{

66
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs

@ -1,66 +0,0 @@
// <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("20170927080244_Initial_Migration")]
partial class Initial_Migration
{
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.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
}
}
}

59
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs

@ -1,59 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
namespace Volo.Abp.EntityFrameworkCore.Tests.Migrations
{
public partial class Initial_Migration : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "People",
columns: table => new
{
Id = table.Column<Guid>(type: "BLOB", nullable: false),
Age = table.Column<int>(type: "INTEGER", nullable: false),
Name = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_People", x => x.Id);
});
migrationBuilder.CreateTable(
name: "AppPhones",
columns: table => new
{
Id = table.Column<long>(type: "INTEGER", nullable: false)
.Annotation("Sqlite:Autoincrement", true),
Number = table.Column<string>(type: "TEXT", nullable: true),
PersonId = table.Column<Guid>(type: "BLOB", nullable: false),
Type = table.Column<int>(type: "INTEGER", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_AppPhones", x => x.Id);
table.ForeignKey(
name: "FK_AppPhones_People_PersonId",
column: x => x.PersonId,
principalTable: "People",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_AppPhones_PersonId",
table: "AppPhones",
column: "PersonId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AppPhones");
migrationBuilder.DropTable(
name: "People");
}
}
}

68
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs

@ -1,68 +0,0 @@
// <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
}
}
}

24
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs

@ -1,24 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
using System;
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");
}
}
}

70
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs

@ -1,70 +0,0 @@
// <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("20171026101049_Added_IsDeleted_To_Person")]
partial class Added_IsDeleted_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<bool>("IsDeleted");
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
}
}
}

24
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs

@ -1,24 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.Abp.EntityFrameworkCore.Tests.Migrations
{
public partial class Added_IsDeleted_To_Person : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "IsDeleted",
table: "People",
type: "INTEGER",
nullable: false,
defaultValue: false);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "IsDeleted",
table: "People");
}
}
}

69
test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs

@ -1,69 +0,0 @@
// <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))]
partial class TestAppDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(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<bool>("IsDeleted");
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
}
}
}

21
test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs

@ -1,5 +1,7 @@
using Microsoft.Data.Sqlite;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Autofac;
using Volo.Abp.EntityFrameworkCore.TestApp.SecondContext;
@ -26,14 +28,13 @@ namespace Volo.Abp.EntityFrameworkCore
options.ReplaceDbContext<IThirdDbContext>();
});
var inMemorySqlite = new SqliteConnection("Data Source=:memory:");
inMemorySqlite.Open();
var sqliteConnection = CreateDatabaseAndGetConnection();
services.Configure<AbpDbContextOptions>(options =>
{
options.Configure(context =>
{
context.DbContextOptions.UseSqlite(inMemorySqlite);
context.DbContextOptions.UseSqlite(sqliteConnection);
});
});
}
@ -43,5 +44,19 @@ namespace Volo.Abp.EntityFrameworkCore
context.ServiceProvider.GetRequiredService<TestAppDbContext>().Database.Migrate();
context.ServiceProvider.GetRequiredService<SecondDbContext>().Database.Migrate();
}
private static SqliteConnection CreateDatabaseAndGetConnection()
{
var connection = new SqliteConnection("Data Source=:memory:");
connection.Open();
var options = new DbContextOptionsBuilder<TestAppDbContext>().UseSqlite(connection).Options;
using (var context = new TestAppDbContext(options))
{
context.GetService<IRelationalDatabaseCreator>().CreateTables();
}
return connection;
}
}
}

22
test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs

@ -0,0 +1,22 @@
using System;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.EntityFrameworkCore
{
public class CityRepository : EfCoreRepository<TestAppDbContext, City, Guid>, ICityRepository
{
public CityRepository(IDbContextProvider<TestAppDbContext> dbContextProvider)
: base(dbContextProvider)
{
}
public async Task<City> FindByNameAsync(string name)
{
return await this.FirstOrDefaultAsync(c => c.Name == name);
}
}
}

2
test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs

@ -9,6 +9,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
{
public DbSet<Person> People { get; set; }
public DbSet<City> Cities { get; set; }
public DbSet<ThirdDbContextDummyEntity> DummyEntities { get; set; }
public TestAppDbContext(DbContextOptions<TestAppDbContext> options)

2
test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs

@ -4,6 +4,7 @@ using Volo.Abp.Autofac;
using Volo.Abp.Data;
using Volo.Abp.Modularity;
using Volo.Abp.TestApp;
using Volo.Abp.TestApp.Domain;
using Volo.Abp.TestApp.MongoDb;
namespace Volo.Abp.MongoDB
@ -30,6 +31,7 @@ namespace Volo.Abp.MongoDB
services.AddMongoDbContext<TestAppMongoDbContext>(options =>
{
options.AddDefaultRepositories<ITestAppMongoDbContext>();
options.AddRepository<City, CityRepository>();
});
services.AddAssemblyOf<AbpMongoDbTestModule>();

23
test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs

@ -0,0 +1,23 @@
using System;
using System.Threading.Tasks;
using MongoDB.Driver;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
using Volo.Abp.TestApp.Domain;
namespace Volo.Abp.TestApp.MongoDb
{
public class CityRepository : MongoDbRepository<ITestAppMongoDbContext, City, Guid>,ICityRepository
{
public CityRepository(IMongoDatabaseProvider<ITestAppMongoDbContext> databaseProvider)
: base(databaseProvider)
{
}
public async Task<City> FindByNameAsync(string name)
{
return await (await Collection.FindAsync(c => c.Name == name)).FirstOrDefaultAsync();
}
}
}

11
test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs

@ -1,4 +1,5 @@
using System.Collections.Generic;
using MongoDB.Driver;
using Volo.Abp.Data;
using Volo.Abp.MongoDB;
using Volo.Abp.TestApp.Domain;
@ -8,11 +9,19 @@ namespace Volo.Abp.TestApp.MongoDb
[ConnectionStringName("TestApp")]
public class TestAppMongoDbContext : AbpMongoDbContext, ITestAppMongoDbContext
{
public IMongoCollection<Person> People { get; set; }
public IMongoCollection<City> Cities { get; set; }
//TODO: Default implementation should read mogo collections from the context!
//GetMappings should send a context and we add to it. Rename to ConfigureMappings.
public override IReadOnlyList<MongoEntityMapping> GetMappings()
{
return new[]
{
new MongoEntityMapping(typeof(Person), "People")
new MongoEntityMapping(typeof(Person), "People"),
new MongoEntityMapping(typeof(City), "Cities")
};
}
}

21
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs

@ -0,0 +1,21 @@
using System;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class City : AggregateRoot<Guid>
{
public string Name { get; set; }
private City()
{
}
public City(Guid id, string name)
: base(id)
{
Name = name;
}
}
}

13
test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs

@ -0,0 +1,13 @@
using System;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp.Domain.Repositories;
namespace Volo.Abp.TestApp.Domain
{
public interface ICityRepository : IBasicRepository<City, Guid>
{
[CanBeNull]
Task<City> FindByNameAsync(string name);
}
}

22
test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs

@ -13,17 +13,37 @@ namespace Volo.Abp.TestApp
public static Guid UserJohnDeletedId { get; } = Guid.NewGuid();
private readonly IBasicRepository<Person, Guid> _personRepository;
private readonly ICityRepository _cityRepository;
public TestDataBuilder(IBasicRepository<Person, Guid> personRepository)
public TestDataBuilder(
IBasicRepository<Person, Guid> personRepository,
ICityRepository cityRepository)
{
_personRepository = personRepository;
_cityRepository = cityRepository;
}
public void Build()
{
AddCities();
AddPeople();
}
private void AddCities()
{
_cityRepository.Insert(new City(Guid.NewGuid(), "Tokyo"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Madrid"));
_cityRepository.Insert(new City(Guid.NewGuid(), "London"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Istanbul"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Paris"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Washington"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Berlin"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Amsterdam"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Beijing"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Rome"));
_cityRepository.Insert(new City(Guid.NewGuid(), "Sao Paulo"));
}
private void AddPeople()
{
var douglas = new Person(UserDouglasId, "Douglas", 42);

Loading…
Cancel
Save