From 1a65039fa3a1801a04df28fb62304d630558de7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 27 Mar 2018 13:32:24 +0300 Subject: [PATCH] Remove Migration from ef core test project. add city to test domain and implement in ef core and mongodb. --- .../Volo/Abp/Domain/Entities/AggregateRoot.cs | 11 +++ .../Volo/Abp/Domain/Entities/Entity.cs | 10 +++ ...170927080244_Initial_Migration.Designer.cs | 66 ----------------- .../20170927080244_Initial_Migration.cs | 59 ---------------- ...84129_Added_TenantId_To_Person.Designer.cs | 68 ------------------ ...20171026084129_Added_TenantId_To_Person.cs | 24 ------- ...1049_Added_IsDeleted_To_Person.Designer.cs | 70 ------------------- ...0171026101049_Added_IsDeleted_To_Person.cs | 24 ------- .../TestAppDbContextModelSnapshot.cs | 69 ------------------ .../AbpEntityFrameworkCoreTestModule.cs | 21 +++++- .../EntityFrameworkCore/CityRepository.cs | 22 ++++++ .../EntityFrameworkCore/TestAppDbContext.cs | 2 + .../Volo/Abp/MongoDB/AbpMongoDbTestModule.cs | 2 + .../Abp/TestApp/MongoDb/CityRepository.cs | 23 ++++++ .../TestApp/MongoDb/TestAppMongoDbContext.cs | 11 ++- .../Volo/Abp/TestApp/Domain/City.cs | 21 ++++++ .../Abp/TestApp/Domain/ICityRepository.cs | 13 ++++ .../Volo/Abp/TestApp/TestDataBuilder.cs | 22 +++++- 18 files changed, 153 insertions(+), 385 deletions(-) delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs delete mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs create mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs create mode 100644 test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs create mode 100644 test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs create mode 100644 test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs diff --git a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs index 8382a2dcd4..ce7a31ec61 100644 --- a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs +++ b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs @@ -21,5 +21,16 @@ namespace Volo.Abp.Domain.Entities public virtual ICollection DomainEvents => _domainEvents ?? (_domainEvents = new Collection()); private ICollection _domainEvents; + + protected AggregateRoot() + { + + } + + protected AggregateRoot(TKey id) + : base(id) + { + + } } } \ No newline at end of file diff --git a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs index 25e6fdd443..adf991ab4e 100644 --- a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs +++ b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/Entity.cs @@ -22,6 +22,16 @@ namespace Volo.Abp.Domain.Entities /// public virtual TKey Id { get; set; } + protected Entity() + { + + } + + protected Entity(TKey id) + { + Id = id; + } + /// public override bool Equals(object obj) { diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs deleted file mode 100644 index 594586a2fc..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.Designer.cs +++ /dev/null @@ -1,66 +0,0 @@ -// -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("Id") - .ValueGeneratedOnAdd(); - - b.Property("Age"); - - b.Property("Name"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Number"); - - b.Property("PersonId"); - - b.Property("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 - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs deleted file mode 100644 index 6b92668a19..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20170927080244_Initial_Migration.cs +++ /dev/null @@ -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(type: "BLOB", nullable: false), - Age = table.Column(type: "INTEGER", nullable: false), - Name = table.Column(type: "TEXT", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_People", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AppPhones", - columns: table => new - { - Id = table.Column(type: "INTEGER", nullable: false) - .Annotation("Sqlite:Autoincrement", true), - Number = table.Column(type: "TEXT", nullable: true), - PersonId = table.Column(type: "BLOB", nullable: false), - Type = table.Column(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"); - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs deleted file mode 100644 index 697ae217b1..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.Designer.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -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("Id") - .ValueGeneratedOnAdd(); - - b.Property("Age"); - - b.Property("Name"); - - b.Property("TenantId"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Number"); - - b.Property("PersonId"); - - b.Property("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 - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs deleted file mode 100644 index e5e15e95a7..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026084129_Added_TenantId_To_Person.cs +++ /dev/null @@ -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( - name: "TenantId", - table: "People", - type: "BLOB", - nullable: true); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "TenantId", - table: "People"); - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs deleted file mode 100644 index cdb7a97811..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.Designer.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -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("Id") - .ValueGeneratedOnAdd(); - - b.Property("Age"); - - b.Property("IsDeleted"); - - b.Property("Name"); - - b.Property("TenantId"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Number"); - - b.Property("PersonId"); - - b.Property("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 - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs deleted file mode 100644 index 046a911bbc..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/20171026101049_Added_IsDeleted_To_Person.cs +++ /dev/null @@ -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( - name: "IsDeleted", - table: "People", - type: "INTEGER", - nullable: false, - defaultValue: false); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "IsDeleted", - table: "People"); - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs deleted file mode 100644 index 36c10563a5..0000000000 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Migrations/TestAppDbContextModelSnapshot.cs +++ /dev/null @@ -1,69 +0,0 @@ -// -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("Id") - .ValueGeneratedOnAdd(); - - b.Property("Age"); - - b.Property("IsDeleted"); - - b.Property("Name"); - - b.Property("TenantId"); - - b.HasKey("Id"); - - b.ToTable("People"); - }); - - modelBuilder.Entity("Volo.Abp.TestApp.Domain.Phone", b => - { - b.Property("Id") - .ValueGeneratedOnAdd(); - - b.Property("Number"); - - b.Property("PersonId"); - - b.Property("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 - } - } -} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs index 9496844b0b..fc0414cb7f 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/AbpEntityFrameworkCoreTestModule.cs +++ b/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(); }); - var inMemorySqlite = new SqliteConnection("Data Source=:memory:"); - inMemorySqlite.Open(); + var sqliteConnection = CreateDatabaseAndGetConnection(); services.Configure(options => { options.Configure(context => { - context.DbContextOptions.UseSqlite(inMemorySqlite); + context.DbContextOptions.UseSqlite(sqliteConnection); }); }); } @@ -43,5 +44,19 @@ namespace Volo.Abp.EntityFrameworkCore context.ServiceProvider.GetRequiredService().Database.Migrate(); context.ServiceProvider.GetRequiredService().Database.Migrate(); } + + private static SqliteConnection CreateDatabaseAndGetConnection() + { + var connection = new SqliteConnection("Data Source=:memory:"); + connection.Open(); + + var options = new DbContextOptionsBuilder().UseSqlite(connection).Options; + using (var context = new TestAppDbContext(options)) + { + context.GetService().CreateTables(); + } + + return connection; + } } } diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs new file mode 100644 index 0000000000..09373153c5 --- /dev/null +++ b/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, ICityRepository + { + public CityRepository(IDbContextProvider dbContextProvider) + : base(dbContextProvider) + { + } + + public async Task FindByNameAsync(string name) + { + return await this.FirstOrDefaultAsync(c => c.Name == name); + } + } +} diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs index 49deda972e..00e052d2dd 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore { public DbSet People { get; set; } + public DbSet Cities { get; set; } + public DbSet DummyEntities { get; set; } public TestAppDbContext(DbContextOptions options) diff --git a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs index 6e714b1b2f..b5d38552fe 100644 --- a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs +++ b/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(options => { options.AddDefaultRepositories(); + options.AddRepository(); }); services.AddAssemblyOf(); diff --git a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs new file mode 100644 index 0000000000..2d6e40e64a --- /dev/null +++ b/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,ICityRepository + { + public CityRepository(IMongoDatabaseProvider databaseProvider) + : base(databaseProvider) + { + + } + + public async Task FindByNameAsync(string name) + { + return await (await Collection.FindAsync(c => c.Name == name)).FirstOrDefaultAsync(); + } + } +} diff --git a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs index 1018012ae2..7e6f366754 100644 --- a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs +++ b/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 People { get; set; } + + public IMongoCollection 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 GetMappings() { return new[] { - new MongoEntityMapping(typeof(Person), "People") + new MongoEntityMapping(typeof(Person), "People"), + new MongoEntityMapping(typeof(City), "Cities") }; } } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/City.cs new file mode 100644 index 0000000000..76361463d7 --- /dev/null +++ b/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 + { + public string Name { get; set; } + + private City() + { + + } + + public City(Guid id, string name) + : base(id) + { + Name = name; + } + } +} diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs new file mode 100644 index 0000000000..c0c2596aa8 --- /dev/null +++ b/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 + { + [CanBeNull] + Task FindByNameAsync(string name); + } +} diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs index dae58441b8..cb907e6fcf 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs +++ b/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 _personRepository; + private readonly ICityRepository _cityRepository; - public TestDataBuilder(IBasicRepository personRepository) + public TestDataBuilder( + IBasicRepository 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);