From 32d60e87fdc92cc7d0b4f65ae7f631bc60d81881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Tue, 27 Mar 2018 13:51:59 +0300 Subject: [PATCH] Added test for repositories --- .../Repositories/Repository_Tests.cs | 12 ++++++++++++ .../TestApp/EntityFrameworkCore/CityRepository.cs | 8 ++++++++ .../Volo/Abp/TestApp/MongoDb/CityRepository.cs | 10 ++++++++++ .../Volo/Abp/TestApp/Domain/ICityRepository.cs | 3 +++ .../Volo/Abp/TestApp/Domain/Person.cs | 5 ++++- .../Volo/Abp/TestApp/TestDataBuilder.cs | 13 ++++++++----- 6 files changed, 45 insertions(+), 6 deletions(-) diff --git a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs index f0ef9066f2..1931a7b82d 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/Repository_Tests.cs @@ -10,17 +10,22 @@ using Xunit; namespace Volo.Abp.EntityFrameworkCore.Repositories { + //TODO: Remove WithUnitOfWork + //TODO: Share same abstract base class for repository tests (with mongodb and others) + public class Repository_Tests : EntityFrameworkCoreTestBase { private readonly IRepository _personRepository; private readonly IRepository _bookRepository; private readonly IRepository _phoneInSecondDbContextRepository; + private readonly ICityRepository _cityRepository; public Repository_Tests() { _personRepository = ServiceProvider.GetRequiredService>(); _bookRepository = ServiceProvider.GetRequiredService>(); _phoneInSecondDbContextRepository = ServiceProvider.GetRequiredService>(); + _cityRepository = GetRequiredService(); } [Fact] @@ -50,6 +55,13 @@ namespace Volo.Abp.EntityFrameworkCore.Repositories }); } + [Fact] + public async Task GetPeopleInTheCityAsync() + { + var people = await _cityRepository.GetPeopleInTheCityAsync("London"); + people.Count.ShouldBeGreaterThan(0); + } + [Fact] public async Task InsertAsync() { 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 index 09373153c5..027f54a03a 100644 --- a/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs +++ b/test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/TestApp/EntityFrameworkCore/CityRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; @@ -18,5 +20,11 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore { return await this.FirstOrDefaultAsync(c => c.Name == name); } + + public async Task> GetPeopleInTheCityAsync(string cityName) + { + var city = await FindByNameAsync(cityName); + return await DbContext.People.Where(p => p.CityId == city.Id).ToListAsync(); + } } } 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 index 0d212dc4b7..f9bdbec39a 100644 --- a/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs +++ b/test/Volo.Abp.MongoDB.Tests/Volo/Abp/TestApp/MongoDb/CityRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using MongoDB.Driver; using Volo.Abp.Domain.Repositories.MongoDB; @@ -19,5 +20,14 @@ namespace Volo.Abp.TestApp.MongoDb { return await (await Collection.FindAsync(c => c.Name == name)).FirstOrDefaultAsync(); } + + public async Task> GetPeopleInTheCityAsync(string cityName) + { + var city = await FindByNameAsync(cityName); + + throw new NotImplementedException(); + + //return await DbContext.People.Where(p => p.CityId == city.Id).ToListAsync(); + } } } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs index 8c3387424f..1c9d923d4c 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/ICityRepository.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; @@ -7,5 +8,7 @@ namespace Volo.Abp.TestApp.Domain public interface ICityRepository : IBasicRepository { Task FindByNameAsync(string name); + + Task> GetPeopleInTheCityAsync(string cityName); } } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs index 69b4abb35a..d9c28f766a 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/Domain/Person.cs @@ -9,6 +9,8 @@ namespace Volo.Abp.TestApp.Domain { public virtual Guid? TenantId { get; set; } + public virtual Guid? CityId { get; set; } + public virtual string Name { get; private set; } public virtual int Age { get; set; } @@ -22,12 +24,13 @@ namespace Volo.Abp.TestApp.Domain } - public Person(Guid id, string name, int age, Guid? tenantId = null) + public Person(Guid id, string name, int age, Guid? tenantId = null, Guid? cityId = null) { Id = id; Name = name; Age = age; TenantId = tenantId; + CityId = cityId; Phones = new Collection(); } diff --git a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs index ca9cc5761d..f1bb42a344 100644 --- a/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs +++ b/test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestDataBuilder.cs @@ -9,8 +9,11 @@ namespace Volo.Abp.TestApp { public static Guid TenantId1 { get; } = new Guid("55687dce-595c-41b4-a024-2a5e991ac8f4"); public static Guid TenantId2 { get; } = new Guid("f522d19f-5a86-4278-98fb-0577319c544a"); - public static Guid UserDouglasId { get; } = Guid.NewGuid(); - public static Guid UserJohnDeletedId { get; } = Guid.NewGuid(); + public static Guid UserDouglasId { get; } = new Guid("1fcf46b2-28c3-48d0-8bac-fa53268a2775"); + public static Guid UserJohnDeletedId { get; } = new Guid("1e28ca9f-df84-4f39-83fe-f5450ecbf5d4"); + + public static Guid IstanbulCityId { get; } = new Guid("4d734a0e-3e6b-4bad-bb43-ef8cf1b09633"); + public static Guid LondonCityId { get; } = new Guid("27237527-605e-4652-a2a5-68e0e512da36"); private readonly IBasicRepository _personRepository; private readonly ICityRepository _cityRepository; @@ -33,8 +36,8 @@ namespace Volo.Abp.TestApp { _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(LondonCityId, "London")); + _cityRepository.Insert(new City(IstanbulCityId, "Istanbul")); _cityRepository.Insert(new City(Guid.NewGuid(), "Paris")); _cityRepository.Insert(new City(Guid.NewGuid(), "Washington")); _cityRepository.Insert(new City(Guid.NewGuid(), "Sao Paulo")); @@ -46,7 +49,7 @@ namespace Volo.Abp.TestApp private void AddPeople() { - var douglas = new Person(UserDouglasId, "Douglas", 42); + var douglas = new Person(UserDouglasId, "Douglas", 42, cityId: LondonCityId); douglas.Phones.Add(new Phone(douglas.Id, "123456789")); douglas.Phones.Add(new Phone(douglas.Id, "123456780", PhoneType.Home));