forked from tsai/eShopOnAbp
10 changed files with 112 additions and 3 deletions
@ -0,0 +1,10 @@ |
|||
using EShopOnAbp.CatalogService.MongoDB; |
|||
using Xunit; |
|||
|
|||
namespace EShopOnAbp.CatalogService; |
|||
|
|||
[CollectionDefinition(CatalogServiceTestConsts.CollectionDefinitionName)] |
|||
public class CatalogServiceDomainCollection : CatalogServiceMongoDbCollectionFixtureBase |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,17 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<Import Project="..\..\common.props" /> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>net6.0</TargetFramework> |
|||
<RootNamespace>EShopOnAbp.CatalogService</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" /> |
|||
<PackageReference Include="Mongo2Go" Version="3.1.3" /> |
|||
<ProjectReference Include="..\..\src\EShopOnAbp.CatalogService.MongoDB\EShopOnAbp.CatalogService.MongoDB.csproj" /> |
|||
<ProjectReference Include="..\EShopOnAbp.CatalogService.TestBase\EShopOnAbp.CatalogService.TestBase.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace EShopOnAbp.CatalogService.MongoDB; |
|||
|
|||
[CollectionDefinition(CatalogServiceTestConsts.CollectionDefinitionName)] |
|||
public class CatalogServiceMongoCollection : CatalogServiceMongoDbCollectionFixtureBase |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using Xunit; |
|||
|
|||
namespace EShopOnAbp.CatalogService.MongoDB; |
|||
|
|||
public class CatalogServiceMongoDbCollectionFixtureBase : ICollectionFixture<CatalogServiceMongoDbFixture> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
using System; |
|||
using Mongo2Go; |
|||
|
|||
namespace EShopOnAbp.CatalogService.MongoDB |
|||
{ |
|||
public class CatalogServiceMongoDbFixture : IDisposable |
|||
{ |
|||
private static readonly MongoDbRunner MongoDbRunner; |
|||
public static readonly string ConnectionString; |
|||
|
|||
static CatalogServiceMongoDbFixture() |
|||
{ |
|||
MongoDbRunner = MongoDbRunner.Start(singleNodeReplSet: true, singleNodeReplSetWaitTimeout: 20); |
|||
ConnectionString = MongoDbRunner.ConnectionString; |
|||
} |
|||
|
|||
public void Dispose() |
|||
{ |
|||
MongoDbRunner?.Dispose(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,10 @@ |
|||
namespace EShopOnAbp.CatalogService.MongoDB |
|||
{ |
|||
/* This class can be used as a base class for MongoDB integration tests, |
|||
* while SampleRepository_Tests uses a different approach. |
|||
*/ |
|||
public abstract class CatalogServiceMongoDbTestBase : CatalogServiceTestBase<CatalogServiceMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
using System; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.Modularity; |
|||
using Volo.Abp.Uow; |
|||
|
|||
namespace EShopOnAbp.CatalogService.MongoDB |
|||
{ |
|||
[DependsOn( |
|||
typeof(CatalogServiceTestBaseModule), |
|||
typeof(CatalogServiceMongoDbModule) |
|||
)] |
|||
public class CatalogServiceMongoDbTestModule : AbpModule |
|||
{ |
|||
public override void ConfigureServices(ServiceConfigurationContext context) |
|||
{ |
|||
var stringArray = CatalogServiceMongoDbFixture.ConnectionString.Split('?'); |
|||
var connectionString = stringArray[0].EnsureEndsWith('/') + |
|||
"Db_" + |
|||
Guid.NewGuid().ToString("N") + "/?" + stringArray[1]; |
|||
|
|||
Configure<AbpDbConnectionOptions>(options => |
|||
{ |
|||
options.ConnectionStrings.Default = connectionString; |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace EShopOnAbp.CatalogService; |
|||
|
|||
public static class CatalogServiceTestConsts |
|||
{ |
|||
public const string CollectionDefinitionName = "CatalogService collection"; |
|||
} |
|||
Loading…
Reference in new issue