mirror of https://github.com/abpframework/abp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
851 B
35 lines
851 B
using System;
|
|
using EphemeralMongo;
|
|
|
|
namespace Volo.Abp.BackgroundJobs.MongoDB;
|
|
|
|
public class MongoDbFixture : IDisposable
|
|
{
|
|
public readonly static IMongoRunner MongoDbRunner;
|
|
|
|
static MongoDbFixture()
|
|
{
|
|
MongoDbRunner = MongoRunner.Run(new MongoRunnerOptions
|
|
{
|
|
UseSingleNodeReplicaSet = true
|
|
});
|
|
}
|
|
|
|
public static string GetRandomConnectionString()
|
|
{
|
|
return GetConnectionString("Db_" + Guid.NewGuid().ToString("N"));
|
|
}
|
|
|
|
public static string GetConnectionString(string databaseName)
|
|
{
|
|
var stringArray = MongoDbRunner.ConnectionString.Split('?');
|
|
var connectionString = stringArray[0].EnsureEndsWith('/') + databaseName + "/?" + stringArray[1];
|
|
return connectionString;
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
MongoDbRunner?.Dispose();
|
|
}
|
|
}
|