private static ITestParameterBuilder GetOrCreateImpersonationDataTestParameter(IPatternScope scope) { ITestParameterBuilder parameterBuilder = scope.TestBuilder.GetParameter(ImpersonationDataParameterName); if (parameterBuilder == null) { // Add a new test parameter for some ImpersonationData. // This makes the test data-driven. ITestDataContextBuilder parameterDataContextBuilder = scope.TestDataContextBuilder.CreateChild(); parameterBuilder = scope.TestBuilder.CreateParameter(ImpersonationDataParameterName, null, parameterDataContextBuilder); // When the ImpersonationData is bound to the parameter before the initialization phase // of the test, add it to the test instance state so we can access it later. parameterBuilder.TestParameterActions.BindTestParameterChain.After((state, obj) => { var data = (ImpersonationData)obj; state.Data.SetValue(ImpersonationDataKey, data); state.AddNameSuffix(data.GetChildTestSuffix()); }); scope.TestBuilder.TestInstanceActions.RunTestInstanceBodyChain.Around((state, inner) => { ImpersonationData data = state.Data.GetValue(ImpersonationDataKey); using (new Impersonation(data.UserName, data.Domain ?? String.Empty, data.Password)) { return(inner(state)); } }); } return(parameterBuilder); }
/// <inheritdoc /> public IPatternScope CreateChildTestScope(string name, ICodeElementInfo codeElement) { if (!CanAddChildTest) { throw new PatternUsageErrorException("Cannot add child tests to the test within this scope."); } ITestDataContextBuilder childTestDataContextBuilder = testDataContextBuilder.CreateChild(); ITestBuilder childTestBuilder = testBuilder.CreateChild(name, codeElement, childTestDataContextBuilder); return(CreateScope(codeElement, childTestBuilder, null, childTestDataContextBuilder, true)); }
/// <inheritdoc /> public IPatternScope CreateTestParameterScope(string name, ICodeElementInfo codeElement) { if (!CanAddTestParameter) { throw new InvalidOperationException("Cannot add test parameters to the test within this scope."); } ITestDataContextBuilder childTestDataContextBuilder = testDataContextBuilder.CreateChild(); ITestParameterBuilder testParameterBuilder = testBuilder.CreateParameter(name, codeElement, childTestDataContextBuilder); return(CreateScope(codeElement, testBuilder, testParameterBuilder, childTestDataContextBuilder, true)); }
/// <inheritdoc /> public ITestBuilder CreateChild(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder) { if (name == null) { throw new ArgumentNullException("name"); } if (dataContextBuilder == null) { throw new ArgumentNullException("dataContextBuilder"); } PatternTest childTest = new PatternTest(name, codeElement, dataContextBuilder.ToPatternTestDataContext()); test.AddChild(childTest); return(new DefaultTestBuilder(GetTestModelBuilder(), childTest)); }
/// <summary> /// Creates a new scope. /// </summary> /// <param name="evaluator">The pattern evaluator.</param> /// <param name="codeElement">The code element associated with the scope, or null if none.</param> /// <param name="testBuilder">The test builder in scope.</param> /// <param name="testParameterBuilder">The test parameter builder in scope, or null if none.</param> /// <param name="testDataContextBuilder">The test data context builder.</param> /// <param name="isDeclaration">True if the scope represents the initial point of declaration /// of a given test component.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="evaluator"/>, /// <paramref name="testBuilder"/> or <paramref name="testDataContextBuilder"/> is null.</exception> public DefaultPatternScope(IPatternEvaluator evaluator, ICodeElementInfo codeElement, ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder, ITestDataContextBuilder testDataContextBuilder, bool isDeclaration) { if (evaluator == null) throw new ArgumentNullException("evaluator"); if (testBuilder == null) throw new ArgumentNullException("testBuilder"); if (testDataContextBuilder == null) throw new ArgumentNullException("testDataContextBuilder"); this.evaluator = evaluator; this.codeElement = codeElement; this.testBuilder = testBuilder; this.testParameterBuilder = testParameterBuilder; this.testDataContextBuilder = testDataContextBuilder; this.isDeclaration = isDeclaration; }
/// <summary> /// Creates a new scope. /// </summary> /// <param name="evaluator">The pattern evaluator.</param> /// <param name="codeElement">The code element associated with the scope, or null if none.</param> /// <param name="testBuilder">The test builder in scope.</param> /// <param name="testParameterBuilder">The test parameter builder in scope, or null if none.</param> /// <param name="testDataContextBuilder">The test data context builder.</param> /// <param name="isDeclaration">True if the scope represents the initial point of declaration /// of a given test component.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="evaluator"/>, /// <paramref name="testBuilder"/> or <paramref name="testDataContextBuilder"/> is null.</exception> public DefaultPatternScope(IPatternEvaluator evaluator, ICodeElementInfo codeElement, ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder, ITestDataContextBuilder testDataContextBuilder, bool isDeclaration) { if (evaluator == null) { throw new ArgumentNullException("evaluator"); } if (testBuilder == null) { throw new ArgumentNullException("testBuilder"); } if (testDataContextBuilder == null) { throw new ArgumentNullException("testDataContextBuilder"); } this.evaluator = evaluator; this.codeElement = codeElement; this.testBuilder = testBuilder; this.testParameterBuilder = testParameterBuilder; this.testDataContextBuilder = testDataContextBuilder; this.isDeclaration = isDeclaration; }
/// <inheritdoc /> public ITestParameterBuilder CreateParameter(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder) { if (name == null) throw new ArgumentNullException("name"); if (dataContextBuilder == null) throw new ArgumentNullException("dataContextBuilder"); PatternTestParameter testParameter = new PatternTestParameter(name, codeElement, dataContextBuilder.ToPatternTestDataContext()); test.AddParameter(testParameter); return new DefaultTestParameterBuilder(GetTestModelBuilder(), testParameter); }
public ITestParameterBuilder CreateParameter(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder) { throw new NotImplementedException(); }
public ITestParameterBuilder CreateParameter(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder) { throw new NotImplementedException(); }
/// <inheritdoc /> public IPatternScope CreateChildTestDataContextScope(ICodeElementInfo codeElement) { ITestDataContextBuilder childTestDataContextBuilder = testDataContextBuilder.CreateChild(); return(CreateScope(codeElement, testBuilder, testParameterBuilder, childTestDataContextBuilder, false)); }
/// <inheritdoc /> public IPatternScope CreateScope(ICodeElementInfo codeElement, ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder, ITestDataContextBuilder testDataContextBuilder, bool isDeclaration) { var scope = new DefaultPatternScope(evaluator, codeElement, testBuilder, testParameterBuilder, testDataContextBuilder, isDeclaration); evaluator.RegisterScope(scope); return(scope); }
/// <inheritdoc /> public ITestParameterBuilder CreateParameter(string name, ICodeElementInfo codeElement, ITestDataContextBuilder dataContextBuilder) { if (name == null) { throw new ArgumentNullException("name"); } if (dataContextBuilder == null) { throw new ArgumentNullException("dataContextBuilder"); } PatternTestParameter testParameter = new PatternTestParameter(name, codeElement, dataContextBuilder.ToPatternTestDataContext()); test.AddParameter(testParameter); return(new DefaultTestParameterBuilder(GetTestModelBuilder(), testParameter)); }
/// <inheritdoc /> public IPatternScope CreateScope(ICodeElementInfo codeElement, ITestBuilder testBuilder, ITestParameterBuilder testParameterBuilder, ITestDataContextBuilder testDataContextBuilder, bool isDeclaration) { var scope = new DefaultPatternScope(evaluator, codeElement, testBuilder, testParameterBuilder, testDataContextBuilder, isDeclaration); evaluator.RegisterScope(scope); return scope; }