mirror of https://github.com/abpframework/abp.git
8 changed files with 147 additions and 106 deletions
@ -0,0 +1,8 @@ |
|||
using Volo.Abp.TestApp.Testing; |
|||
|
|||
namespace Volo.Abp.EntityFrameworkCore.Repositories |
|||
{ |
|||
public class EfCore_Repository_Basic_Tests : Repository_Basic_Tests<AbpEntityFrameworkCoreTestModule> |
|||
{ |
|||
} |
|||
} |
|||
@ -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<AbpMongoDbTestModule> |
|||
{ |
|||
[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(); |
|||
} |
|||
} |
|||
} |
|||
@ -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<Person, Guid> _personRepository; |
|||
private readonly ICityRepository _cityRepository; |
|||
|
|||
public MongoDb_Repository_Tests() |
|||
{ |
|||
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|||
_cityRepository = GetRequiredService<ICityRepository>(); |
|||
} |
|||
|
|||
[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); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,13 @@ |
|||
using Volo.Abp.Modularity; |
|||
|
|||
namespace Volo.Abp.TestApp.Testing |
|||
{ |
|||
public abstract class TestAppTestBase<TStartupModule> : AbpIntegratedTest<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
} |
|||
@ -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<TStartupModule> : TestAppTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
protected readonly IRepository<Person, Guid> PersonRepository; |
|||
protected readonly ICityRepository CityRepository; |
|||
|
|||
protected Repository_Basic_Tests() |
|||
{ |
|||
PersonRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|||
CityRepository = GetRequiredService<ICityRepository>(); |
|||
} |
|||
|
|||
|
|||
[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"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue