0

I have a table like following in my features files:

Then I should see 'View' option on following rows
| version    | d_temp__ts | d_promote__ts |
| 17.0       |            | 2020-08-14    |
| 17.1       | 2020-08-18 |               |
| 17.2       |            | 2020-09-14    |
| 17.2       | 2020-09-15 |               |
| 17.3       |            | 2020-09-18    |
| 17.4       | 2020-09-28 |               |

And In Step definition I am using CreateDynamicSet from Specflow.Assist.Dynamic(1.4.2) to get the table value:

[Then(@"I should see '(.*)' option on following rows")]
    public void ThenIShouldSeeOptionOnFollowingRows(string actionType, Table table)
    {
           manageVersionPage = new Wcsp2ManageVersionPage(sc);

         IEnumerable<dynamic> tableData = table.CreateDynamicSet();
        foreach(var row in tableData)
        {
           

            string wcspVersion = row.n_wcsp_ver.ToString();
            string checkout = row.d_checkout__ts.ToString();
            string temp = row.d_temp__ts.ToString();
            string promote = row.d_promote__ts.ToString();

            Console.WriteLine("Test2");
            Console.WriteLine($"wcspVersion = {wcspVersion}");
            Console.WriteLine($"checkout = {checkout}");
            Console.WriteLine($"temp ={temp}");
            Console.WriteLine($" promote ={promote}");

              
            //do some other operations
        }
    }

While printing the value having Date like 2020-08-14 it is converting to date like 18-Aug-20 12:00:00 AM. And While converting 17.0 to string I am getting only 17

I don't want this kind conversion. I need to get the exact value that is in the feature files. How can I get the exact value from the feature file as string?

Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
  • 1
    The code isn't converting the datetime. It is just diplaying in the default ToString() method. You need to modify the ToString() to output in the format you want. See : https://learn.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings and https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-date-and-time-format-strings – jdweng Sep 08 '20 at 11:09
  • Does this answer your question? [Formatting a float to 2 decimal places](https://stackoverflow.com/questions/6356351/formatting-a-float-to-2-decimal-places) (same applies to `decimal` type). – Greg Burghardt Sep 17 '20 at 16:19
  • @GregBurghardt that didn't solve my issue. I think the **CreateDynamicSet()** from **specflow.assist.dynamic** is automatically converting the data to date and integer. – Suban Dhyako Sep 21 '20 at 11:38
  • Which line of code is causing the problem? I see a column in your data table called "version" but I don't see anything referencing that column name in your C# code. – Greg Burghardt Sep 21 '20 at 13:51
  • `IEnumerable tableData = table.CreateDynamicSet();` This line is causing problem. While using **CreateDynamicSet()** we don't need to reference it another class – Suban Dhyako Sep 24 '20 at 04:55

0 Answers0