mirror of https://github.com/abpframework/abp.git
10 changed files with 154 additions and 9 deletions
@ -0,0 +1,26 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netcoreapp2.0</TargetFramework> |
|||
<AssemblyName>Volo.Abp.MongoDB.Tests</AssemblyName> |
|||
<PackageId>Volo.Abp.MongoDB.Tests</PackageId> |
|||
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> |
|||
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
|||
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
|||
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
|||
<RootNamespace /> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" /> |
|||
<ProjectReference Include="..\..\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\AbpTestBase\AbpTestBase.csproj" /> |
|||
<ProjectReference Include="..\Volo.Abp.TestApp\Volo.Abp.TestApp.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" /> |
|||
<PackageReference Include="Mongo2Go" Version="2.2.1" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,43 @@ |
|||
using Microsoft.Extensions.DependencyInjection; |
|||
using Mongo2Go; |
|||
using Volo.Abp.Autofac; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.TestApp; |
|||
using Volo.Abp.TestApp.MongoDb; |
|||
|
|||
namespace Volo.Abp.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(AbpAutofacModule), |
|||
typeof(AbpMongoDbModule), |
|||
typeof(AbpTestBaseModule), |
|||
typeof(TestAppModule) |
|||
)] |
|||
public class AbpMongoDbTestModule : AbpModule |
|||
{ |
|||
private MongoDbRunner _mongoDbRunner; |
|||
|
|||
public override void ConfigureServices(IServiceCollection services) |
|||
{ |
|||
_mongoDbRunner = MongoDbRunner.Start(); |
|||
|
|||
services.Configure<DbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = _mongoDbRunner.ConnectionString; |
|||
}); |
|||
|
|||
services.AddMongoDbContext<TestAppMongoDbContext>(options => |
|||
{ |
|||
options.AddDefaultRepositories<ITestAppMongoDbContext>(); |
|||
}); |
|||
|
|||
services.AddAssemblyOf<AbpMongoDbTestModule>(); |
|||
} |
|||
|
|||
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|||
{ |
|||
_mongoDbRunner.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace Volo.Abp.MongoDB |
|||
{ |
|||
public abstract class MongoDbTestBase : AbpIntegratedTest<AbpMongoDbTestModule> |
|||
{ |
|||
protected override void SetAbpApplicationCreationOptions(AbpApplicationCreationOptions options) |
|||
{ |
|||
options.UseAutofac(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
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; |
|||
|
|||
public MongoDb_Repository_Tests() |
|||
{ |
|||
_personRepository = GetRequiredService<IRepository<Person, Guid>>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task GetAsync() |
|||
{ |
|||
(await _personRepository.GetAsync(TestDataBuilder.UserDouglasId)).ShouldNotBeNull(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
|
|||
namespace Volo.Abp.TestApp.MongoDb |
|||
{ |
|||
[ConnectionStringName("TestApp")] |
|||
public interface ITestAppMongoDbContext : IAbpMongoDbContext |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
using System.Collections.Generic; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.MongoDB; |
|||
using Volo.Abp.TestApp.Domain; |
|||
|
|||
namespace Volo.Abp.TestApp.MongoDb |
|||
{ |
|||
[ConnectionStringName("TestApp")] |
|||
public class TestAppMongoDbContext : AbpMongoDbContext, ITestAppMongoDbContext |
|||
{ |
|||
public override IReadOnlyList<MongoEntityMapping> GetMappings() |
|||
{ |
|||
return new[] |
|||
{ |
|||
new MongoEntityMapping(typeof(Person), "People") |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue