The way I avoid binding and encouraging reuse is as follows:
1.) Group my actions with an object, for example, AccountRepositorySteps (for AccountRepository) or AccountControllerSteps (for AccountController).
2.) Take steps that depend on abstractions, not concrete (as with our production code).
3.) Rely on the current Context script to pass values ββbetween steps and step files.
Here is a short example:
Given a guy with the name Darren exists
And a guy with the name John exists
When I hit the guy page
Then I should see two guys
RepositorySteps.cs
private List<string> guys;
[BeforeScenario]
public void Setup(){
guys = new List<string>();
var fake = new Mock<IRepository>();
fake.Setup(x=>x.GetGuys()).Returns(guys);
ScenarioContext.Current.Set(fake)
ScenarioContext.Current.Set(fake.Object);
}
[Given("a guy with the name '(.*)' exists"]
public void a(string guy){
guys.Add(guy);
var fake = ScenarioContext.Current.Get<Mock<IRepository>>();
}
GuyController.cs
When["I hit the guy page"]
public void x(){
var repository = ScenarioContext.Current.Get<IRepository>();
var controller = new GuyController(repository);
var result = controller.Index();
ScenarioContext.Current.Set(result);
}
, GuyController , , . IRepository . - REAL- IRepository , , , ScenarioContext IRepository.
, , . , , SpecFlow, .