public string FullyQualifiedApplicationPath(ITestContext testContext) { //Return variable declaration var appPath = string.Empty; //Getting the current context of HTTP request var context = testContext.HttpContext; //Checking the current context content if (context != null) { //Formatting the fully qualified website url/name appPath = string.Format("{0}://{1}{2}{3}", context.Request.Url.Scheme, context.Request.Url.Host, context.Request.Url.Port == 80 ? string.Empty : ":" + context.Request.Url.Port, context.Request.ApplicationPath); } if (!appPath.EndsWith("/")) appPath += "/"; return appPath; }
public void Test(ITestContext context) { if (this.url.IsNullOrEmpty() || this.url == "/" || this.url == "~" || this.url == "~/") { this.url = this.FullyQualifiedApplicationPath(context); } if (this.action.IsNullOrEmpty()) { throw new ApplicationException(Errors.UrlAndActionCannotBeEmpty); } this.service = new WebApiService { Timeout = this.timeout }; try { var result = this.arguments == null ? this.service.Get<object>(this.url, this.action) : this.service.Get<object>(this.url, this.action, this.arguments); } catch (WebApiException ex) { Assert.Fails(Errors.FailedToAccessService, ex.Message); } }
public override sealed void SetUp(ITestContext context) { // TODO -- later, make this thing be able to swap up the application under test _application = context.Retrieve<IApplicationUnderTest>(); beforeRunning(); }
protected override void execute(IWebElement element, IDictionary<string, object> cellValues, IStep step, ITestContext context) { // TODO -- StoryTeller needs to pull this all inside the Cell if (!cellValues.ContainsKey(_cell.Key)) { // already caught as a syntax error return; } var handler = ElementHandlers.FindHandler(element); var expectedValue = cellValues[_cell.Key]; var matchingHandler = handler as IMatchingHandler ?? new BasicMatchingHandler(handler, context); if (matchingHandler.MatchesData(element, expectedValue)) { context.IncrementRights(); } else { context.ResultsFor(step).MarkFailure(_cell.Key); context.IncrementWrongs(); } context.ResultsFor(step).SetActual(_cell.Key, handler.GetData(CurrentContext, element)); }
public override void SetUp(ITestContext context) { _settings = new DeploymentSettings("storyteller"); context.Store(_settings); _writer = new DeploymentWriter("storyteller"); }
public void ScenarioSetup(ITestContext testContext) { //Debug.WriteLine("ScenarioSetup Executes on thread creation"); //Debug.WriteLine("Exceptions here are not handled!"); Console.WriteLine($"Created Thread {testContext.ThreadId}"); }
public ResultsWriter(HtmlDocument document, ITestContext context) { _document = document; _context = context; _document.AddStyle(HtmlClasses.CSS()); }
public IEnumerable<Step> Scan(ITestContext testContext, MethodInfo method, Example example) { var executableAttribute = (ExecutableAttribute)method.GetCustomAttributes(typeof(ExecutableAttribute), false).FirstOrDefault(); if (executableAttribute == null) yield break; string stepTitle = executableAttribute.StepTitle; if (string.IsNullOrEmpty(stepTitle)) stepTitle = Configurator.Scanners.Humanize(method.Name); var stepAsserts = IsAssertingByAttribute(method); var methodParameters = method.GetParameters(); var inputs = new List<object>(); var inputPlaceholders = Regex.Matches(stepTitle, " <(\\w+)> "); for (int i = 0; i < inputPlaceholders.Count; i++) { var placeholder = inputPlaceholders[i].Groups[1].Value; for (int j = 0; j < example.Headers.Length; j++) { if (example.Values.ElementAt(j).MatchesName(placeholder)) { inputs.Add(example.GetValueOf(j, methodParameters[inputs.Count].ParameterType)); break; } } } var stepAction = StepActionFactory.GetStepAction(method, inputs.ToArray()); yield return new Step(stepAction, new StepTitle(stepTitle), stepAsserts, executableAttribute.ExecutionOrder, true, new List<StepArgument>()); }
public override void SetUp(ITestContext context) { RunningNode.Subscriptions.ClearAll(); MessageHistory.ClearAll(); InMemoryQueueManager.ClearAll(); FubuTransport.ApplyMessageHistoryWatching = true; }
public void ReadExpected(ITestContext context, IStep step, SetRow row) { Cell.ReadArgument(context, step, x => { row.Values[Cell.Key] = x; }); }
public void IterationSetup(ITestContext testContext) { //Debug.WriteLine("IterationSetup is executed before each ExecuteScenario call"); if (Random.Next(100) % 50 == 0) throw new Exception("2% error chance for testing"); }
public void WriteResults(StepResults results, ITestContext context) { if (!_cell.IsResult) { WritePreview(context); return; } var actual = results.HasActual(_cell.Key) ? results.GetActual(_cell.Key) : "MISSING"; if (results.IsInException(_cell.Key)) { Text("Error!"); AddClass(HtmlClasses.EXCEPTION); return; } if (results.IsFailure(_cell.Key)) { var expected = _step.Get(_cell.Key); string text = "{0}, but was '{1}'".ToFormat(expected, actual); Text(text); AddClass(HtmlClasses.FAIL); } else { Text(context.GetDisplay(actual)); AddClass(HtmlClasses.PASS); } }
public virtual IEnumerable<Scenario> Scan(ITestContext testContext) { Type scenarioType; string scenarioTitle; if (testContext.Examples == null) { var steps = ScanScenarioForSteps(testContext); scenarioType = testContext.TestObject.GetType(); scenarioTitle = _scenarioTitle ?? GetScenarioText(scenarioType); var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList(); yield return new Scenario(testContext.TestObject, orderedSteps, scenarioTitle, testContext.Tags); yield break; } scenarioType = testContext.TestObject.GetType(); scenarioTitle = _scenarioTitle ?? GetScenarioText(scenarioType); var scenarioId = Configurator.IdGenerator.GetScenarioId(); foreach (var example in testContext.Examples) { var steps = ScanScenarioForSteps(testContext, example); var orderedSteps = steps.OrderBy(o => o.ExecutionOrder).ThenBy(o => o.ExecutionSubOrder).ToList(); yield return new Scenario(scenarioId, testContext.TestObject, orderedSteps, scenarioTitle, example, testContext.Tags); } }
protected override void execute(IWebElement element, IDictionary<string, object> cellValues, IStep step, ITestContext context) { assertCondition(element.Enabled, DisabledElementMessage); assertCondition(element.Displayed, HiddenElementMessage); element.Click(); }
public void IterationTearDown(ITestContext testContext) { //Debug.WriteLine("IterationTearDown is executed each time after ExecuteScenario iteration is finished."); //Debug.WriteLine("It is also executed even when IterationSetup or ExecuteScenario fails"); if (Random.Next(100) % 25 == 0) throw new Exception("4% error chance for testing"); }
protected override void setUp(ITestContext context) { // Do any necessary bootstrapping just before a test run // ITestContext is effectively an IoC container, so you // might be registering your application services here _system = new SystemUnderTest(); context.Store(_system); }
public ITestContext Execute(ITestContext context) { var nunitContext = (NUnitTestFixtureDescriptor.Context)context; nunitContext.TestSetup(); myMethod.Invoke(nunitContext.Value, new object[0]); nunitContext.TestTeardown(); return null; }
/// <summary> /// IBaseAdapter method: called to execute a test. /// </summary> /// <param name="testElement">The test object to run</param> /// <param name="testContext">The Test conext for this test invocation</param> void IBaseAdapter.Run(ITestElement testElement, ITestContext testContext) { Trace.TraceInformation("Called DynamicHostAdapter.Run"); ITestAdapter realAdapter = GetTestAdapter(testElement); realAdapter.Run(testElement, testContext); }
public void Execute(IStep containerStep, ITestContext context) { context.PerformAction(containerStep, _before); containerStep.LeafFor(_leafName).AllSteps().Each(step => { context.RunStep(InnerGrammar, step); }); context.PerformAction(containerStep, _after); }
public override void RegisterServices(ITestContext context) { base.RegisterServices(context); var remoteGraph = new RemoteBehaviorGraph(TEST_APPLICATION_ROOT); context.Store(remoteGraph); context.Store(_runner); }
public override void SetUp(ITestContext context) { _system.Do<Window>(x => { _window = x; _window.Show(); }); }
public FixtureLibrary Build(ITestContext context) { _library = new FixtureLibrary(); context.VisitFixtures(this); return _library; }
public void WriteResults(ITestContext context) { context.ResultsFor(_step).ForExceptionText(writeExceptionText); rows().Each(row => writeResultsRow(row, context)); _headerRow.FirstChild().AddClass("left-cell"); }
/// <summary> /// Creates a wrapper for a <see cref="ITestContext" />. /// </summary> /// <param name="inner">The context to wrap.</param> /// <param name="sandbox">The sandbox to use, or null if none.</param> /// <exception cref="ArgumentNullException">Thrown if <paramref name="inner"/> is null.</exception> private TestContext(ITestContext inner, Sandbox sandbox) { if (inner == null) throw new ArgumentNullException("inner"); this.inner = inner; this.sandbox = sandbox; }
public void WriteResults(ITestContext context) { // This code Dru. If there's an exception in the results, call // back to the writeExceptionText(string) method to write in // the exception context.ResultsFor(_step).ForExceptionText(writeExceptionText); rows().Each(row => writeResultsRow(row, context)); }
public void RegisterServices(ITestContext context) { var remoteGraph = new RemoteBehaviorGraph(TEST_APPLICATION_ROOT); context.Store(remoteGraph); context.Store(_runner); context.Store(_application); }
internal static IEnumerable<Step> Scan(this IStepScanner scanner, ITestContext testContext) { // ToDo: this is rather hacky and is not DRY. Should think of a way to get rid of this return new ReflectiveScenarioScanner() .GetMethodsOfInterest(testContext.TestObject.GetType()) .SelectMany(x => scanner.Scan(testContext, x)) .OrderBy(s => s.ExecutionOrder) .ToList(); }
public PreviewWriter(HtmlDocument document, ITestContext context) { _document = document; _context = context; _document.AddStyle(HtmlClasses.CSS()); _document.Push("div").AddClass("main"); }
private IGrammar inner(ITestContext context) { if (_inner == null) { _inner = _import.FindGrammar(context); } return _inner; }
public Context(ITestContext parentContext, Type type, Dictionary<SpecialMethodKind, MethodInfo> specialMethods) { myParentContext = parentContext; mySpecialMethods = specialMethods; myValue = CreateInstance(type); MethodInfo methodInfo; if (mySpecialMethods.TryGetValue(SpecialMethodKind.Setup, out methodInfo)) methodInfo.Invoke(myValue, new object[0]); }
protected WhenProjectingToComplexTypeMembers(ITestContext <TOrmContext> context) : base(context) { }
public void ScenarioSetup(ITestContext testContext) { Debug.WriteLine("ScenarioSetup Executes on thread creation"); Debug.WriteLine("Exceptions here are not handled!"); }
public void WriteResults(ITestContext context) { context.ResultsFor(_step).ForExceptionText(text => Append(new ExceptionTag(text))); }
protected static void execute(int value, ITestContext context) { Count += value; Context = context; }
public override void Execute(IStep containerStep, ITestContext context) { Before(containerStep, context); _inner.Execute(containerStep, context); After(containerStep, context); }
protected WhenViewingProjectionPlans(ITestContext <TOrmContext> context) : base(context) { }
protected WhenIgnoringMembers(ITestContext <TOrmContext> context) : base(context) { }
protected DownloadUpload(ITestContext context, ITestOutputHelper testOutputHelper) : base(context, testOutputHelper) { this.savedChunksPackSize = this.context.Options.ChunksPackSize; }
public void Run() { var test = (PatternTest)testCommand.Test; TestContextCookie?parentContextCookie = null; try { if (parentContext != null) { parentContextCookie = parentContext.Enter(); } // The first time we call Run, we check whether the ApartmentState of the // Thread is correct. If it is not, then we start a new thread and reenter // with a flag set to skip initial processing. if (!reentered) { if (executor.progressMonitor.IsCanceled) { result = new TestResult(TestOutcome.Canceled); return; } if (!testCommand.AreDependenciesSatisfied()) { ITestContext context = testCommand.StartPrimaryChildStep(parentTestStep); context.LogWriter.Warnings.WriteLine("Skipped due to an unsatisfied test dependency."); result = context.FinishStep(TestOutcome.Skipped, null); return; } executor.progressMonitor.SetStatus(test.Name); if (test.ApartmentState != ApartmentState.Unknown && Thread.CurrentThread.GetApartmentState() != test.ApartmentState) { reentered = true; ThreadTask task = new TestEnvironmentAwareThreadTask("Test Runner " + test.ApartmentState, (GallioAction)Run, executor.environmentManager); task.ApartmentState = test.ApartmentState; task.Run(null); if (!task.Result.HasValue) { throw new ModelException( String.Format("Failed to perform action in thread with overridden apartment state {0}.", test.ApartmentState), task.Result.Exception); } return; } } // Actually run the test. // Yes, this is a monstrously long method due to the inlining optimzation to minimize stack depth. using (Sandbox sandbox = parentSandbox.CreateChild()) { using (new ProcessIsolation()) { using (sandbox.StartTimer(test.TimeoutFunc())) { TestOutcome outcome; PatternTestActions testActions = test.TestActions; if (testActionsDecorator != null) { outcome = testActionsDecorator(sandbox, ref testActions); } else { outcome = TestOutcome.Passed; } if (outcome.Status == TestStatus.Passed) { PatternTestStep primaryTestStep = new PatternTestStep(test, parentTestStep); PatternTestState testState = new PatternTestState(primaryTestStep, testActions, executor.converter, executor.formatter, testCommand.IsExplicit); bool invisibleTest = true; outcome = outcome.CombineWith(sandbox.Run(TestLog.Writer, new BeforeTestAction(testState).Run, "Before Test")); if (outcome.Status == TestStatus.Passed) { bool reusePrimaryTestStep = !testState.BindingContext.HasBindings; if (!reusePrimaryTestStep) { primaryTestStep.IsTestCase = false; } invisibleTest = false; TestContext primaryContext = TestContext.PrepareContext( testCommand.StartStep(primaryTestStep), sandbox); testState.SetInContext(primaryContext); using (primaryContext.Enter()) { primaryContext.LifecyclePhase = LifecyclePhases.Initialize; outcome = outcome.CombineWith(primaryContext.Sandbox.Run(TestLog.Writer, new InitializeTestAction(testState).Run, "Initialize")); } if (outcome.Status == TestStatus.Passed) { var actions = new List <RunTestDataItemAction>(); try { foreach (IDataItem bindingItem in testState.BindingContext.GetItems(!executor.options.SkipDynamicTests)) { actions.Add(new RunTestDataItemAction(executor, testCommand, testState, primaryContext, reusePrimaryTestStep, bindingItem)); } if (actions.Count == 0) { TestLog.Warnings.WriteLine("Test skipped because it is parameterized but no data was provided."); outcome = TestOutcome.Skipped; } else { if (actions.Count == 1 || !test.IsParallelizable) { foreach (var action in actions) { action.Run(); } } else { executor.scheduler.Run(GenericCollectionUtils.ConvertAllToArray <RunTestDataItemAction, GallioAction>( actions, action => action.Run)); } TestOutcome combinedOutcome = TestOutcome.Passed; foreach (var action in actions) { combinedOutcome = combinedOutcome.CombineWith(action.Outcome); } outcome = outcome.CombineWith(reusePrimaryTestStep ? combinedOutcome : combinedOutcome.Generalize()); } } catch (TestException ex) { if (ex.Outcome.Status == TestStatus.Failed) { TestLog.Failures.WriteException(ex, String.Format("An exception occurred while getting data items for test '{0}'.", testState.Test.FullName)); } else { TestLog.Warnings.WriteException(ex); } outcome = ex.Outcome; } catch (Exception ex) { TestLog.Failures.WriteException(ex, String.Format("An exception occurred while getting data items for test '{0}'.", testState.Test.FullName)); outcome = TestOutcome.Error; } } primaryContext.SetInterimOutcome(outcome); using (primaryContext.Enter()) { primaryContext.LifecyclePhase = LifecyclePhases.Dispose; outcome = outcome.CombineWith(primaryContext.Sandbox.Run(TestLog.Writer, new DisposeTestAction(testState).Run, "Dispose")); } result = primaryContext.FinishStep(outcome); } outcome = outcome.CombineWith(sandbox.Run(TestLog.Writer, new AfterTestAction(testState).Run, "After Test")); if (invisibleTest) { result = PublishOutcomeFromInvisibleTest(testCommand, primaryTestStep, outcome); } } } } } } catch (Exception ex) { result = ReportTestError(testCommand, parentTestStep, ex, String.Format("An exception occurred while preparing to run test '{0}'.", test.FullName)); } finally { if (parentContextCookie.HasValue) { parentContextCookie.Value.ExitContext(); } executor.progressMonitor.SetStatus(""); executor.progressMonitor.Worked(1); } }
public override void Act(ITestContext testContext) { testContext.ProcessResults = AutoVersionsDBAPI.GetScriptFilesState(testContext.ProjectConfig.Id, null); }
public override void Act(ITestContext testContext) { testContext.ProcessResults = AutoVersionsDBAPI.CreateNewIncrementalScriptFile(testContext.ProjectConfig.Id, ScriptName1, null); }
protected WhenProjectingCircularReferences(ITestContext <TOrmContext> context) : base(context) { }
/// <summary> /// [Call from external environment] Runs the remote action once. /// </summary> /// <param name="context">Context</param> /// <param name="action">Action to run.</param> public static void Run(this ITestContext context, Action action) { context.ContextOpen(); action(); context.ContextClose(); }
public override void Act(ITestContext testContext) { testContext.ProcessResults = AutoVersionsDBAPI.SyncDB(testContext.ProjectConfig.Id, null); }
IEnumerable <object> ITestDataSource.GetData(UTF.ITestMethod testMethodInfo, ITestContext testContext) { return(null); }
public override void Asserts(ITestContext testContext) { _projectConfigWithDBArrangeAndAssert.Asserts(GetType().Name, testContext, false); _dbAsserts.AssertRestore(GetType().Name, testContext.ProcessResults.Trace); }
public override void Release(ITestContext testContext) { _projectConfigsStorageHelper.ClearAllProjects(); }
/// <summary> /// Initializes a new instance of the <see cref="TestMethodRunner"/> class. /// </summary> /// <param name="testMethodInfo"> /// The test method info. /// </param> /// <param name="testMethod"> /// The test method. /// </param> /// <param name="testContext"> /// The test context. /// </param> /// <param name="captureDebugTraces"> /// The capture debug traces. /// </param> /// <param name="reflectHelper"> /// The reflect Helper object. /// </param> public TestMethodRunner(TestMethodInfo testMethodInfo, TestMethod testMethod, ITestContext testContext, bool captureDebugTraces, ReflectHelper reflectHelper) { Debug.Assert(testMethodInfo != null, "testMethodInfo should not be null"); Debug.Assert(testMethod != null, "testMethod should not be null"); Debug.Assert(testContext != null, "testContext should not be null"); this.testMethodInfo = testMethodInfo; this.test = testMethod; this.testContext = testContext; this.captureDebugTraces = captureDebugTraces; this.reflectHelper = reflectHelper; }
public void WritePreview(ITestContext context) { rows().Each(row => { writePreviewRow(row, context); }); }
public void ScenarioTearDown(ITestContext testContext) { Debug.WriteLine("ScenarioTearDown Executes once LoadTest execution is over"); Debug.WriteLine("Exceptions here are not handled!"); }
public override void Act(ITestContext testContext) { testContext.Result = AutoVersionsDBAPI.GetProjectsList(); }
protected WhenConfiguringConstructorDataSourcesInline(ITestContext <TOrmContext> context) : base(context) { }
/// <summary> /// Initializes a new instance of the <see cref="TestMethodRunner"/> class. /// </summary> /// <param name="testMethodInfo"> /// The test method info. /// </param> /// <param name="testMethod"> /// The test method. /// </param> /// <param name="testContext"> /// The test context. /// </param> /// <param name="captureDebugTraces"> /// The capture debug traces. /// </param> public TestMethodRunner(TestMethodInfo testMethodInfo, TestMethod testMethod, ITestContext testContext, bool captureDebugTraces) : this(testMethodInfo, testMethod, testContext, captureDebugTraces, ReflectHelper.Instance) { }
public void Run(ITestElement testElement, ITestContext testContext) { target.Run(testElement, testContext); }
public override void Release(ITestContext testContext) { _projectConfigWithDBArrangeAndAssert.Release(testContext); }
/// <summary> /// Resolve the test method. The function will try to /// find a function that has the method name with 0 parameters. If the function /// cannot be found, or a function is found that returns non-void, the result is /// set to error. /// </summary> /// <param name="testMethod"> The test Method. </param> /// <param name="testClassInfo"> The test Class Info. </param> /// <param name="testContext"> The test Context. </param> /// <param name="captureDebugTraces"> Indicates whether the test method should capture debug traces.</param> /// <returns> /// The TestMethodInfo for the given test method. Null if the test method could not be found. /// </returns> private TestMethodInfo ResolveTestMethod(TestMethod testMethod, TestClassInfo testClassInfo, ITestContext testContext, bool captureDebugTraces) { Debug.Assert(testMethod != null, "testMethod is Null"); Debug.Assert(testClassInfo != null, "testClassInfo is Null"); var methodInfo = this.GetMethodInfoForTestMethod(testMethod, testClassInfo); if (methodInfo == null) { // Means the specified test method could not be found. return(null); } var expectedExceptionAttribute = this.reflectionHelper.ResolveExpectedExceptionHelper(methodInfo, testMethod); var timeout = this.GetTestTimeout(methodInfo, testMethod); var testMethodOptions = new TestMethodOptions() { Timeout = timeout, Executor = this.GetTestMethodAttribute(methodInfo, testClassInfo), ExpectedException = expectedExceptionAttribute, TestContext = testContext, CaptureDebugTraces = captureDebugTraces }; var testMethodInfo = new TestMethodInfo(methodInfo, testClassInfo, testMethodOptions); this.SetCustomProperties(testMethodInfo, testContext); return(testMethodInfo); }
public void WritePreview(ITestContext context) { }
public void Execute(IStep containerStep, ITestContext context) { context.PerformAction(containerStep, _before); context.ExecuteWithFixture <T>(containerStep.LeafFor(LeafName()), containerStep); }
public override void Execute(IStep containerStep, ITestContext context) { _action(containerStep, context); }
public override void Asserts(ITestContext testContext) { _projectConfigWithDBArrangeAndAssert.Asserts(GetType().Name, testContext, false); _processAsserts.AssertContainError(GetType().Name, testContext.ProcessResults.Trace, CheckDeliveryEnvValidator.Name); }