Db2Code–part 5 – testing
For testing I should find some databases to test to ( and do not forget that generating SELECT from PK supports just 1 PK, not multiple).
Microsoft already show some sample database – you can download from https://github.com/microsoft/sql-server-samples/tree/master/samples/databases . However , those must exists in the moment of running tests – so I have as options:
- Have an Sql Server ( by docker or on PC) and run the sql every time at the beginning of every start run test
- Have an Sqlite database file with all data and copy it .
( SqlServer in memory will be a good options, but it do not work with Sql insert/update….)
A specific test looks like this
static void CreateDb()
{//the restore operation just replace the sqlite database
DatabaseOperations.Restore(context, “Pubs”);}
[Theory]
[InlineData(SearchCriteria.Equal, ediscountsColumns.stor_id, “8042”, 1)]
[InlineData(SearchCriteria.Different, ediscountsColumns.stor_id, “8042”, 2)]
[InlineData(SearchCriteria.Equal, ediscountsColumns.stor_id, null, 2)]
[InlineData(SearchCriteria.Different, ediscountsColumns.stor_id, null, 1)]
//[InlineData(SearchCriteria.Equal, ediscountsColumns.discount, “5”, 1)]
[InlineData(SearchCriteria.Equal, ediscountsColumns.lowqty, “100”, 1)]
public async Task SearchAdvanced(SearchCriteria sc, ediscountsColumns col, string val, int nrRecs)
{
CreateDb();
var data = await context.discountsSimpleSearch(sc, col, val).ToArrayAsync();
Assert.Equal(nrRecs, data.Length);
}
One consequence will be that the tests cannot run in parallel .And , after all, it is just a work of coding data and results. Tiresome work, however pays in the long term.
Leave a Reply