2025-02-02 23:13:17 +01:00
|
|
|
using Moq;
|
2025-01-31 22:08:54 +01:00
|
|
|
using Newtonsoft.Json.Linq;
|
2025-02-02 23:13:17 +01:00
|
|
|
using Tests;
|
|
|
|
|
using Core.Configurations.SmartConfig;
|
|
|
|
|
using Core.Configurations.Common;
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
namespace Tests.ConfigurationTests;
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
[TestClass]
|
|
|
|
|
public class ConfigurationTests : TestFixture
|
|
|
|
|
{
|
|
|
|
|
[TestInitialize]
|
|
|
|
|
public void Init()
|
|
|
|
|
{
|
|
|
|
|
}
|
2025-01-31 22:08:54 +01:00
|
|
|
|
|
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
[TestMethod]
|
|
|
|
|
public void ConfigurationSettingsTest()
|
|
|
|
|
{
|
|
|
|
|
var pairs = new List<KeyValuePair<string, JToken>>
|
|
|
|
|
{
|
|
|
|
|
new("Debug", true),
|
|
|
|
|
// Database konfiguration
|
|
|
|
|
new("Database:ConnectionString", "Server=db.example.com;Port=5432"),
|
|
|
|
|
new("Database:Timeout", 30),
|
|
|
|
|
new("Database:UseSSL", true),
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
// Logging konfiguration med JObject
|
|
|
|
|
new("Logging:FileOptions", JObject.Parse(@"{
|
|
|
|
|
'Path': '/var/logs/app.log',
|
|
|
|
|
'MaxSizeMB': 100,
|
|
|
|
|
'RetentionDays': 7
|
|
|
|
|
}")),
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
// Feature flags med kompleks konfiguration
|
|
|
|
|
new("Features:Experimental", JObject.Parse(@"{
|
|
|
|
|
'Enabled': true,
|
|
|
|
|
'RolloutPercentage': 25,
|
|
|
|
|
'AllowedUserGroups': ['beta']
|
|
|
|
|
}")),
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
// API endpoints med array
|
|
|
|
|
new("API:Endpoints", "/api/users"),
|
|
|
|
|
new("API:Endpoints", "/api/products")
|
|
|
|
|
};
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
var result = KeyValueToJson.Convert(pairs);
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
var expected = JObject.Parse(@"{
|
|
|
|
|
'Debug' : true,
|
|
|
|
|
'Database': {
|
|
|
|
|
'ConnectionString': 'Server=db.example.com;Port=5432',
|
|
|
|
|
'Timeout': 30,
|
|
|
|
|
'UseSSL': true
|
|
|
|
|
},
|
|
|
|
|
'Logging': {
|
|
|
|
|
'FileOptions': {
|
|
|
|
|
'Path': '/var/logs/app.log',
|
|
|
|
|
'MaxSizeMB': 100,
|
|
|
|
|
'RetentionDays': 7
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'Features': {
|
|
|
|
|
'Experimental': {
|
|
|
|
|
'Enabled': true,
|
|
|
|
|
'RolloutPercentage': 25,
|
|
|
|
|
'AllowedUserGroups': ['beta']
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
'API': {
|
|
|
|
|
'Endpoints': ['/api/users', '/api/products']
|
|
|
|
|
}
|
|
|
|
|
}");
|
2025-01-31 22:08:54 +01:00
|
|
|
|
2025-02-02 23:13:17 +01:00
|
|
|
Assert.IsTrue(JToken.DeepEquals(expected, result));
|
|
|
|
|
}
|
|
|
|
|
}
|