Added test: Repository_Basic_Tests_With_Int_Pk

pull/1810/head
Halil İbrahim Kalkan 5 years ago
parent 8c174210a0
commit 7e4f1f3439

@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Testing;
namespace Volo.Abp.EntityFrameworkCore.Repositories
{
public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk<AbpEntityFrameworkCoreTestModule>
{
}
}

@ -15,6 +15,8 @@ namespace Volo.Abp.EntityFrameworkCore
public DbSet<BookInSecondDbContext> Books { get; set; }
public DbSet<EntityWithIntPk> EntityWithIntPks { get; set; }
public TestMigrationsDbContext(DbContextOptions<TestMigrationsDbContext> options)
: base(options)
{

@ -13,6 +13,8 @@ namespace Volo.Abp.TestApp.EntityFrameworkCore
public DbSet<ThirdDbContextDummyEntity> DummyEntities { get; set; }
public DbSet<EntityWithIntPk> EntityWithIntPks { get; set; }
public TestAppDbContext(DbContextOptions<TestAppDbContext> options)
: base(options)
{

@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Testing;
namespace Volo.Abp.MemoryDb.Repositories
{
public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk<AbpMemoryDbTestModule>
{
}
}

@ -8,7 +8,8 @@ namespace Volo.Abp.TestApp.MemoryDb
public class TestAppMemoryDbContext : MemoryDbContext
{
private static readonly Type[] EntityTypeList = {
typeof(Person)
typeof(Person),
typeof(EntityWithIntPk)
};
public override IReadOnlyList<Type> GetEntityTypes()

@ -0,0 +1,9 @@
using Volo.Abp.TestApp.Testing;
namespace Volo.Abp.MongoDB.Repositories
{
public class Repository_Basic_Tests_With_Int_Pk : Repository_Basic_Tests_With_Int_Pk<AbpMongoDbTestModule>
{
}
}

@ -8,9 +8,11 @@ namespace Volo.Abp.TestApp.MongoDB
[ConnectionStringName("TestApp")]
public class TestAppMongoDbContext : AbpMongoDbContext, ITestAppMongoDbContext
{
[MongoCollection("Persons")] //Intentially changed the collection name to test it
[MongoCollection("Persons")] //Intentionally changed the collection name to test it
public IMongoCollection<Person> People => Collection<Person>();
public IMongoCollection<EntityWithIntPk> EntityWithIntPks => Collection<EntityWithIntPk>();
public IMongoCollection<City> Cities => Collection<City>();
protected override void CreateModel(IMongoModelBuilder modelBuilder)

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Domain.Entities;
namespace Volo.Abp.TestApp.Domain
{
public class EntityWithIntPk : AggregateRoot<int>
{
public string Name { get; set; }
public EntityWithIntPk()
{
}
public EntityWithIntPk(string name)
{
Name = name;
}
}
}

@ -17,19 +17,23 @@ namespace Volo.Abp.TestApp
private readonly IBasicRepository<Person, Guid> _personRepository;
private readonly ICityRepository _cityRepository;
private readonly IRepository<EntityWithIntPk, int> _entityWithIntPksRepository;
public TestDataBuilder(
IBasicRepository<Person, Guid> personRepository,
ICityRepository cityRepository)
ICityRepository cityRepository,
IRepository<EntityWithIntPk, int> entityWithIntPksRepository)
{
_personRepository = personRepository;
_cityRepository = cityRepository;
_entityWithIntPksRepository = entityWithIntPksRepository;
}
public void Build()
{
AddCities();
AddPeople();
AddEntitiesWithPks();
}
private void AddCities()
@ -63,5 +67,10 @@ namespace Volo.Abp.TestApp
_personRepository.Insert(tenant1Person1);
_personRepository.Insert(tenant1Person2);
}
private void AddEntitiesWithPks()
{
_entityWithIntPksRepository.Insert(new EntityWithIntPk("Entity1"));
}
}
}

@ -0,0 +1,42 @@
using System.Linq;
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_With_Int_Pk<TStartupModule> : TestAppTestBase<TStartupModule>
where TStartupModule : IAbpModule
{
protected readonly IRepository<EntityWithIntPk, int> EntityWithIntPkRepository;
protected Repository_Basic_Tests_With_Int_Pk()
{
EntityWithIntPkRepository = GetRequiredService<IRepository<EntityWithIntPk, int>>();
}
[Fact]
public void FirstOrDefault()
{
WithUnitOfWork(() =>
{
var entity = EntityWithIntPkRepository.FirstOrDefault(e => e.Name == "Entity1");
entity.ShouldNotBeNull();
entity.Name.ShouldBe("Entity1");
});
}
[Fact]
public void Get()
{
WithUnitOfWork(() =>
{
var entity = EntityWithIntPkRepository.Get(1);
entity.ShouldNotBeNull();
entity.Name.ShouldBe("Entity1");
});
}
}
}
Loading…
Cancel
Save