开发者

.net unit test project with CSV datasource not reading in values correctly

开发者 https://www.devze.com 2023-04-07 17:10 出处:网络
I have a Unit Test project in .net 4.0.One of the test methods reads in a CSV file.Unfortunately, some of the values in the csv file are not being read.I think what is happening is that .net is choosi

I have a Unit Test project in .net 4.0. One of the test methods reads in a CSV file. Unfortunately, some of the values in the csv file are not being read. I think what is happening is that .net is choosing what type a column is and ignoring any values that do not fit within that type. For example, I may have a column where 90% of the values are numbers, but the other 10% are num开发者_Python百科bers with letters. The numbers with letters are not coming through. Any ideas on how to fix this?

Here is the attribute on top of my test method

        [DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\test.csv", "test#csv",  DataAccessMethod.Sequential), DeploymentItem("MyProject.Tests\\TestData\\Test.csv"), TestMethod()]

Thanks! AFrieze


You need to enclose the values in the mixed-type column in quotation marks. E.g.

AllNumeric,Mixed,AllString
1,"1",a
2,"2b",b

Alternatively, you can create a file named Schema.ini in the same directory as the csv file to specify the type, as mentioned below. http://geekswithblogs.net/dotNETvinz/archive/2011/01/03/uploading-and-importing-csv-file-to-sql-server-in-asp.net.aspx

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号