Data driven testing in MSTest - problem with TestContext.DataRow

I'm having essentially the same problem as the question linked below, but I cannot seem to get it to work. I'm getting "cannot apply indexing [] to an expression of type System.Data.DataRow". As far as I can tell, I have implemented the solution correctly.

Problems with data driven testing in MSTest

[TestClass]
public class UnitTest1
{
    private TestContext testContextInstance;

    public TestContext TestContext
    {
        get
        {
            return testContextInstance;
        }
        set
        {
            testContextInstance = value;
        }
    }        

    private ServiceReference1.ProductCatalogClient client = new ServiceReference1.ProductCatalogClient("BasicHttpBinding_IProductCatalog");

    [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\CountList.csv", "CountList#csv", DataAccessMethod.Sequential), DeploymentItem("..\\ServiceTest\\CountList.csv"), TestMethod]
    public void AreCountsCorrect()
    {
        int id = TestContext.DataRow["Id"] as int;
        int count = client.GetProductCount(id);
        Assert.IsTrue(count == TestContext.DataRow["Count"] as int);
    }
}

14
задан Community 23 May 2017 в 12:17
поделиться