This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,96 @@
using DTS.Common.Interface.Database;
using NUnit.Framework;
using System.IO;
using System.Linq;
namespace DatabaseUnitTesting
{
[TestFixture]
public partial class DBAPITests
{
private const string INSTANCE_NAME = "DataPROInstance";
private const string LOCAL_SERVER = @"(localdb)\DataPROInstance";
private const string SCRIPTS_FOLDER = "SQL Server Scripts";
private const string LOCAL_DB_FOLDER = "db";
private const string ISO = "ISO";
private const string ATTACH_DBS_BAT = "AttachDBs.bat";
private bool _setup = false;
private IUserDbRecord _user = null;
private const int SettingsDefaultMaxLogFileSize = 4194304;
private const int SettingsDefaultDBLoggingLevel = 783;
private int clientDbVersion = DTS.Common.Storage.DbOperations.MINIMUM_LTS_DB_VERSION;
[OneTimeSetUp]
public void Setup()
{
if (!DbAPI.DbAPI._loggerInitialized)
{
DbAPI.DbAPI.InitializeLogger(SettingsDefaultMaxLogFileSize, "Logs", SettingsDefaultDBLoggingLevel);
}
var dllLocation = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
var debugOrRelease = dllLocation.Directory.Name;
var architecture = dllLocation.Directory.Parent.Name;
var curDir = System.Environment.CurrentDirectory;
if (curDir.Contains("Common"))
{
curDir = curDir.Substring(0, curDir.IndexOf("Common"));
curDir = Path.Combine(curDir, "DataPRO");
}
else
{
var tokens = curDir.Split(new[] { Path.DirectorySeparatorChar });
var count = tokens.Count(d => d.Equals("DataPRO"));
if (1 == count)
{
tokens[0] = $"{tokens[0]}{Path.DirectorySeparatorChar}";
var index = tokens.ToList().IndexOf("DataPRO");
tokens = tokens.Take(index + 1).ToArray();
curDir = Path.Combine(tokens);
}
else if (0 == count)
{
curDir = Path.Combine(curDir, "DataPRO");
}
}
var exeOutputLocation = Path.Combine(curDir, "DataPRO", "bin", architecture, debugOrRelease);
var details = new DbAPI.Connections.ConnectionDetails();
details.AttachDbsBatPath = Path.Combine(exeOutputLocation, SCRIPTS_FOLDER, ATTACH_DBS_BAT);
details.DbFolderPath = Path.Combine(exeOutputLocation, LOCAL_DB_FOLDER);
details.DbName = "DataPRO";
details.UsingCentralizedDb = false;
details.DbServer = LOCAL_SERVER;
details.InstanceName = INSTANCE_NAME;
details.UseNTLMAuthentication = true;
details.SqlDbPath = DTS.Common.Utils.Database.GetSqlServerLocalDbPath();
details.ODBCToolsPath = DTS.Common.Utils.Database.GetODBCToolsPath(null);
var res = DbAPI.DbAPI.Connections.ConnectToDb(details);
_setup = true;
}
[Test]
public void TestConnect()
{
if (!_setup) { Setup(); }
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
Assert.IsTrue(connections.Any(), $"Db connected");
}
private void Login()
{
var connections = DbAPI.DbAPI.Connections.GetActiveConnections();
var hr = DbAPI.DbAPI.Connections.LoginUser(connections.First(), "Admin", "DTSAdmin", out var user);
if (0 == hr)
{
_user = user;
clientDbVersion = connections.FirstOrDefault().ClientDbVersion;
}
}
[Test]
public void TestLogin()
{
if (!_setup) { Setup(); }
TestConnect();
if (null == _user) { Login(); }
Assert.IsNotNull(_user, "User logged in");
}
}
}