-
Notifications
You must be signed in to change notification settings - Fork 7
Dependent Contexts
davidmfoley edited this page Sep 13, 2010
·
2 revisions
StorEvil will do simple constructor injection of dependent contexts.
What this means is that any parameters to the constructor of a context object will be created when the context class is created.
These context instances, like all others, are shared between any classes reference them.
You can have one context that depends on another, or share a context class that is not used to parse grammar between contexts.
In this example, the UserAssertions and AdminUserContext context classes use the UserTestContext to store the state of the system as each step is executed.
The UserTestContext will be created when either of these classes is created (when any line matches a method in either class).
[StorEvil.Context]
public class AdminUserContext {
public AdminUserContext(UserTestContext user) {
_user = user;
}
public void Given_user_has_superuser_privileges() {
...
}
}
[StorEvil.Context]
public class UserAssertions {
public UserAssertionContext(UserTestContext user) {
_user = user; // same instance as given to AdminUserContext... one instance per type, per scenario
}
public void Then_user_should_be_an_admin() {
Assert.IsTrue(_user.IsAdministrator);
}
}
public class UserTestContext {
public CurrentUserId { get; set; }
public bool IsAdministrator {get; set; }
}