Search code examples
c#stringencapsulationspecflowmethod-call

How to encapsulate method 1 to method 2 specflow?


I have the following question in regards to encapsulation using the SpecFlow framework, goal is to encapsulate Method 1 in method 2, below are the following features/scenarios as well as the generated step, I believe I need to use string.format. Anyway please advise how to encapsulate the existing given in method 1 to method 2.

Firstly please see scenario.

Scenario Outline: Compare XYZ data against the given templates
Given I have located the XYZ file from <xyzfilelocation>

Examples:
| xyzfilelocation                                                      |
| Tests\Meebu\Doggg\Cat\xyz\Yhyh800\Yhyh800_TheId_1234567.FirstOne.xml |
| Tests\Meebu\Doggg\Cat\xyz\Yhyh800\Yhyh800_TheId_7654321.SecondTwo.xml|

Secondly see the steps generated.

//Method 1

[Given(@"I have located the XYZ file from (.*)")]
public void GivenIHaveLocatedTheXYZFileFromLocation(string xyzfilelocation)
{
string file = new System.IO.DirectoryInfo(Assembly.GetExecutingAssembly().Location).Parent.FullName + "\\" + xyzfilelocation;

_context.ActualXYZ = new XmlDocument();
_context.ActualXYZ.Load(file);
}

//Method 2, I want to encapsulate above method here, Im trying to do below, is this correct way and I believe I need to do string.format please advise/will this work and is it encapsulation?

[When(@"I compare XYZ file (.*)")]
public void WhenICompareXYZFile(string xyzfilelocation)
{

//Calling the method Given I have located the XYZ file from <xyzfilelocation>
Given(string.Format("I have located the XYZ file from {0}", xyzfilelocation));
}

Solution

  • You can just call the method like you would in a standard class: GivenIHaveLocatedTheXYZFileFromLocation(string.Format("I have located the XYZ file from {0}", xyzfilelocation));