From 7e4f1f3439fa5154d033b33c440c302ad750d60e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Fri, 20 Sep 2019 10:14:40 +0300 Subject: [PATCH] Added test: Repository_Basic_Tests_With_Int_Pk --- .../Repository_Basic_Tests_With_Int_Pk.cs | 9 ++++ .../TestMigrationsDbContext.cs | 2 + .../EntityFrameworkCore/TestAppDbContext.cs | 2 + .../Repository_Basic_Tests_With_Int_Pk.cs | 9 ++++ .../MemoryDb/TestAppMemoryDbContext.cs | 3 +- .../Repository_Basic_Tests_With_Int_Pk.cs | 9 ++++ .../TestApp/MongoDb/TestAppMongoDbContext.cs | 4 +- .../Abp/TestApp/Domain/EntityWithIntPk.cs | 22 ++++++++++ .../Volo/Abp/TestApp/TestDataBuilder.cs | 11 ++++- .../Repository_Basic_Tests_With_Int_Pk.cs | 42 +++++++++++++++++++ 10 files changed, 110 insertions(+), 3 deletions(-) create mode 100644 framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests_With_Int_Pk.cs create mode 100644 framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/Repository_Basic_Tests_With_Int_Pk.cs create mode 100644 framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs create mode 100644 framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/EntityWithIntPk.cs create mode 100644 framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests_With_Int_Pk.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests_With_Int_Pk.cs new file mode 100644 index 0000000000..44cf993be8 --- /dev/null +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Basic_Tests_With_Int_Pk.cs @@ -0,0 +1,9 @@ +using Volo.Abp.TestApp.Testing; + +namespace Volo.Abp.EntityFrameworkCore.Repositories +{ + public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk + { + + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs index cb9726d6b4..0f9def32f0 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/TestMigrationsDbContext.cs @@ -15,6 +15,8 @@ namespace Volo.Abp.EntityFrameworkCore public DbSet Books { get; set; } + public DbSet EntityWithIntPks { get; set; } + public TestMigrationsDbContext(DbContextOptions options) : base(options) { diff --git a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs index 00e052d2dd..bfcecdeb65 100644 --- a/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs +++ b/framework/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/TestAppDbContext.cs @@ -13,6 +13,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore public DbSet DummyEntities { get; set; } + public DbSet EntityWithIntPks { get; set; } + public TestAppDbContext(DbContextOptions options) : base(options) { diff --git a/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/Repository_Basic_Tests_With_Int_Pk.cs b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/Repository_Basic_Tests_With_Int_Pk.cs new file mode 100644 index 0000000000..31cd74043d --- /dev/null +++ b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/Repositories/Repository_Basic_Tests_With_Int_Pk.cs @@ -0,0 +1,9 @@ +using Volo.Abp.TestApp.Testing; + +namespace Volo.Abp.MemoryDb.Repositories +{ + public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk + { + + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/TestAppMemoryDbContext.cs b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/TestAppMemoryDbContext.cs index 902c013ed8..09b134a078 100644 --- a/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/TestAppMemoryDbContext.cs +++ b/framework/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/TestAppMemoryDbContext.cs @@ -8,7 +8,8 @@ namespace Volo.Abp.TestApp.MemoryDb public class TestAppMemoryDbContext : MemoryDbContext { private static readonly Type[] EntityTypeList = { - typeof(Person) + typeof(Person), + typeof(EntityWithIntPk) }; public override IReadOnlyList GetEntityTypes() diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs new file mode 100644 index 0000000000..e300f4740d --- /dev/null +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/Repositories/Repository_Basic_Tests_With_Int_Pk.cs @@ -0,0 +1,9 @@ +using Volo.Abp.TestApp.Testing; + +namespace Volo.Abp.MongoDB.Repositories +{ + public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk + { + + } +} \ No newline at end of file diff --git a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs index fd7562f6df..03869ce566 100644 --- a/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs +++ b/framework/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/TestAppMongoDbContext.cs @@ -8,9 +8,11 @@ namespace Volo.Abp.TestApp.MongoDB [ConnectionStringName("TestApp")] public class TestAppMongoDbContext : AbpMongoDbContext, ITestAppMongoDbContext { - [MongoCollection("Persons")] //Intentially changed the collection name to test it + [MongoCollection("Persons")] //Intentionally changed the collection name to test it public IMongoCollection People => Collection(); + public IMongoCollection EntityWithIntPks => Collection(); + public IMongoCollection Cities => Collection(); protected override void CreateModel(IMongoModelBuilder modelBuilder) diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/EntityWithIntPk.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/EntityWithIntPk.cs new file mode 100644 index 0000000000..040af1a4e9 --- /dev/null +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/EntityWithIntPk.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Volo.Abp.Domain.Entities; + +namespace Volo.Abp.TestApp.Domain +{ + public class EntityWithIntPk : AggregateRoot + { + public string Name { get; set; } + + public EntityWithIntPk() + { + + } + + public EntityWithIntPk(string name) + { + Name = name; + } + } +} diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs index 25886f77a6..1f955b3e82 100644 --- a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs @@ -17,19 +17,23 @@ namespace Volo.Abp.TestApp private readonly IBasicRepository _personRepository; private readonly ICityRepository _cityRepository; + private readonly IRepository _entityWithIntPksRepository; public TestDataBuilder( IBasicRepository personRepository, - ICityRepository cityRepository) + ICityRepository cityRepository, + IRepository entityWithIntPksRepository) { _personRepository = personRepository; _cityRepository = cityRepository; + _entityWithIntPksRepository = entityWithIntPksRepository; } public void Build() { AddCities(); AddPeople(); + AddEntitiesWithPks(); } private void AddCities() @@ -63,5 +67,10 @@ namespace Volo.Abp.TestApp _personRepository.Insert(tenant1Person1); _personRepository.Insert(tenant1Person2); } + + private void AddEntitiesWithPks() + { + _entityWithIntPksRepository.Insert(new EntityWithIntPk("Entity1")); + } } } \ No newline at end of file diff --git a/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs new file mode 100644 index 0000000000..026b958e60 --- /dev/null +++ b/framework/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests_With_Int_Pk.cs @@ -0,0 +1,42 @@ +using System.Linq; +using Shouldly; +using Volo.Abp.Domain.Repositories; +using Volo.Abp.Modularity; +using Volo.Abp.TestApp.Domain; +using Xunit; + +namespace Volo.Abp.TestApp.Testing +{ + public abstract class Repository_Basic_Tests_With_Int_Pk : TestAppTestBase + where TStartupModule : IAbpModule + { + protected readonly IRepository EntityWithIntPkRepository; + + protected Repository_Basic_Tests_With_Int_Pk() + { + EntityWithIntPkRepository = GetRequiredService>(); + } + + [Fact] + public void FirstOrDefault() + { + WithUnitOfWork(() => + { + var entity = EntityWithIntPkRepository.FirstOrDefault(e => e.Name == "Entity1"); + entity.ShouldNotBeNull(); + entity.Name.ShouldBe("Entity1"); + }); + } + + [Fact] + public void Get() + { + WithUnitOfWork(() => + { + var entity = EntityWithIntPkRepository.Get(1); + entity.ShouldNotBeNull(); + entity.Name.ShouldBe("Entity1"); + }); + } + } +}