Skip to content

Commit

Permalink
Update mongo test case;
Browse files Browse the repository at this point in the history
  • Loading branch information
agile.zhou committed Jan 27, 2024
1 parent b62a055 commit c052747
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 34 deletions.
18 changes: 18 additions & 0 deletions test/AgileConfig.Server.ServiceTests/mongodb/AppServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using System;
using Testcontainers.MongoDb;
using AgileConfig.Server.Data.Repository.Mongodb;

namespace AgileConfig.Server.ServiceTests.mongodb
{
Expand All @@ -12,6 +13,23 @@ public class AppServiceTests_mongo : AppServiceTests
{
static MongoDbContainer _container = new MongoDbBuilder().WithImage("mongo:6.0").Build();

public override void ClearData()
{
var app_repository = new AppRepository(_container.GetConnectionString());
var apps = app_repository.AllAsync().Result;
foreach (var entity in apps)
{
app_repository.DeleteAsync(entity).Wait();
}

var appref_repository = new AppInheritancedRepository(_container.GetConnectionString());
var apprefs = appref_repository.AllAsync().Result;
foreach (var entity in apprefs)
{
appref_repository.DeleteAsync(entity).Wait();
}
}

[ClassInitialize]
public static async Task ClassInit(TestContext testContext)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SettingServiceTests_mongo : SettingServiceTests
public override void ClearData()
{
}

static MongoDbContainer _container = new MongoDbBuilder().WithImage("mongo:6.0").Build();

[ClassInitialize]
Expand Down
92 changes: 58 additions & 34 deletions test/AgileConfig.Server.ServiceTests/sqlite/ConfigServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,10 @@ public async Task GetAllConfigsAsyncTest()

var env = "DEV";
var id = Guid.NewGuid().ToString();
var appid = Guid.NewGuid().ToString();
var source = new Config
{
AppId = "001",
AppId = appid,
Id = id,
Group = "g",
Key = "k",
Expand All @@ -268,7 +269,7 @@ public async Task GetAllConfigsAsyncTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = appid,
Id = id1,
Group = "g",
Key = "k",
Expand Down Expand Up @@ -297,9 +298,12 @@ public async Task GetByAppIdKeyTest()

var env = "DEV";
var id = Guid.NewGuid().ToString();
var appid1 = Guid.NewGuid().ToString();
var appid2 = Guid.NewGuid().ToString();

var source = new Config
{
AppId = "001",
AppId = appid1,
Id = id,
Group = "g",
Key = "k",
Expand All @@ -314,7 +318,7 @@ public async Task GetByAppIdKeyTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = appid1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -329,7 +333,7 @@ public async Task GetByAppIdKeyTest()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = appid2,
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -348,10 +352,10 @@ public async Task GetByAppIdKeyTest()
var result2 = await _service.AddAsync(source2, env);
Assert.IsTrue(result2);

var config = await _service.GetByAppIdKeyEnv("001", "g", "k", env);
var config = await _service.GetByAppIdKeyEnv(appid1, "g", "k", env);
Assert.IsNotNull(config);

var config1 = await _service.GetByAppIdKeyEnv("002", "g", "k", env);
var config1 = await _service.GetByAppIdKeyEnv(appid2, "g", "k", env);
Assert.IsNull(config1);
}

Expand All @@ -361,9 +365,12 @@ public async Task GetByAppIdTest()
this.ClearData();
var id = Guid.NewGuid().ToString();
var env = "DEV";
var appid1 = Guid.NewGuid().ToString();
var appid2 = Guid.NewGuid().ToString();

var source = new Config
{
AppId = "001",
AppId = appid1,
Id = id,
Group = "g",
Key = "k",
Expand All @@ -378,7 +385,7 @@ public async Task GetByAppIdTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = appid1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -393,7 +400,7 @@ public async Task GetByAppIdTest()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = appid2,
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -412,7 +419,7 @@ public async Task GetByAppIdTest()
var result2 = await _service.AddAsync(source2, env);
Assert.IsTrue(result2);

var configs = await _service.GetByAppIdAsync("001", env);
var configs = await _service.GetByAppIdAsync(appid1, env);
Assert.IsNotNull(configs);
Assert.AreEqual(1, configs.Count);
}
Expand All @@ -423,9 +430,11 @@ public async Task SearchTest()
this.ClearData();
var env = "DEV";
var id = Guid.NewGuid().ToString();
var appid1 = Guid.NewGuid().ToString();
var appid2 = Guid.NewGuid().ToString();
var source = new Config
{
AppId = "001",
AppId = appid1,
Id = id,
Group = "group",
Key = "key",
Expand All @@ -440,7 +449,7 @@ public async Task SearchTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = appid1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -455,7 +464,7 @@ public async Task SearchTest()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = appid2,
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -474,7 +483,7 @@ public async Task SearchTest()
var result2 = await _service.AddAsync(source2, env);
Assert.IsTrue(result2);

var configs = await _service.Search("001", "", "", env);
var configs = await _service.Search(appid1, "", "", env);
Assert.IsNotNull(configs);
Assert.AreEqual(1, configs.Count);
var configs1 = await _service.Search("", "o", "", env);
Expand All @@ -492,9 +501,11 @@ public async Task CountEnabledConfigsAsyncTest()

string env = "DEV";
var id = Guid.NewGuid().ToString();
var appid = Guid.NewGuid().ToString();

var source = new Config
{
AppId = "001",
AppId = appid,
Id = id,
Group = "group",
Key = "key",
Expand All @@ -509,7 +520,7 @@ public async Task CountEnabledConfigsAsyncTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = appid,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -524,7 +535,7 @@ public async Task CountEnabledConfigsAsyncTest()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = "xxx",
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -543,8 +554,8 @@ public async Task CountEnabledConfigsAsyncTest()
var result2 = await _service.AddAsync(source2, env);
Assert.IsTrue(result2);

await _service.Publish("001", new string[] { }, "", "", env);
await _service.Publish("002", new string[] { }, "", "", env);
await _service.Publish(appid, new string[] { }, "", "", env);
await _service.Publish("xxx", new string[] { }, "", "", env);

var count = await _service.CountEnabledConfigsAsync();
Assert.AreEqual(1, count);
Expand All @@ -557,9 +568,13 @@ public async Task AppPublishedConfigsMd5Test()

string env = "DEV";
var id = Guid.NewGuid().ToString();
var app1 = Guid.NewGuid().ToString();
var app2 = Guid.NewGuid().ToString();


var source = new Config
{
AppId = "001",
AppId = app1,
Id = id,
Group = "group",
Key = "key",
Expand All @@ -574,7 +589,7 @@ public async Task AppPublishedConfigsMd5Test()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = app1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -590,7 +605,7 @@ public async Task AppPublishedConfigsMd5Test()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = app2,
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -609,7 +624,7 @@ public async Task AppPublishedConfigsMd5Test()
var result2 = await _service.AddAsync(source2, env);
Assert.IsTrue(result2);

var md5 = await _service.AppPublishedConfigsMd5("001", env);
var md5 = await _service.AppPublishedConfigsMd5(app1, env);
Assert.IsNotNull(md5);
}

Expand All @@ -624,9 +639,12 @@ public async Task GetPublishedConfigsByAppIdTest()
this.ClearData();

var id = Guid.NewGuid().ToString();
var app1 = Guid.NewGuid().ToString();
var app2 = Guid.NewGuid().ToString();

var source = new Config
{
AppId = "001",
AppId = app1,
Id = id,
Group = "group",
Key = "key",
Expand All @@ -640,7 +658,7 @@ public async Task GetPublishedConfigsByAppIdTest()
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = app1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -654,7 +672,7 @@ public async Task GetPublishedConfigsByAppIdTest()
var id2 = Guid.NewGuid().ToString();
var source2 = new Config
{
AppId = "002",
AppId = app2,
Id = id2,
Group = "g",
Key = "k",
Expand All @@ -678,9 +696,13 @@ public async Task GetPublishedConfigsByAppIdTest()
public async Task AddRangeAsyncTest()
{
var id = Guid.NewGuid().ToString();
var app1 = Guid.NewGuid().ToString();
var app2 = Guid.NewGuid().ToString();
var env = "DEV";

var source = new Config
{
AppId = "001",
AppId = app1,
Id = id,
Group = "group",
Key = "key",
Expand All @@ -689,12 +711,13 @@ public async Task AddRangeAsyncTest()
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
Status = ConfigStatus.Enabled,
OnlineStatus = OnlineStatus.Online
OnlineStatus = OnlineStatus.Online,
Env = env
};
var id1 = Guid.NewGuid().ToString();
var source1 = new Config
{
AppId = "001",
AppId = app1,
Id = id1,
Group = "g",
Key = "k",
Expand All @@ -703,18 +726,19 @@ public async Task AddRangeAsyncTest()
CreateTime = DateTime.Now,
UpdateTime = DateTime.Now,
Status = ConfigStatus.Deleted,
OnlineStatus = OnlineStatus.Online
OnlineStatus = OnlineStatus.Online,
Env = env
};

var result = await _service.AddRangeAsync(new List<Config> {
source,
source1
}, "");
}, env);
Assert.IsTrue(result);

var config = await _service.GetAsync(id, "");
var config = await _service.GetAsync(id, env);
Assert.IsNotNull(config);
var config1 = await _service.GetAsync(id1, "");
var config1 = await _service.GetAsync(id1, env);
Assert.IsNotNull(config1);
}

Expand Down

0 comments on commit c052747

Please sign in to comment.