Browse Source

Move common test code to Repository_Basic_Tests.

pull/272/head
Halil İbrahim Kalkan 9 years ago
parent
commit
53b81bf410
  1. 8
      test/Volo.Abp.EntityFrameworkCore.Tests/Volo/Abp/EntityFrameworkCore/Repositories/EfCore_Repository_Basic_Tests.cs
  2. 3
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/AbpMongoDbTestModule.cs
  3. 62
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Basic_Tests.cs
  4. 101
      test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs
  5. 3
      test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj
  6. 9
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/TestAppModule.cs
  7. 13
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/MongoDbTestBase.cs
  8. 54
      test/Volo.Abp.TestApp/Volo/Abp/TestApp/Testing/Repository_Basic_Tests.cs

8
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<AbpEntityFrameworkCoreTestModule>
{
}
}

3
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

62
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<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();
}
}
}

101
test/Volo.Abp.MongoDB.Tests/Volo/Abp/MongoDB/MongoDb_Repository_Tests.cs

@ -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);
}
}
}

3
test/Volo.Abp.TestApp/Volo.Abp.TestApp.csproj

@ -12,8 +12,11 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.AutoMapper\Volo.Abp.AutoMapper.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.Ddd.Application\Volo.Abp.Ddd.Application.csproj" />
<ProjectReference Include="..\..\src\Volo.Abp.TestBase\Volo.Abp.TestBase.csproj" />
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" />
</ItemGroup>
</Project>

9
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)

13
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<TStartupModule> : AbpIntegratedTest<TStartupModule>
where TStartupModule : IAbpModule
{
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options)
{
options.UseAutofac();
}
}
}

54
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<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…
Cancel
Save