From cb96d3df4ae3020fe7afcbd0401e0e05b2941bc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 27 Mar 2018 15:47:10 +0300 Subject: [PATCH] Implemented CityRepository for memorydb. --- .../Abp/Domain/Repositories/IRepository.cs | 1 - .../MemoryDb/MemoryDbRepository.cs | 2 ++ .../Abp/MemoryDb/AbpMemoryDbTestModule.cs | 9 ++++-- .../Abp/TestApp/MemoryDb/CityRepository.cs | 30 +++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/CityRepository.cs diff --git a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs index 61e4e84688..a64d7fa2e0 100644 --- a/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs +++ b/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Repositories/IRepository.cs @@ -1,5 +1,4 @@ using System; -using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; diff --git a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs index 171e574f87..0ca1f7d2b6 100644 --- a/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs +++ b/src/Volo.Abp.MemoryDb/Volo/Abp/Domain/Repositories/MemoryDb/MemoryDbRepository.cs @@ -12,6 +12,8 @@ namespace Volo.Abp.Domain.Repositories.MemoryDb where TMemoryDbContext : MemoryDbContext where TEntity : class, IEntity { + //TODO: Add dbcontext just like mongodb implementation! + public virtual List Collection => Database.Collection(); public virtual IMemoryDatabase Database => DatabaseProvider.GetDatabase(); diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/AbpMemoryDbTestModule.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/AbpMemoryDbTestModule.cs index 86708d55ef..980cf1eecb 100644 --- a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/AbpMemoryDbTestModule.cs +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/MemoryDb/AbpMemoryDbTestModule.cs @@ -5,10 +5,14 @@ using Volo.Abp.TestApp.MemoryDb; using Volo.Abp.Data; using Volo.Abp.Autofac; using Volo.Abp.TestApp; +using Volo.Abp.TestApp.Domain; namespace Volo.Abp.MemoryDb { - [DependsOn(typeof(TestAppModule), typeof(AbpMemoryDbModule), typeof(AbpAutofacModule))] + [DependsOn( + typeof(TestAppModule), + typeof(AbpMemoryDbModule), + typeof(AbpAutofacModule))] public class AbpMemoryDbTestModule : AbpModule { public override void ConfigureServices(IServiceCollection services) @@ -23,9 +27,10 @@ namespace Volo.Abp.MemoryDb services.AddMemoryDbContext(options => { options.AddDefaultRepositories(); + options.AddRepository(); }); - services.AddAssemblyOf(); + services.AddAssemblyOf(); } } } diff --git a/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/CityRepository.cs b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/CityRepository.cs new file mode 100644 index 0000000000..b6d43dc875 --- /dev/null +++ b/test/Volo.Abp.MemoryDb.Tests/Volo/Abp/TestApp/MemoryDb/CityRepository.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Volo.Abp.Domain.Repositories.MemoryDb; +using Volo.Abp.MemoryDb; +using Volo.Abp.TestApp.Domain; + +namespace Volo.Abp.TestApp.MemoryDb +{ + public class CityRepository : MemoryDbRepository, ICityRepository + { + public CityRepository(IMemoryDatabaseProvider databaseProvider) + : base(databaseProvider) + { + } + + public Task FindByNameAsync(string name) + { + return Task.FromResult(Collection.FirstOrDefault(c => c.Name == name)); + } + + public async Task> GetPeopleInTheCityAsync(string cityName) + { + var city = await FindByNameAsync(cityName); + + return Database.Collection().Where(p => p.CityId == city.Id).ToList(); + } + } +}