From 53b81bf4105d86dba8fb5b221c897f3cf5ab36b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 27 Mar 2018 14:54:07 +0300 Subject: [PATCH] Move common test code to Repository_Basic_Tests. --- .../EfCore_Repository_Basic_Tests.cs | 8 ++ .../Volo/Abp/MongoDB/AbpMongoDbTestModule.cs | 3 - .../MongoDB/MongoDb_Repository_Basic_Tests.cs | 62 +++++++++++ .../Abp/MongoDB/MongoDb_Repository_Tests.cs | 101 ------------------ test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj | 3 + .../Volo/Abp/TestApp/TestAppModule.cs | 9 +- .../Abp/TestApp/Testing/MongoDbTestBase.cs | 13 +++ .../TestApp/Testing/Repository_Basic_Tests.cs | 54 ++++++++++ 8 files changed, 147 insertions(+), 106 deletions(-) create mode 100644 test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/EfCore_Repository_Basic_Tests.cs create mode 100644 test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Basic_Tests.cs delete mode 100644 test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs create mode 100644 test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MongoDbTestBase.cs create mode 100644 test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests.cs diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/EfCore_Repository_Basic_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/EfCore_Repository_Basic_Tests.cs new file mode 100644 index 0000000000..5a469ba8e1 --- /dev/null +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/EfCore_Repository_Basic_Tests.cs @@ -0,0 +1,8 @@ +using Volo.Abp.TestApp.Testing; + +namespace Volo.Abp.EntityFrameworkCore.Repositories +{ + public class EfCore_Repository_Basic_Tests : Repository_Basic_Tests + { + } +} 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 b5d38552fe..7f8425a9df 100644 --- a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs +++ b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs @@ -1,6 +1,5 @@ using Microsoft.Extensions.DependencyInjection; using Mongo2Go; -using Volo.Abp.Autofac; using Volo.Abp.Data; using Volo.Abp.Modularity; using Volo.Abp.TestApp; @@ -10,9 +9,7 @@ using Volo.Abp.TestApp.MongoDb; namespace Volo.Abp.MongoDB { [DependsOn( - typeof(AbpAutofacModule), typeof(AbpMongoDbModule), - typeof(AbpTestBaseModule), typeof(TestAppModule) )] public class AbpMongoDbTestModule : AbpModule diff --git a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Basic_Tests.cs b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Basic_Tests.cs new file mode 100644 index 0000000000..5d8d48d388 --- /dev/null +++ b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Basic_Tests.cs @@ -0,0 +1,62 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.TestApp; +using Volo.Abp.TestApp.Domain; +using Volo.Abp.TestApp.Testing; +using Xunit; + +namespace Volo.Abp.MongoDB +{ + public class MongoDb_Repository_Basic_Tests : Repository_Basic_Tests + { + [Fact] + public async Task GetAsync() + { + var person = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); + person.Name.ShouldBe("Douglas"); + person.Phones.Count.ShouldBe(2); + } + + [Fact] + public void Linq_Queries() + { + PersonRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull(); + + PersonRepository.Count().ShouldBeGreaterThan(0); + } + + [Fact] + public async Task UpdateAsync() + { + var person = await PersonRepository.GetAsync(TestDataBuilder.UserDouglasId); + + person.ChangeName("Douglas-Updated"); + person.Phones.Add(new Phone(person.Id, "6667778899", PhoneType.Office)); + + await PersonRepository.UpdateAsync(person); + + person = await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId); + person.ShouldNotBeNull(); + person.Name.ShouldBe("Douglas-Updated"); + person.Phones.Count.ShouldBe(3); + person.Phones.Any(p => p.PersonId == person.Id && p.Number == "6667778899" && p.Type == PhoneType.Office).ShouldBeTrue(); + } + + [Fact] + public async Task InsertAsync() + { + var person = new Person(Guid.NewGuid(), "New Person", 35); + person.Phones.Add(new Phone(person.Id, "1234567890")); + + await PersonRepository.InsertAsync(person); + + person = await PersonRepository.FindAsync(person.Id); + person.ShouldNotBeNull(); + person.Name.ShouldBe("New Person"); + person.Phones.Count.ShouldBe(1); + person.Phones.Any(p => p.PersonId == person.Id && p.Number == "1234567890").ShouldBeTrue(); + } + } +} diff --git a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs deleted file mode 100644 index 56127cc42f..0000000000 --- a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using Shouldly; -using Volo.Abp.Domain.Repositories; -using Volo.Abp.TestApp; -using Volo.Abp.TestApp.Domain; -using Xunit; - -namespace Volo.Abp.MongoDB -{ - public class MongoDb_Repository_Tests : MongoDbTestBase - { - private readonly IRepository _personRepository; - private readonly ICityRepository _cityRepository; - - public MongoDb_Repository_Tests() - { - _personRepository = GetRequiredService>(); - _cityRepository = GetRequiredService(); - } - - [Fact] - public async Task GetAsync() - { - var person = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId); - person.Name.ShouldBe("Douglas"); - person.Phones.Count.ShouldBe(2); - } - - [Fact] - public async Task FindAsync_Should_Return_Null_For_Not_Found_Entity() - { - var person = await _personRepository.FindAsync(Guid.NewGuid()); - person.ShouldBeNull(); - } - - [Fact] - public void Linq_Queries() - { - _personRepository.FirstOrDefault(p => p.Name == "Douglas").ShouldNotBeNull(); - - _personRepository.Count().ShouldBeGreaterThan(0); - } - - [Fact] - public async Task DeleteAsync() - { - await _personRepository.DeleteAsync(TestDataBuilder.UserDouglasId); - - (await _personRepository.FindAsync(TestDataBuilder.UserDouglasId)).ShouldBeNull(); - } - - [Fact] - public async Task UpdateAsync() - { - var person = await _personRepository.GetAsync(TestDataBuilder.UserDouglasId); - - person.ChangeName("Douglas-Updated"); - person.Phones.Add(new Phone(person.Id, "6667778899", PhoneType.Office)); - - await _personRepository.UpdateAsync(person); - - person = await _personRepository.FindAsync(TestDataBuilder.UserDouglasId); - person.ShouldNotBeNull(); - person.Name.ShouldBe("Douglas-Updated"); - person.Phones.Count.ShouldBe(3); - person.Phones.Any(p => p.PersonId == person.Id && p.Number == "6667778899" && p.Type == PhoneType.Office).ShouldBeTrue(); - } - - [Fact] - public async Task InsertAsync() - { - var person = new Person(Guid.NewGuid(), "New Person", 35); - person.Phones.Add(new Phone(person.Id, "1234567890")); - - await _personRepository.InsertAsync(person); - - person = await _personRepository.FindAsync(person.Id); - person.ShouldNotBeNull(); - person.Name.ShouldBe("New Person"); - person.Phones.Count.ShouldBe(1); - person.Phones.Any(p => p.PersonId == person.Id && p.Number == "1234567890").ShouldBeTrue(); - } - - [Fact] - public async Task Custom_Repository_Method() - { - var city = await _cityRepository.FindByNameAsync("Istanbul"); - city.ShouldNotBeNull(); - city.Name.ShouldBe("Istanbul"); - } - - [Fact] - public async Task Should_Access_To_Other_Collections_In_Same_Context_In_A_Custom_Method() - { - var people = await _cityRepository.GetPeopleInTheCityAsync("London"); - people.Count.ShouldBeGreaterThan(0); - } - } -} diff --git a/test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj b/test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj index 49ab464f51..738cb025c2 100644 --- a/test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj +++ b/test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj @@ -12,8 +12,11 @@ + + + diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs index 2ae07e2519..2720696492 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Volo.Abp.Application; +using Volo.Abp.Autofac; using Volo.Abp.Modularity; using Volo.Abp.TestApp.Domain; using Volo.Abp.AutoMapper; @@ -7,8 +8,12 @@ using Volo.Abp.TestApp.Application.Dto; namespace Volo.Abp.TestApp { - [DependsOn(typeof(AbpAutoMapperModule))] - [DependsOn(typeof(AbpDddApplicationModule))] + [DependsOn( + typeof(AbpDddApplicationModule), + typeof(AbpAutofacModule), + typeof(AbpTestBaseModule), + typeof(AbpAutoMapperModule) + )] public class TestAppModule : AbpModule { public override void ConfigureServices(IServiceCollection services) diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MongoDbTestBase.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MongoDbTestBase.cs new file mode 100644 index 0000000000..3f4a2b4360 --- /dev/null +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MongoDbTestBase.cs @@ -0,0 +1,13 @@ +using Volo.Abp.Modularity; + +namespace Volo.Abp.TestApp.Testing +{ + public abstract class TestAppTestBase : AbpIntegratedTest + where TStartupModule : IAbpModule + { + protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) + { + options.UseAutofac(); + } + } +} \ No newline at end of file diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests.cs new file mode 100644 index 0000000000..c7d6f33202 --- /dev/null +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests.cs @@ -0,0 +1,54 @@ +using System; +using System.Threading.Tasks; +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 : TestAppTestBase + where TStartupModule : IAbpModule + { + protected readonly IRepository PersonRepository; + protected readonly ICityRepository CityRepository; + + protected Repository_Basic_Tests() + { + PersonRepository = GetRequiredService>(); + CityRepository = GetRequiredService(); + } + + + [Fact] + public async Task FindAsync_Should_Return_Null_For_Not_Found_Entity() + { + var person = await PersonRepository.FindAsync(Guid.NewGuid()); + person.ShouldBeNull(); + } + + [Fact] + public async Task DeleteAsync() + { + await PersonRepository.DeleteAsync(TestDataBuilder.UserDouglasId); + + (await PersonRepository.FindAsync(TestDataBuilder.UserDouglasId)).ShouldBeNull(); + } + + [Fact] + public async Task Should_Access_To_Other_Collections_In_Same_Context_In_A_Custom_Method() + { + var people = await CityRepository.GetPeopleInTheCityAsync("London"); + people.Count.ShouldBeGreaterThan(0); + } + + [Fact] + public async Task Custom_Repository_Method() + { + var city = await CityRepository.FindByNameAsync("Istanbul"); + city.ShouldNotBeNull(); + city.Name.ShouldBe("Istanbul"); + } + } +}