Mohammed Thabet
Mohammed Thabet

Reputation: 21677

Unit testing method with input parameters from multiple data tables

I would like to create unit test method using Microsoft Unit testing and this method take its input parameters from different tables inside the same DB .

[TestMethod()]
[DataSource("System.Data.SqlClient", "Data Source=ServerName;Initial Catalog=DBName;Persist Security Info=True;User ID=--;Password=--",
   "Table1", DataAccessMethod.Random), TestMethod]
public void MyTestMethod(int parameter1,int parameter2)
{
}

For example, parameter1 from table1 and parameter2 from table 2. Can I do that ?

Also, can I make a condition e.g join 2 tables to retrieve sample test data or you can retrieve parameter2 from table2 filtering by parameter1?

All ideas are welcomed.

Upvotes: 1

Views: 919

Answers (1)

k.m
k.m

Reputation: 31454

I don't think it's possible, given TableName property on DataSource attribute requires you to specify one name explicitly. What you could do instead, is create a view with data you need, that includes joining your two original tables.

Examples on how to use DataSource attribute properly can be found at online MSDN documentation.

Upvotes: 1

Related Questions