using System; using FrameworkBLL.Promotion; using Microsoft.Extensions.Configuration; using Xunit; namespace FrameworkTests; public class PromotionSystemContextTests { private static IConfiguration ConfigWith(string? databaseName, string? databaseType = null) { var dict = new System.Collections.Generic.Dictionary(); if (databaseName is not null) dict["Promotion:HomeDatabaseName"] = databaseName; if (databaseType is not null) dict["Promotion:HomeDatabaseType"] = databaseType; return new ConfigurationBuilder().AddInMemoryCollection(dict).Build(); } [Fact] public void GetSystemLogin_ReturnsClientIdMinusOneAndConfiguredDatabase() { var ctx = new PromotionSystemContext(ConfigWith("GB5DEMO", "0")); var login = ctx.GetSystemLogin(); Assert.Equal(-1, login.ClientId); Assert.Equal(-1, login.UserId); Assert.Equal("GB5DEMO", login.DatabaseName); Assert.Equal((byte)0, login.DatabaseType); } [Fact] public void Constructor_MissingHomeDatabaseName_Throws() { Assert.Throws(() => new PromotionSystemContext(ConfigWith(null))); } [Fact] public void GetSystemLogin_DatabaseTypeDefaultsToZeroWhenNotConfigured() { var ctx = new PromotionSystemContext(ConfigWith("GB5DEMO")); Assert.Equal((byte)0, ctx.GetSystemLogin().DatabaseType); } }