2

I am very new to Specflow/Specrun and C# programming. I need help in fixing the issue I am facing.

I have a Specrun feature file which queries database. Below is the code of the feature file:

Scenario Outline: Ensure all rows are correctly inserted on in the table
    Given I am connected to "Database-XYZ"
    When I run a script to ensure all rows are inserted for <tableName> of a <schemaName>
    Then All tables have correct <columnCount> count.

This works absolutely fine. But I want to comment the second line and specify the database name at run time using the default.srprofile file.

I want to execute runtests.cmd file (from commandline) using default.srprofile file and feed the database name at run time. Is it possible to achieve this?

user1493004
  • 101
  • 2
  • 2
  • 6
  • 1
    What do you meen by run time? The srProfile is read at the beginning of the testrun. Or do you simply want to configure the database somewhere because it is different for different developers? – Andreas Willich Nov 08 '16 at 08:28

1 Answers1

2

Not sure if this will help but you may want to use the app.config. I set my Database and the Environment and then call it from a step. This way you could create a call and set the database according to the environment under test by just changing the value in the app.config. You could do something like the below.

 app.config
 <add key="DatabaseTest" value="myDBConnectionString" />
 <add key="DatabaseDev" value="myDBConnectionString" />
 <add key="Environment" value="test" />

 Step:
 using System.Configuration; //make sure you have this included to use ConfigurationManager

    [Given(@"I am connected to my environment database")]
    public void GivenIAmConnectedToMyEnvironmentDatabase()
    {

     var myEnv = ConfigurationManager.AppSettings["Environment"];
     switch (myEnv)
     {
       case "test":
         var  _testDatabase = ConfigurationManager.AppSettings["DatabaseTest"];
         //create db connection 
         break;
       case "dev":
          var _devDatabase = ConfigurationManager.AppSettings["DatabaseDev"];
          //create db connection 
          break;
     }
     }
Dazed
  • 1,527
  • 1
  • 13
  • 25