1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
using System.Text.Json.Nodes;
using Spacebar.ConfigModel.Extensions;
using Spacebar.Db.Contexts;
namespace ConfigTest;
public class Worker(ILogger<Worker> logger, SpacebarDbContext db) : BackgroundService
{
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
var config = db.Configs
.OrderBy(x => x.Key)
.ToDictionary(x => x.Key, x => x.Value);
foreach (var (key, value) in config)
{
Console.WriteLine("Config Key: {0}, Value: {1}", key, value ?? "[NULL]");
}
var readConfig = config.ToNestedJsonObject();
Console.WriteLine(readConfig);
var mapped = readConfig.ToFlatKv();
foreach (var (key, value) in mapped)
{
Console.WriteLine("Mapped Key: {0}, Value: {1}", key, value ?? "[NULL]");
}
// check that they're equal
foreach (var (key, value) in config)
{
if (!mapped.ContainsKey(key))
{
Console.WriteLine("Missing Key in Mapped: {0}", key);
continue;
}
if (mapped[key] != value)
{
Console.WriteLine("Value Mismatch for Key: {0}, Original: {1}, Mapped: {2}", key, value ?? "[NULL]", mapped[key] ?? "[NULL]");
}
}
Environment.Exit(0);
}
}
|