Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support functions in DataSourceAttribute and function parameters #228

Closed
bungeemonkee opened this issue Jul 26, 2017 · 3 comments
Closed

Comments

@bungeemonkee
Copy link

Description

Trying to convert an old NUnit test project to MSTest (while porting a solution to .Net Core). The existing tests all use the same set of about 200 text files across several folders to hold all the test cases. The existing NUnit implementation has a single utility function that reads the contents of each directory and provides the sets of file names as an IEnumerable<string>. Then each test takes a single string parameter to tell it what file has the test case.

I can find no way to replicate this behavior with MSTest (v1.1.11). Any function that takes any parameters throws a TargetParameterCountException with the message "Parameter count mismatch" (probably issue #199 ). Additionally any attempt to use the TestContext.DataRow property won't compile. It seems in previous versions of MSTest the DataRow property only appeared when a reference to the System.Data assembly was added but I can't find a .Net Core equivalent. (System.Data.Common didn't work and nothing else seemed appropriate. The Reverse Package Search didn't find anything that seemed relevant).

How can I get something close to this behavior without coding hundreds of separate test cases?

Thanks!

Steps To Reproduce

[TestClass]
public class Tests
{
    public TestContext Context { get; set; }

    public static IEnumerable<string> FolderFileNameIterator()
    {
        var textFileFolder = new DirectoryInfo("Data");
        foreach (var sampleFile in textFileFolder.GetFiles())
        {
            yield return sampleFile.Name;
        }
    }

    [TestMethod, DataSource("FolderFileNameIterator")]
    public void Test1(string FileName)
    {
        // Test code
    }

    [TestMethod, DataSource("FolderFileNameIterator")]
    public void Test2()
    {
        var fileName = Context.DataRow[0]; // Won't compile
        // Test code
    }
}

Environment

Test Assembly:
NetCoreApp 1.1
MSTest.TestFramework 1.1.11
MSTest.TestAdapter 1.1.11
Microsoft.NET.Test.Sdk 15.0.0

Assembly Under Test:
Net Standard 1.4

@AbhitejJohn
Copy link
Contributor

@bungeemonkee : I believe DynamicData attribute is what you are looking for. Its been added into the 1.2.0-beta version of the Framework/adapter tuple. #169 details this better.

@bungeemonkee
Copy link
Author

Thanks @AbhitejJohn I'll try this out in a few hours and close this issue if it works. In that case it would seem the real issue is one of documentation.

@bungeemonkee
Copy link
Author

This worked for me, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants