Populate Enova database settings from connection string
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using System.Data.Common;
|
||||
using System.Reflection;
|
||||
using System.Runtime.Loader;
|
||||
using SmartB2B.Enova.Contracts;
|
||||
using SmartB2B.Enova.Service;
|
||||
using SmartB2B.Enova.Service.Configuration;
|
||||
@@ -36,6 +37,7 @@ var tests = new (string Name, Func<Task> Run)[]
|
||||
("Parametr /debug włącza szczegółowe logowanie", DebugSwitchEnablesVerboseLogging),
|
||||
("Parametr /verbose można wyłączyć", VerboseSwitchCanBeDisabled),
|
||||
("Tryb szczegółowy jest przekazywany do adaptera", VerboseModeReachesAdapter),
|
||||
("Rejestracja bazy przenosi parametry connection stringa", DatabaseRegistrationUsesConnectionString),
|
||||
("Provider SQL działa na bieżącej platformie", SqlProviderIsSupported)
|
||||
};
|
||||
|
||||
@@ -79,6 +81,69 @@ static Task SqlProviderIsSupported()
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
static Task DatabaseRegistrationUsesConnectionString()
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
string? installationPath = null;
|
||||
while (directory is not null)
|
||||
{
|
||||
var candidate = Path.Combine(directory.FullName, "enova365 2604.4.4");
|
||||
if (File.Exists(Path.Combine(candidate, "Soneta.Business.dll")))
|
||||
{
|
||||
installationPath = candidate;
|
||||
break;
|
||||
}
|
||||
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
if (installationPath is null)
|
||||
{
|
||||
throw new InvalidOperationException("Nie znaleziono lokalnej instalacji enova365 do testu adaptera.");
|
||||
}
|
||||
|
||||
Assembly? ResolveSonetaAssembly(AssemblyLoadContext context, AssemblyName name)
|
||||
{
|
||||
var candidate = Path.Combine(installationPath, $"{name.Name}.dll");
|
||||
return File.Exists(candidate) ? context.LoadFromAssemblyPath(candidate) : null;
|
||||
}
|
||||
|
||||
AssemblyLoadContext.Default.Resolving += ResolveSonetaAssembly;
|
||||
var adapterAssembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(
|
||||
Path.Combine(AppContext.BaseDirectory, "SmartB2B.Enova.Adapter.dll"));
|
||||
var adapterType = adapterAssembly.GetType("SmartB2B.Enova.Adapter.EnovaOrderAdapter", throwOnError: true)
|
||||
?? throw new InvalidOperationException("Nie znaleziono typu adaptera Enovy.");
|
||||
var parseConnectionString = adapterType.GetMethod(
|
||||
"ParseSqlConnectionString",
|
||||
BindingFlags.Static | BindingFlags.NonPublic)
|
||||
?? throw new InvalidOperationException("Nie znaleziono metody analizującej connection string Enovy.");
|
||||
object settings;
|
||||
try
|
||||
{
|
||||
settings = parseConnectionString.Invoke(
|
||||
null,
|
||||
["Server=sql01;Database=Moms_Care;User ID=smartb2b;Password=haslo-sql;TrustServerCertificate=True"])
|
||||
?? throw new InvalidOperationException("Adapter nie odczytał konfiguracji połączenia Enovy.");
|
||||
}
|
||||
catch (TargetInvocationException exception) when (exception.InnerException is not null)
|
||||
{
|
||||
throw exception.InnerException;
|
||||
}
|
||||
|
||||
AssertEqual("sql01", GetProperty(settings, "DataSource"), "serwer SQL");
|
||||
AssertEqual("Moms_Care", GetProperty(settings, "InitialCatalog"), "nazwa bazy SQL");
|
||||
AssertEqual("smartb2b", GetProperty(settings, "UserID"), "użytkownik SQL");
|
||||
AssertEqual("haslo-sql", GetProperty(settings, "Password"), "hasło SQL");
|
||||
AssertEqual(false, GetProperty(settings, "IntegratedSecurity"), "uwierzytelnianie zintegrowane");
|
||||
AssertEqual(true, GetProperty(settings, "TrustServerCertificate"), "zaufanie certyfikatowi SQL");
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
static object? GetProperty(object instance, string name) =>
|
||||
instance.GetType().GetProperty(name)?.GetValue(instance)
|
||||
?? throw new InvalidOperationException($"Nie znaleziono wartości właściwości '{name}'.");
|
||||
|
||||
static Task ValidFractionalDiscount()
|
||||
{
|
||||
AssertNoErrors(CreateValidRequest(12.5m));
|
||||
|
||||
Reference in New Issue
Block a user