Prevent TestContext from automatically converting data

I parameterize my test cases using data read from CSV files. One of the columns in the csv file has simple date values ​​(like regular strings) in US format, for example mm/dd/yyyy . When data is actually read and populated in TestContext , however, TestContext.DataRow["MyDateColumn"] actually returns a converted System.DateTime object with a timestamp of 12:00:00 AM . I absolutely do not require or do not want this automatic conversion. How to stop this?

+4
source share
3 answers

If the type MyDateColumn is set to datetime, it should / should return a datetime object.

Try changing the type of MyDateColumn as a string and see if this does the trick.

UPDATE

Change the dates in CSV so that they are "mm / dd / yyyy" instead of mm / dd / yyyy.

+2
source
 DateTime.Parse(TestContext.DataRow["MyDateColumn"], CultureInfo.InvariantCulture).ToShortDateString() 
0
source

I got a solution for this :)

I just put it in front of the actual data. When I receive data, the data arrives as is. Before using it, I remove 'from the data using the substring method.

I remember using this technique for excel to have numbers displayed as text. It worked for me.

0
source

Source: https://habr.com/ru/post/1342282/


All Articles