简体   繁体   中英

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));
}

您可以像在标准类中那样调用该方法: GivenIHaveLocatedTheXYZFileFromLocation(string.Format("I have located the XYZ file from {0}", xyzfilelocation));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM