1

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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.