Prevent TestContext data from being automagically converted
I am parameterising my test cases by using dat开发者_运维技巧a read from .csv files. One of the columns in the csv file has simple date values (as regular strings) in US format, eg mm/dd/yyyy
. When the data is actually read and populated into a TestContext
however, TestContext.DataRow["MyDateColumn"]
actually returns a converted System.DateTime
object, complete with a timestamp of 12:00:00 AM
. I absolutely do not require or want this automatic conversion. How do I stop this from happening?
If the type of the MyDateColumn is set to datetime, then it would/should return a datetime object.
Try changing the type of MyDateColumn to be string and see if that does the trick.
UPDATE
Change dates in the CSV so that they are "mm/dd/yyyy" instead of mm/dd/yyyy.
DateTime.Parse(TestContext.DataRow["MyDateColumn"], CultureInfo.InvariantCulture).ToShortDateString()
I got solution for this :)
I just put ' before actual data. When I retrieve data, data comes as is. Before using it, I remove ' from data with substring method.
I remember using this technique on excel to make numbers appear as text. It worked for me.
I put double qoutes around the data. That gives back strings, without removing the quotes.
columnInt, columnString
1, "11.12.89"
2, "12.12.89"
精彩评论