Last active
August 15, 2016 13:06
-
-
Save gasparnagy/cc4a3b3eef671a2f2246eb633f4ca7af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class CalculatorSteps | |
{ | |
private readonly CalculatorController controller = new CalculatorController(); | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ControllerContext | |
{ | |
public CalculatorController Controller { get; } = new CalculatorController(); | |
... | |
} | |
[Binding] | |
public class CalculatorSteps | |
{ | |
public CalculatorSteps(ControllerContext controllerContext) | |
{ | |
... //save controllerContext to an instance field | |
} | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ControllerContext | |
{ | |
public CalculatorController Controller { get; private set; } | |
public ControllerContext() | |
{ | |
var containerBuilder = Dependencies.CreateContainerBuilder(); // invoke runtime dependency configuration | |
//TODO: apply test-specific customizations if needed | |
var container = containerBuilder.Build(); // create container | |
Controller = container.Resolve<CalculatorController>(); | |
} | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Binding] | |
public class DependencyConfiguration | |
{ | |
private IObjectContainer objectContainer; | |
public DependencyConfiguration(IObjectContainer objectContainer) | |
{ | |
this.objectContainer = objectContainer; | |
} | |
[BeforeScenario(Order = 0)] | |
public void ConfigureDependencies() | |
{ | |
if (...) | |
objectContainer.RegisterTypeAs<RealDbDriver, IControllerDriver>(); | |
else | |
objectContainer.RegisterTypeAs<StubDbDriver, IControllerDriver>(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class TestDependencies | |
{ | |
[ScenarioDependencies] | |
public static ContainerBuilder CreateContainerBuilder() | |
{ | |
// create container with the runtime dependencies | |
var builder = Dependencies.CreateContainerBuilder(); | |
//TODO: add customizations, stubs required for testing | |
//auto-reg all types from our assembly | |
//builder.RegisterAssemblyTypes(typeof(TestDependencies).Assembly).SingleInstance(); | |
//auto-reg all [Binding] types from our assembly | |
builder.RegisterTypes(typeof(TestDependencies).Assembly.GetTypes().Where(t => Attribute.IsDefined(t, typeof(BindingAttribute))).ToArray()).SingleInstance(); | |
return builder; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment