uladz-zubrycki / reseed Goto Github PK
View Code? Open in Web Editor NEWInitialize and clean integration tests database in a convenient, reliable and fast way.
License: Apache License 2.0
Initialize and clean integration tests database in a convenient, reliable and fast way.
License: Apache License 2.0
With reseed and xunit the data inserted in the prepare database phase and data inserted during tests are not being deleted from the database when cleanup database is called at the end of the test. The record created during prepare database is not removed from the database after cleanup is called. If I call restore database in the dispose method the records are properly deleted after tests.
SeedActions
{
var deviceLogTable = new ObjectName("DeviceActivityLog");
string deviceQuery = $"DELETE FROM [dbo].[DeviceActivityLog] where DeviceId = {TestData.DeviceId.ToString()}";
var actions = _reseeder.Generate(
dbConnection, SeedMode.Basic(
BasicInsertDefinition.Script(),
CleanupDefinition.Script(
CleanupMode.Delete(),
CleanupTarget.Including(
configure: c => c.IncludeTables(new ObjectName("DeviceActivityLog")),
customScripts: new[]
{
(deviceLogTable, deviceQuery)
}
)),
DataProviders.Inline(builder => builder
//Add barcode
.AddEntities(
new Entity("DeviceActivityLog",
new[]
{
new Property("DeviceActivityLogId",TestData.DeviceActivityLogId.ToString()),
new Property("ActivityUnique",TestData.DeviceActivityUnique.ToString()),
new Property("Timestamp","2022-05-31 19:56:39.000"),
new Property("DeviceActivityTypeId","23"),
new Property("EntityId",TestData.LocationId.ToString()),
new Property("DeviceId",TestData.DeviceId.ToString()),
new Property("TransAmount","0.00"),
new Property("TicketPrice","0.00"),
new Property("ActivityLogFileName","220531195639"),
new Property("IsError","1"),
new Property("DrawerNumber",""),
new Property("ErrorMessage",""),
}
))
.Build())));
return actions;
}
Base test class. Constructor gets called before each test where I call Restore Database.
[Collection("Database Collection")]
public class BaseApiTest
{
protected readonly TestFixture fixture;
protected readonly ITestOutputHelper testOutput;
public DatabaseHelper databaseHelper;
//constructor is called before each test
public BaseApiTest(TestFixture _fixture, ITestOutputHelper testOutputHelper)
{
fixture = _fixture;
testOutput = testOutputHelper;
fixture.Databases.ForEach(db => db.RestoreDatabase());
}
//Returns authenticated HTTP client with bearer token
public HttpClient GetClient()
{
var client = fixture.Client;
return client;
}
}
Test Fixture where I can Cleanup Database in dispose which is called after all tests have run.
public TestFixture()
{
Client = new HttpClient();
TmsConnection = new SqlConnection(TmsConnectionString);
TmsConnection.Open();
DbTMS = new DatabaseHelperTMS(TmsConnection);
LoggingConnection = new SqlConnection(LoggingConnectionString);
LoggingConnection.Open();
DbLogging = new DatabaseHelperLogging(LoggingConnection);
Databases = new List<IDatabaseSeedManager>() { DbTMS, DbLogging };
Databases.ForEach(db => db.PrepareDatabaseSeed());
}
//runs after class is created before any tests run
//Get bearer token to authenticate client
public async Task InitializeAsync()
{
await AuthenticateClient();
}
public async Task DisposeAsync()
{
}
public void Dispose()
{
Databases.ForEach(db => db.CleanDatabase());
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.