protected void BuildTestActions(ITestBuilder <TScenario> builder) { foreach (var configurator in _testActionConfigurators) { configurator.Configure(builder); } }
/// <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); }
/// <summary> /// Applies semantic actions to the assembly-level test to estalish its runtime behavior. /// </summary> /// <remarks> /// <para> /// This method is called after <see cref="InitializeAssemblyTest" />. /// </para> /// <para> /// The default behavior for a <see cref="TestAssemblyPatternAttribute" /> /// is to configure the test actions as follows: /// <list type="bullet"> /// <item><see cref="PatternTestActions.InitializeTestChain" />: Reset the <see cref="TestAssemblyExecutionParameters" /> /// to defaults.</item> /// </list> /// </para> /// <para> /// You can override this method to change the semantics as required. /// </para> /// </remarks> /// <param name="testBuilder">The test builder.</param> /// <param name="assembly">The assembly.</param> protected virtual void SetTestSemantics(ITestBuilder testBuilder, IAssemblyInfo assembly) { testBuilder.TestActions.InitializeTestChain.After( delegate(PatternTestState testInstanceState) { TestAssemblyExecutionParameters.Reset(); }); }
public AgentTests() { client = new Mock <IHttpRequestClient>(); client.Setup(c => c.MakeRequest(It.IsAny <HttpRequestMessage>())) .Callback <HttpRequestMessage>(r => message = r); builder = TestBuilderFactory.Create("/test", client.Object); }
/// <summary> /// Applies semantic actions to a test to estalish its runtime behavior. /// </summary> /// <remarks> /// <para> /// This method is called after <see cref="InitializeTest" />. /// </para> /// <para> /// The default behavior for a <see cref="TestTypePatternAttribute" /> /// is to configure the test actions as follows: /// <list type="bullet"> /// <item><see cref="PatternTestInstanceActions.BeforeTestInstanceChain" />: Set the /// fixture instance name and <see cref="PatternTestInstanceState.FixtureType" />.</item> /// <item><see cref="PatternTestInstanceActions.InitializeTestInstanceChain" />: Create /// the fixture instance and set the <see cref="PatternTestInstanceState.FixtureInstance" /> /// property accordingly.</item> /// <item><see cref="PatternTestInstanceActions.DisposeTestInstanceChain" />: If the fixture type /// implements <see cref="IDisposable" />, disposes the fixture instance.</item> /// <item><see cref="PatternTestInstanceActions.DecorateChildTestChain" />: Decorates the child's /// <see cref="PatternTestInstanceActions.BeforeTestInstanceChain" /> to set its <see cref="PatternTestInstanceState.FixtureInstance" /> /// and <see cref="PatternTestInstanceState.FixtureType" /> properties to those /// of the fixture. The child test may override these values later on but this /// is a reasonable default setting for test methods within a fixture.</item> /// </list> /// </para> /// <para> /// You can override this method to change the semantics as required. /// </para> /// </remarks> /// <param name="testBuilder">The test builder.</param> /// <param name="type">The test type.</param> protected virtual void SetTestSemantics(ITestBuilder testBuilder, ITypeInfo type) { testBuilder.TestInstanceActions.BeforeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { ObjectCreationSpec spec = testInstanceState.GetFixtureObjectCreationSpec(type); testInstanceState.Data.SetValue(FixtureObjectCreationSpecKey, spec); testInstanceState.FixtureType = spec.ResolvedType; if (!testInstanceState.IsReusingPrimaryTestStep) { testInstanceState.NameBase = spec.Format(testInstanceState.NameBase, testInstanceState.Formatter); } }); testBuilder.TestInstanceActions.InitializeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { if (!type.IsAbstract && !type.IsInterface) { ObjectCreationSpec spec = testInstanceState.Data.GetValue(FixtureObjectCreationSpecKey); testInstanceState.FixtureInstance = spec.CreateInstance(); } }); testBuilder.TestInstanceActions.DisposeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { IDisposable dispose = testInstanceState.FixtureInstance as IDisposable; if (dispose != null) { dispose.Dispose(); } }); testBuilder.TestInstanceActions.DecorateChildTestChain.After( delegate(PatternTestInstanceState testInstanceState, PatternTestActions decoratedTestActions) { decoratedTestActions.TestInstanceActions.BeforeTestInstanceChain.Before(delegate(PatternTestInstanceState childTestInstanceState) { IMemberInfo member = childTestInstanceState.Test.CodeElement as IMemberInfo; if (member != null) { ITypeInfo memberDeclaringType = member.DeclaringType; if (memberDeclaringType != null) { if (type.Equals(memberDeclaringType) || type.IsSubclassOf(memberDeclaringType)) { childTestInstanceState.FixtureType = testInstanceState.FixtureType; childTestInstanceState.FixtureInstance = testInstanceState.FixtureInstance; } } } }); }); }
public SchoolClassBuilder(IClassAssigner classAssigner, IPersonCreator personCreator, ITestBuilder testBuilder, ICourseManager courseManager, ITestAssigner testAssigner) { terms = new List <Term>(); classes = new List <SchoolClass>(); this.classAssigner = classAssigner; this.personCreator = personCreator; this.testBuilder = testBuilder; this.courseManager = courseManager; this.testAssigner = testAssigner; }
/// <inheritdoc /> protected override void SetTestSemantics(ITestBuilder testBuilder, ITypeInfo type) { testBuilder.TestActions.TestInstanceActions.BeforeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { if (testInstanceState.FixtureType != null) ThrowUsageErrorException("There appears to already be a fixture defined for the assembly."); }); base.SetTestSemantics(testBuilder, type); }
/// <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)); }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="testModel">The underlying test model.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> /// or <paramref name="testModel"/> is null.</exception> public DefaultTestModelBuilder(IReflectionPolicy reflectionPolicy, PatternTestModel testModel) { if (reflectionPolicy == null) throw new ArgumentNullException("reflectionPolicy"); if (testModel == null) throw new ArgumentNullException("testModel"); this.reflectionPolicy = reflectionPolicy; this.testModel = testModel; rootTestBuilder = new DefaultTestBuilder(this, testModel.RootTest); }
/// <inheritdoc /> public override void Consume(IPatternScope containingScope, ICodeElementInfo codeElement, bool skipChildren) { //TODO: Review: Issue 762: Shouldn't the base method be invoked here? //base.Consume(containingScope, codeElement, skipChildren); var type = codeElement as ITypeInfo; Validate(containingScope, type); ITestBuilder assemblyTest = containingScope.TestBuilder; InitializeTest(containingScope, type); SetTestSemantics(assemblyTest, type); }
/// <inheritdoc /> protected override void SetTestSemantics(ITestBuilder testBuilder, ITypeInfo type) { testBuilder.TestActions.TestInstanceActions.BeforeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { if (testInstanceState.FixtureType != null) { ThrowUsageErrorException("There appears to already be a fixture defined for the assembly."); } }); base.SetTestSemantics(testBuilder, type); }
/// <summary> /// Creates a test model builder. /// </summary> /// <param name="reflectionPolicy">The reflection policy.</param> /// <param name="testModel">The underlying test model.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="reflectionPolicy"/> /// or <paramref name="testModel"/> is null.</exception> public DefaultTestModelBuilder(IReflectionPolicy reflectionPolicy, PatternTestModel testModel) { if (reflectionPolicy == null) { throw new ArgumentNullException("reflectionPolicy"); } if (testModel == null) { throw new ArgumentNullException("testModel"); } this.reflectionPolicy = reflectionPolicy; this.testModel = testModel; rootTestBuilder = new DefaultTestBuilder(this, testModel.RootTest); }
public AssertionTests() { message = new HttpResponseMessage(); message.StatusCode = HttpStatusCode.OK; message.Content = new StringContent("Hello World"); message.Headers.Add("TestHeader", "Test"); user = new User { Name = "Peter", Age = 32, Id = 1 }; clientMock = new Mock <IHttpRequestClient>(); clientMock.Setup(c => c.MakeRequest(It.IsAny <HttpRequestMessage>())).Returns(() => message); builder = TestBuilderFactory.Create("/test", clientMock.Object); builder.SetMethod(HttpMethod.Get); }
/// <summary> /// Applies semantic actions to a test to estalish its runtime behavior. /// </summary> /// <remarks> /// <para> /// This method is called after <see cref="InitializeTest" />. /// </para> /// <para> /// The default behavior for a <see cref="TestMethodPatternAttribute" /> /// is to configure the test actions as follows: /// <list type="bullet"> /// <item><see cref="PatternTestInstanceActions.BeforeTestInstanceChain" />: Set the /// test step name, <see cref="PatternTestInstanceState.TestMethod" /> and /// <see cref="PatternTestInstanceState.TestArguments" /> based on any values bound /// to the test method's generic parameter and method parameter slots.</item> /// <item><see cref="PatternTestInstanceActions.ExecuteTestInstanceChain" />: Invoke the method.</item> /// </list> /// </para> /// <para> /// You can override this method to change the semantics as required. /// </para> /// </remarks> /// <param name="testBuilder">The test builder.</param> /// <param name="method">The test method.</param> protected virtual void SetTestSemantics(ITestBuilder testBuilder, IMethodInfo method) { testBuilder.TestInstanceActions.BeforeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { MethodInvocationSpec spec = testInstanceState.GetTestMethodInvocationSpec(method); testInstanceState.TestMethod = spec.ResolvedMethod; testInstanceState.TestArguments = spec.ResolvedArguments; if (!testInstanceState.IsReusingPrimaryTestStep) { testInstanceState.NameBase = spec.Format(testInstanceState.NameBase, testInstanceState.Formatter); } }); testBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(Execute); }
/// <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; }
private static ITestBuilder GetBuilder(MethodInfo method) { if (builders == null) { InitBuilders(); } object[] attributes = method.GetCustomAttributes(false); foreach (object attribute in attributes) { ITestBuilder builder = (ITestBuilder)builders[attribute.GetType()]; if (builder != null) { return(builder); } } return(normalBuilder); }
public TestsController_GeneratingTests() { generators = new IExerciseGenerator[] { new OpenQuestionExerciseGenerator(), new MatchingQuestionExerciseGenerator(), new ChoiceQuestionExerciseGenerator() }; exercises = new Exercise[0]; cards = new List <Card> { new Card("t1", "d1", "admin", id), new Card("t2", "d2", "admin", id) }; collection = new Collection("coll", "admin", id); testQuery = new TestQueryDto(id, new List <TestBlockDto> { new TestBlockDto(generators[0].GetTypeCaption(), 1), new TestBlockDto(generators[1].GetTypeCaption(), 2), new TestBlockDto(generators[2].GetTypeCaption(), 3) }, null); fakeStorage = A.Fake <IStorage>(); fakeTestStorage = A.Fake <ITestStorage>(); factory = A.Fake <ITestBuilderFactory>(); fakeBuilder = A.Fake <ITestBuilder>(); A.CallTo(() => fakeStorage.FindCollection(A <Guid> ._, A <CancellationToken> ._)).Returns(collection); A.CallTo(() => fakeStorage.GetCollectionCards(id, A <CancellationToken> ._)).Returns(cards); A.CallTo(() => fakeBuilder.Build()).Returns(exercises); A.CallTo(() => fakeBuilder.WithGenerator(A <IExerciseGenerator> ._, A <int> ._)).Returns(fakeBuilder); A.CallTo(() => factory.GetBuilder(cards, A <ICardsSelector> ._)).Returns(fakeBuilder); controller = new TestsController(fakeStorage, fakeTestStorage, factory, generators, null); ControllerTestsHelper.AttachUserToControllerContext(controller, "admin"); }
/// <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> /// Make a test case from a given fixture type and method /// </summary> /// <param name="fixtureType">The fixture type</param> /// <param name="method">MethodInfo for the particular method</param> /// <returns>A test case or null</returns> public static TestCase Make(Type fixtureType, MethodInfo method) { TestCase testCase = null; if (Reflect.HasTestAttribute(method) || Reflect.IsObsoleteTestMethod(method)) { if (Reflect.IsTestMethodSignatureCorrect(method)) { ITestBuilder builder = GetBuilder(method); testCase = builder.Make(fixtureType, method); if (Reflect.HasIgnoreAttribute(method)) { testCase.ShouldRun = false; testCase.IgnoreReason = Reflect.GetIgnoreReason(method); } if (Reflect.HasCategoryAttribute(method)) { IList categories = Reflect.GetCategories(method); CategoryManager.Add(categories); testCase.Categories = categories; } testCase.IsExplicit = Reflect.HasExplicitAttribute(method); testCase.Description = Reflect.GetDescription(method); } else { testCase = new NotRunnableTestCase(method); } } return(testCase); }
public TestDirector(ITestBuilder builder) { this.builder = builder; }
public AssemblyLoader(ITestBuilder testBuilder) { _testBuilder = testBuilder; }
/// <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; }
public void Generate(IList<PropertyWithName> props, string baseSaveDirectory, RunConfig config) { var dir = Path.Combine(baseSaveDirectory, config.Directory); if(!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } clientBuilder = config.HttpBuilder; taskBuilder = config.TaskBuilder; testBuilder = config.TestBuilder; variables = config.Variables; var cu = CompilationUnit(); cu = cu.AddUsing("System").WithLeadingTrivia(GeneratorBase.GetLicenseComment()); cu = cu.AddUsings(new string[] { "System.Threading.Tasks", "Newtonsoft.Json", "Newtonsoft.Json.Linq" }); cu = cu.AddUsings(clientBuilder.Namespace); cu = cu.AddUsings(testBuilder.Namespaces); if(String.Compare(variables.GetValue("IsUWP"), "1", true) == 0) { cu = cu.AddUsing("System.Runtime.InteropServices"); } var namesp = NamespaceDeclaration(IdentifierName("Sannel.House.ServerSDK.Tests")); var @class = ClassDeclaration("ServerContextTests") .AddModifiers(Token(SyntaxKind.PublicKeyword), Token(SyntaxKind.PartialKeyword)); foreach(var prop in props) { @class = addType(prop, @class); } namesp = namesp.AddMembers(@class); cu = cu.AddMembers(namesp).NormalizeWhitespace("\t", true); using(var writer = new StreamWriter(File.OpenWrite(Path.Combine(dir, config.FileName)))) { cu.WriteTo(writer); } }
public void Configure(ITestBuilder <TScenario> builder) { var action = new SendTestAction <TScenario, TMessage>(_endpointAccessor, _message, _callback); builder.AddTestAction(action); }
public TestOptions(ITestBuilder builder) : base(builder) { }
/// <summary> /// Applies semantic actions to a test to estalish its runtime behavior. /// </summary> /// <remarks> /// <para> /// This method is called after <see cref="InitializeTest" />. /// </para> /// <para> /// The default behavior for a <see cref="TestMethodPatternAttribute" /> /// is to configure the test actions as follows: /// <list type="bullet"> /// <item><see cref="PatternTestInstanceActions.BeforeTestInstanceChain" />: Set the /// test step name, <see cref="PatternTestInstanceState.TestMethod" /> and /// <see cref="PatternTestInstanceState.TestArguments" /> based on any values bound /// to the test method's generic parameter and method parameter slots.</item> /// <item><see cref="PatternTestInstanceActions.ExecuteTestInstanceChain" />: Invoke the method.</item> /// </list> /// </para> /// <para> /// You can override this method to change the semantics as required. /// </para> /// </remarks> /// <param name="testBuilder">The test builder.</param> /// <param name="method">The test method.</param> protected virtual void SetTestSemantics(ITestBuilder testBuilder, IMethodInfo method) { testBuilder.TestInstanceActions.BeforeTestInstanceChain.After( delegate(PatternTestInstanceState testInstanceState) { MethodInvocationSpec spec = testInstanceState.GetTestMethodInvocationSpec(method); testInstanceState.TestMethod = spec.ResolvedMethod; testInstanceState.TestArguments = spec.ResolvedArguments; if (!testInstanceState.IsReusingPrimaryTestStep) testInstanceState.NameBase = spec.Format(testInstanceState.NameBase, testInstanceState.Formatter); }); testBuilder.TestInstanceActions.ExecuteTestInstanceChain.After(Execute); }