using SwBLL.ServerConfig;
using SwDAL.CustomCode.ServerConfig;
using SwDAL.DTO.ServerConfig;
using GB5Shared.Connection;
using GB5Shared.DTO.Framework.AutoNumber;
using GB5Shared.DTO.Framework.CommonConfig;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.GenerateAutoNumber;
using GB5Shared.QueryExecutor;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Moq;
using Xunit;
namespace SwTests;
///
/// Covers ServerConfigBLL — the write path ClientDatabaseProvisioner calls after creating a
/// physical database, so ReportConnectionResolver/ServerConfigCache can route to it at runtime.
/// All DAL/encryption dependencies are mocked; no real gb5system database is touched.
///
public class ServerConfigBLLTests
{
private static (ServerConfigBLL Svc, Mock Dal, Mock AppConnection)
BuildService()
{
var dal = new Mock();
var appConnection = new Mock();
appConnection.Setup(c => c.Encrypt(It.IsAny(), It.IsAny())).Returns("ENCRYPTED");
// AutoNumber is a concrete class (not an interface) — build a real instance backed by a
// mocked IQueryExecutor so RegisterDatabaseAsync's now-real MSERVER/MSERVERCONFIG
// AutoNumber allocations resolve without throwing. The exact allocated value doesn't
// matter to any assertion here (InsertServerAsync/InsertServerConfigAsync are themselves
// mocked to return fixed IDs) — only that GetNumberAsync completes successfully.
var queryExecutor = new Mock();
queryExecutor
.Setup(q => q.QueryAsync(It.IsAny(), It.IsAny(), It.IsAny