Introduced new features including database upgrade logic, schema comparison, and schema-based updates. Refactored main program structure for modularity. Added unit tests and updated configuration files to support upgrades and enhanced mapping functionality.
65 lines
1.9 KiB
C#
65 lines
1.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using JetBrains.Annotations;
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
using tbfDBBackup.compare_dumps.joinValues;
|
|
using tbfDBBackup.configuration;
|
|
|
|
namespace tbfDBBackup.Tests.compare_dumps.joinValues;
|
|
|
|
[TestClass]
|
|
[TestSubject(typeof(Joiner))]
|
|
public class JoinerTest
|
|
{
|
|
|
|
string GetProjectRoot() {
|
|
string dir = AppContext.BaseDirectory;
|
|
while (dir != null && !Directory.GetFiles(dir, "*.csproj").Any()) {
|
|
dir = Directory.GetParent(dir)?.FullName;
|
|
}
|
|
return dir ?? throw new Exception("Project root not found.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void SchemaJoiner()
|
|
{
|
|
// Arrange - project test
|
|
string projectRoot = GetProjectRoot();
|
|
//Configure test database
|
|
Configuration dbConfiguration = new Configuration();
|
|
|
|
dbConfiguration.DbConnectionStrings = new List<DbConnection>();
|
|
dbConfiguration.DbConnectionStrings.Add(new DbConnection()
|
|
{
|
|
Connection = "SERVER=localhost; DATABASE={DatabaseName}; UID=root; PASSWORD=; CHARSET=utf8;",
|
|
DatabaseName = "testdbupdate",
|
|
Enabled = true,
|
|
IsOneTimeOpaque = true,
|
|
Name = "test",
|
|
});
|
|
dbConfiguration.UpgradeDatabase = new List<Upgrade>();
|
|
dbConfiguration.UpgradeDatabase.Add(new Upgrade()
|
|
{
|
|
DatabaseName = "testdbupdate",
|
|
Enabled = true,
|
|
Name = "test upgrade",
|
|
JSONFileName = "",
|
|
Query = "",
|
|
IsOneTimeOpaque = true
|
|
});
|
|
|
|
|
|
Joiner joiner = new Joiner(
|
|
dbConfiguration,
|
|
projectRoot,
|
|
"Resources/old.sql",
|
|
"Resources/schema-mapping.json");
|
|
|
|
joiner.SchemaJoiner();
|
|
|
|
Assert.IsTrue(joiner.IsJoindedSuccesfully);
|
|
|
|
}
|
|
} |