/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel" /> Test Double IoC container.</param> /// <returns> /// The System/Software Under Test. /// </returns> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("Feature: Calculator"); f.AppendLine("Scenario: Add two numbers"); f.AppendLine("Given a <first>:"); f.AppendLine("| first |"); f.AppendLine("| 1 |"); f.AppendLine("| 2 |"); f.AppendLine("When add a 10"); f.AppendLine("Then should have <result>:"); f.AppendLine("| result |"); f.AppendLine("| 11 |"); f.AppendLine("| 12 |"); f.AppendLine("Scenario: Subtract two numbers"); f.AppendLine(" Given a <first>:"); f.AppendLine(" | first |"); f.AppendLine(" | 11 |"); f.AppendLine(" | 12 |"); f.AppendLine(" When subtract a 10"); f.AppendLine(" Then should have <result>:"); f.AppendLine(" | result |"); f.AppendLine(" | 1 |"); f.AppendLine(" | 0 |"); return(LexerFeature.Create(f.ToString())); }
/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel" /> Test Double IoC container.</param> /// <returns> /// The System/Software Under Test. /// </returns> protected override IFixtureMethods Given(IFixtureKernel kernel) { var gherkin = new StringBuilder(); gherkin.AppendLine("Feature: Fixture Method Scenario Outline No Steps"); gherkin.AppendLine("# ScenarioId: 001"); gherkin.AppendLine("Scenario: Placeholder"); gherkin.AppendLine("Given a placeholder"); gherkin.AppendLine("# ScenarioId: 002"); gherkin.AppendLine("Scenario Outline: Withdraw fixed amount"); gherkin.AppendLine("Where: In credit"); gherkin.AppendLine("test cases where the account is in credit"); gherkin.AppendLine("| balance | withdrawal | received | remaining |"); gherkin.AppendLine("| 500m | 50m | 50m | 450m |"); gherkin.AppendLine("| 500m | 100m | 100m | 400m |"); gherkin.AppendLine("| 500m | 200m | 200m | 300m |"); var lexer = Lexer.For("c:\test.feature", new StringReader(gherkin.ToString())); var ast = lexer.Parse(); kernel.Bind(ast.Scenarios[1]); Get <IGherkinScenario>().Gherkin.ForAll(Console.WriteLine); kernel.Load(ctx => new FixtureMethodsBindings(WithTestRunner())); return(base.Given(kernel)); }
/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel" /> Test Double IoC container.</param> /// <returns> /// The System/Software Under Test. /// </returns> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("Feature: Calculator"); f.AppendLine("Scenario Outline: Add two numbers"); f.AppendLine(" System should add two"); f.AppendLine(" numbers"); f.AppendLine("Given a <first>"); f.AppendLine("When add a <second>"); f.AppendLine("Then should have <result>"); f.AppendLine("Examples:"); f.AppendLine("| first | second | result |"); f.AppendLine("| 1 | 2 | 3 |"); f.AppendLine("| 1 | 3 | 4 |"); f.AppendLine("Scenario Outline: Subtract two numbers"); f.AppendLine(" Given a <first>:"); f.AppendLine(" When subtract a <second>"); f.AppendLine(" Then should have <result>:"); f.AppendLine("Examples:"); f.AppendLine(" | first | second | result |"); f.AppendLine(" | 11 | 10 | 1 |"); f.AppendLine(" | 12 | 10 | 2 |"); return(LexerFeature.Create(f.ToString())); }
public static T BindDummy <T>(this IFixtureKernel kernel) where T : class { var result = TestDouble.For <T>().Dummy(); kernel.Bind(result); return(result); }
public static Mock <T> BindMock <T>(this IFixtureKernel kernel) where T : class { var result = new Mock <T>(); kernel.Bind(result.Object); return(result); }
/// <summary> /// Binds the specified factory into the underlying IoC container. /// </summary> /// <typeparam name="T">The type of interface to add to the underlying IoC container.</typeparam> /// <param name="kernel">The kernel.</param> /// <param name="factory">The factory.</param> /// <returns>An object that support the <typeparamref name="T"/> interface.</returns> public static T Bind <T>(this IFixtureKernel kernel, Func <IFixtureKernel, T> factory) where T : class { var result = factory(kernel); kernel.Bind(result); return(result); }
public static Mock <T> BindMock <T>(this IFixtureKernel kernel, Action <Mock <T> > behaviour) where T : class { var result = kernel.BindMock <T>(); behaviour(result); return(result); }
/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel" /> Test Double IoC container.</param> /// <returns> /// The System/Software Under Test. /// </returns> protected override ISpockFixture Given(IFixtureKernel kernel) { var options = new Mock <ISpockOptions>(); options.SetupGet(x => x.TestRunner).Returns(TestRunner.NUnit); var result = Lexer.For(options.Object).Parse(GherkinFactory.Create(Gherkin())); result.Spock().ForAll(Console.WriteLine); return(result); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("Feature: Calculator"); f.AppendLine("In order to avoid silly mistakes"); f.AppendLine("as a math idiot"); f.AppendLine("I want to be told the sum of two numbers"); return(LexerFeature.Create(f.ToString())); }
public static ITestSpy <T, TIndirectOutput> ReplaceWithTestSpy <T, TIndirectOutput>( this IFixtureKernel kernel, Expression <Action <T> > expression) where T : class where TIndirectOutput : class { var result = TestDouble.Spy <T, TIndirectOutput>(expression); kernel.Bind(result.Dependency); return(result); }
public static ISaboteurVerify <T> ReplaceWithSaboteur <T, TException>( this IFixtureKernel kernel, Expression <Action <T> > expression) where T : class where TException : Exception, new() { var result = TestDouble.For <T>().Verifiable.Saboteur <TException>(expression); kernel.Bind(result.Dependency); return(result); }
/// <summary> /// Loads the specified bindings into the kernel. /// </summary> /// <param name="kernel">The kernel.</param> public void Load(IFixtureKernel kernel) { // ReSharper disable once RedundantBoolCompare kernel.Bind(TestDouble.Stub <ISpockOptions>(o => o.TestRunner == this.testRunner && o.SetIgnore == true)); kernel.BindDummy <IFixtureInvariants>(); kernel.BindDummy <IGherkinBlock>(); kernel.Bind <IMethods, ScenarioMethods>(); kernel.Bind <IBuilder <IFixtureMethods>, FixtureMethodBuilder>(); kernel.Bind(ctx => ctx.Get <FixtureMethodBuilder>().Build()); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("# language: fr"); f.AppendLine("Fonctionnalité: Calculator"); f.AppendLine(" Contexte: Set up initial state"); f.AppendLine(" Get the system in a state to do this"); f.AppendLine(" Soit the system is this"); f.AppendLine(" Et it is doing this"); return(LexerFeature.Create(f.ToString())); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("# language: en"); f.AppendLine("Feature: Calculator"); f.AppendLine(" Background: Set up initial state"); f.AppendLine(" Get the system in a state to do this"); f.AppendLine(" Given the system is this"); f.AppendLine(" And it is doing this"); return(LexerFeature.Create(f.ToString())); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("# language: fr"); f.AppendLine("Fonctionnalité: Calculator"); f.AppendLine("Scénario: Add two numbers"); f.AppendLine("Soit a <first>:"); f.AppendLine("| first |"); f.AppendLine("| 1 |"); f.AppendLine("| 2 |"); f.AppendLine("Quand add a 10"); f.AppendLine("Alors should have <result>:"); f.AppendLine("| result |"); f.AppendLine("| 11 |"); f.AppendLine("| 12 |"); return(LexerFeature.Create(f.ToString())); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("Feature: Calculator"); f.AppendLine("Scenario: Add two numbers"); f.AppendLine("Given a <first>:"); f.AppendLine("| first |"); f.AppendLine("| 1 |"); f.AppendLine("| 2 |"); f.AppendLine("When add a 10"); f.AppendLine(" \"\"\""); f.AppendLine(" some text"); f.AppendLine(" here with spacing"); f.AppendLine(" \"\"\""); f.AppendLine(" And something else goes on"); f.AppendLine("Then should have result"); return(LexerFeature.Create(f.ToString())); }
/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel" /> Test Double IoC container.</param> /// <returns> /// The System/Software Under Test. /// </returns> protected override IFixtureMethods Given(IFixtureKernel kernel) { var gherkin = new StringBuilder(); gherkin.AppendLine("Feature: Fixture Method Scenario Outline No Steps"); gherkin.AppendLine("# ScenarioId: 000"); gherkin.AppendLine("Scenario: Placeholder"); gherkin.AppendLine("Given a placeholder"); gherkin.AppendLine("# ScenarioId: 001"); gherkin.AppendLine("Scenario: Successful withdrawal from an account in credit"); AddStep(gherkin); var lexer = Lexer.For("c:\test.feature", new StringReader(gherkin.ToString())); var ast = lexer.Parse(); kernel.Bind(ast.Scenarios[1]); Get <IGherkinScenario>().Gherkin.ForAll(Console.WriteLine); kernel.Load(ctx => new FixtureMethodsBindings(WithTestRunner())); return(base.Given(kernel)); }
/// <inheritdoc /> protected override IGherkinFeature Given(IFixtureKernel kernel) { var f = new StringBuilder(); f.AppendLine("@ category: Integration"); f.AppendLine("Feature: Calculator"); f.AppendLine("Scenario: Add two numbers"); f.AppendLine("Given a <first>:"); f.AppendLine("| first |"); f.AppendLine("| 1 |"); f.AppendLine("| 2 |"); f.AppendLine("And the system is in this state"); f.AppendLine("# And this is commented out"); f.AppendLine("And the system is also in this state"); f.AppendLine("But not in this state"); f.AppendLine("When add a 10"); f.AppendLine("Then should have <result>:"); f.AppendLine("| result |"); f.AppendLine("| 11 |"); f.AppendLine("| 12 |"); return(LexerFeature.Create(f.ToString())); }
/// <summary> /// Arrange all necessary preconditions and inputs. /// </summary> /// <param name="kernel">The <see cref="IFixtureKernel"/> Test Double IoC container.</param> /// <returns>The System/Software Under Test.</returns> protected virtual TSut Given(IFixtureKernel kernel) { return(this.Get <TSut>()); }
/// <summary> /// Initializes a new instance of the <see cref="GivenWhenThen{TSut}" /> class. /// </summary> /// <param name="fixtureIoC">The fixture IoC container.</param> protected GivenWhenThen(IFixtureKernel fixtureIoC) : base(fixtureIoC) { }
/// <summary> /// Initializes a new instance of the <see cref="GivenWhenThenBase" /> class. /// </summary> /// <param name="kernel">The fixture IoC kernel container.</param> protected GivenWhenThenBase(IFixtureKernel kernel) { this.kernel = kernel; }
/// <summary> /// Extension point for sub-classes to bind to the IoC kernel. /// </summary> /// <param name="container">The fixture kernel IoC container.</param> protected virtual void Background(IFixtureKernel container) { }
/// <summary> /// Loads the bindings created by the factory into the underlying IoC container. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="factory">The factory.</param> public static void Load(this IFixtureKernel kernel, Func <IFixtureKernel, IFixtureBindings> factory) { Load(kernel, factory(kernel)); }
/// <summary> /// Binds the test double builder into the underlying IoC container. /// </summary> /// <typeparam name="T">The type of interface to add to the underlying IoC container.</typeparam> /// <param name="kernel">The kernel.</param> /// <param name="builder">The test double builder.</param> public static void BindBuilder <T>(this IFixtureKernel kernel, ITestDoubleBuilder <T> builder) where T : class { kernel.Bind(builder.Build()); }
/// <summary> /// Loads the specified bindings into the underlying IoC container. /// </summary> /// <param name="kernel">The kernel.</param> /// <param name="bindings">The bindings.</param> public static void Load(this IFixtureKernel kernel, IFixtureBindings bindings) { bindings.Load(kernel); }
/// <summary> /// Binds the interception point into the IoC container. /// </summary> /// <typeparam name="T">The object that is to be faked.</typeparam> /// <param name="kernel">The underlying IoC container kernel.</param> /// <param name="item">The interaction point.</param> /// <remarks> /// Will un-register any existing bindings for the <typeparamref name="T" /> and register /// the interaction points fake object. /// </remarks> public static void BindPoint <T>(this IFixtureKernel kernel, ITestDoubleInteractionPointFor <T> item) where T : class { kernel.BindSingleton(item.Dependency); }
/// <summary> /// Loads the bindings into the underlying IoC container. /// </summary> /// <typeparam name="TBindings">The bindings.</typeparam> /// <param name="kernel">The kernel.</param> public static void Load <TBindings>(this IFixtureKernel kernel) where TBindings : IFixtureBindings, new() { Load(kernel, new TBindings()); }