I am trying to use SpecFlow BDD testing with data collected from an SQL Analysis services cube (got ideas from this article https://notesfromthelifeboat.com/post/analysis-services-2-testing/)
Most of the things work, but the final step where I want to compare an expected result set with a result from a dax query, I run into some problems. The code below shows the two most interesting methods. GivenIHaveMadeTheFollowingFilterSelection(Table table) creates a System.Data.DataTable object with some rows, and I want to compare this object with the result set from the SpecFlow Table as described below. The important things happen inside the ThenTheDataShouldBeDisplayedAsFollows(Table table) method. I want to compare the Specflow table with the system.data.Datatable in the easiest way. I believe there is a way converting the DataTable object so I can use Specflow assist methods comparing in one line (I hope). My code is experimenting with many possibilities but I hope I can make use of table.CompareToSet() so I don't need to loop and compare row by row (then I need sorting).
I hope you understand my problem and can guide me through this
Regards Geir
Date | Order count | Total amount |
---|---|---|
2020-01-01 | 2 | 150.00 |
2020-01-03 | 1 | 750.00 |
2020-01-04 | 2 | 130.50 |
[
[Given(@"I have made the following filter selection:")]
public void GivenIHaveMadeTheFollowingFilterSelection(Table table)
{
var query = @"EVALUATE SUMMARIZECOLUMNS (
'Date'[Date],
FILTER('Date', 'Date'[Year] = 2020),
""Order count"", [CountOfOrders],
""Total amount"", [Total Amount]
)";
this.dataTable = _tabularHelper.GetDataTable(query);
}
[Then(@"the data should be displayed as follows:")]
public void ThenTheDataShouldBeDisplayedAsFollows(Table table)
{
int index = 0;
var expectedRows = table.CreateSet<WeeklySales>() ;
var collection = ConvertToTankReadings(this.dataTable);
Assert.IsTrue(table.RowCount == this.dataTable.Rows.Count);
table.CompareToSet<WeeklySales>(collection);
foreach (WeeklySales expectedRow in expectedRows)
{
DataRow row = this.dataTable.Rows[index++];
var tt = expectedRow.TotalAmount;
var tt1 = expectedRow.Date;
var tt2 = expectedRow.OrderCount;
//Assert.AreEqual(expectedRow.TotalAmount, row["[Total Amount]"]);
}
}