C# Solution
Since I myself find it easiest to work with already compiling solutions, I have put together a visual studio, C# solution with the following types of project, where SQL Deleter is being used
- Winform
- Consol application
- Blazor
- Unit Test
To download the solution, click here on the following:
SQL_Deleter_example.zip
To get an overview how the code could look, here is the example from the Unit Test:
namespace SQL_Deleter_UnitTest_Example
{
// Test class
public class UnitTest1 : IClassFixture<TestCompletionFixture>
{
private readonly TestCompletionFixture _fixture;
public UnitTest1(TestCompletionFixture fixture)
{
_fixture = fixture;
}
[Fact]
public void CheckPerson()
{
Assert.True(_fixture.oldObject.CompareResult(_fixture.newObject, "delete from [Person].[Person] where BusinessEntityID = 1;"));
_fixture.testsPassed++;
}
[Fact]
public void AnotherTest()
{
Assert.True(true); // Example of another test
_fixture.testsPassed++;
}
}
// Test completion fixture
public class TestCompletionFixture : IAsyncLifetime
{
public int testsPassed = 0;
public SQLDeleter.Connection connection;
public SQLDeleter.ConnectionObject oldObject;
public SQLDeleter.ConnectionObject newObject;
public readonly string currentVersion = "1.5.0";
public TestCompletionFixture()
{
var connString = $"Data Source=localhost\\SQLEXPRESS;Initial Catalog=AdventureWorks2022;TrustServerCertificate=true; Integrated Security=True;";
connection = new SQLDeleter.Connection(connString);
oldObject = connection.LoadLatestInserted();
if (oldObject == null)
{
oldObject = connection.GetSyncWithDB();
newObject = oldObject;
connection.Save(oldObject, currentVersion); // Save if no old object
}
else
{
newObject = connection.GetSyncWithDB();
}
}
public async Task InitializeAsync()
{
}
public async Task DisposeAsync()
{
// Called after all tests in the test class have completed
if(testsPassed == 2 && !connection.GetSortedVersions().Contains(currentVersion))
{
connection.Save(newObject, currentVersion); // all tests has passed and we have a new version, so we save it down
}
}
}
}