/// <summary> /// Construct a CompositeWorkItem for executing a test suite /// using a filter to select child tests. /// </summary> /// <param name="suite">The TestSuite to be executed</param> /// <param name="context">The execution context to be used</param> /// <param name="childFilter">A filter used to select child tests</param> public CompositeWorkItem(TestSuite suite, TestExecutionContext context, ITestFilter childFilter) : base(suite, context) { _suite = suite; _setupCommand = suite.GetOneTimeSetUpCommand(); _teardownCommand = suite.GetOneTimeTearDownCommand(); _childFilter = childFilter; }
/// <summary> /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> public SetUpTearDownCommand(TestCommand innerCommand) : base(innerCommand) { Guard.ArgumentValid(innerCommand.Test is TestMethod, "SetUpTearDownCommand may only apply to a TestMethod", "innerCommand"); Guard.OperationValid(Test.TypeInfo != null, "TestMethod must have a non-null TypeInfo"); _setUpTearDownItems = CommandBuilder.BuildSetUpTearDownList(Test.TypeInfo.Type, typeof(SetUpAttribute), typeof(TearDownAttribute)); }
/// <summary> /// Construct a WorkItem for a particular test. /// </summary> /// <param name="test">The test that the WorkItem will run</param> /// <param name="context">The context to be used for running this test</param> public WorkItem(Test test, TestExecutionContext context) { _test = test; _context = context.Save(); testResult = test.MakeTestResult(); _command = test.GetTestCommand(); _state = WorkItemState.Ready; }
/// <summary> /// Runs a TestCommand, sending notifications to a listener. /// </summary> /// <param name="command">A TestCommand to be executed.</param> /// <param name="context">The context in which to execute the command.</param> /// <returns>A TestResult.</returns> public static TestResult Execute(TestCommand command) { TestResult testResult; TestExecutionContext.Save(); TestExecutionContext context = TestExecutionContext.CurrentContext; //context = new TestExecutionContext(context); context.CurrentTest = command.Test; context.CurrentResult = command.Test.MakeTestResult(); context.Listener.TestStarted(command.Test); long startTime = DateTime.Now.Ticks; try { TestSuiteCommand suiteCommand = command as TestSuiteCommand; if (suiteCommand != null) testResult = ExecuteSuiteCommand(suiteCommand, context); //{ // suiteCommand.DoOneTimeSetup(); // foreach (TestCommand childCommand in suiteCommand.Children) // Execute(childCommand, context); // suiteCommand.DoOneTimeTearDown(); //} else testResult = command.Execute(context); testResult.AssertCount = context.AssertCount; long stopTime = DateTime.Now.Ticks; double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond; testResult.Time = time; context.Listener.TestFinished(testResult); } catch (Exception ex) { #if !NETCF if (ex is ThreadAbortException) Thread.ResetAbort(); #endif context.CurrentResult.RecordException(ex); return context.CurrentResult; } finally { TestExecutionContext.Restore(); //context.ReverseChanges(); //context = context.prior; } return testResult; }
/// <summary> /// Construct a CompositeWorkItem for executing a test suite /// using a filter to select child tests. /// </summary> /// <param name="suite">The TestSuite to be executed</param> /// <param name="context">The execution context to be used</param> /// <param name="childFilter">A filter used to select child tests</param> public CompositeWorkItem(TestSuite suite, TestExecutionContext context, ITestFilter childFilter) : base(suite, context) { _suite = suite; SetUpTearDownList setUpTearDown = null; if (suite.FixtureType != null) setUpTearDown = new SetUpTearDownList( suite.FixtureType, typeof(OneTimeSetUpAttribute), typeof(OneTimeTearDownAttribute)); _setupCommand = MakeSetUpCommand(suite, setUpTearDown); _teardownCommand = MakeTearDownCommand(suite, setUpTearDown); _childFilter = childFilter; }
public ApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable<IApplyToContext> changes) : base(innerCommand) { _changes = changes; }
/// <summary> /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> public SetUpTearDownCommand(TestCommand innerCommand) : base(innerCommand) { if (Test.FixtureType != null) _methods = new SetUpTearDownList(Test.FixtureType, typeof(SetUpAttribute), typeof(TearDownAttribute)); }
public TestCommand Wrap(TestCommand command) { return new ExpectedExceptionCommand(command, _expectedExceptionType); }
/// <summary> /// Construct a simple work item for a test. /// </summary> /// <param name="test">The test to be executed</param> public SimpleWorkItem(TestMethod test, FinallyDelegate fd) : base(test, fd) { _command = test.MakeTestCommand(); }
/// <summary> /// TODO: Documentation needed for constructor /// </summary> /// <param name="innerCommand"></param> protected DelegatingTestCommand(TestCommand innerCommand) : base(innerCommand.Test) { this.innerCommand = innerCommand; }
public TimeoutCommand(TestCommand innerCommand, int timeout) : this(innerCommand, timeout, new DebuggerProxy()) { }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return new RepeatedTestCommand(command); }
/// <summary> /// Construct a BeforeCommand /// </summary> public BeforeTestCommand(TestCommand innerCommand) : base(innerCommand) { }
/// <summary> /// Initializes a new instance of the <see cref="TestActionCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> public TestActionCommand(TestCommand innerCommand) : base(innerCommand) { Guard.ArgumentValid(innerCommand.Test is TestMethod, "TestActionCommand may only apply to a TestMethod", "innerCommand"); }
/// <summary> /// Initializes a new instance of the <see cref="MaxTimeCommand"/> class. /// TODO: Add a comment about where the max time is retrieved. /// </summary> /// <param name="innerCommand">The inner command.</param> public MaxTimeCommand(TestCommand innerCommand) : base(innerCommand) { this.maxTime = Test.Properties.GetSetting(PropertyNames.MaxTime, 0); }
public ApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable <IApplyToContext> changes) : base(innerCommand) { _changes = changes; }
/// <summary> /// Initializes a new instance of the <see cref="TestActionCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> public BeforeAndAfterTestCommand(TestCommand innerCommand) : base(innerCommand) { }
/// <summary> /// Construct an AfterCommand /// </summary> public AfterTestCommand(TestCommand innerCommand) : base(innerCommand) { }
/// <summary> /// Initializes a new instance of the <see cref="ExpectedExceptionCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> /// <param name="exceptionData">The exception data.</param> public ExpectedExceptionCommand(TestCommand innerCommand, ExpectedExceptionData exceptionData) : base(innerCommand) { this.exceptionData = exceptionData; }
/// <summary> /// Constructs a TheoryResultCommand /// </summary> /// <param name="command">The command to be wrapped by this one</param> public TheoryResultCommand(TestCommand command) : base(command) { }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return(new SetUpTearDownCommand(command)); }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return new SetUpTearDownCommand(command); }
/// <summary> /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> public SetUpTearDownCommand(TestCommand innerCommand) : base(innerCommand) { this.setUpMethods = Test.SetUpMethods; this.tearDownMethods = Test.TearDownMethods; }
/// <summary> /// Runs a TestCommand, sending notifications to a listener. /// </summary> /// <param name="command">A TestCommand to be executed.</param> /// <param name="context">The context in which to execute the command.</param> /// <returns>A TestResult.</returns> public static TestResult Execute(TestCommand command) { TestResult testResult; TestExecutionContext.Save(); TestExecutionContext context = TestExecutionContext.CurrentContext; //context = new TestExecutionContext(context); context.CurrentTest = command.Test; context.CurrentResult = command.Test.MakeTestResult(); context.Listener.TestStarted(command.Test); long startTime = DateTime.Now.Ticks; try { TestSuiteCommand suiteCommand = command as TestSuiteCommand; if (suiteCommand != null) { testResult = ExecuteSuiteCommand(suiteCommand, context); } //{ // suiteCommand.DoOneTimeSetup(); // foreach (TestCommand childCommand in suiteCommand.Children) // Execute(childCommand, context); // suiteCommand.DoOneTimeTearDown(); //} else { testResult = command.Execute(context); } testResult.AssertCount = context.AssertCount; long stopTime = DateTime.Now.Ticks; double time = ((double)(stopTime - startTime)) / (double)TimeSpan.TicksPerSecond; testResult.Time = time; context.Listener.TestFinished(testResult); } catch (Exception ex) { #if !NETCF if (ex is ThreadAbortException) { Thread.ResetAbort(); } #endif context.CurrentResult.RecordException(ex); return(context.CurrentResult); } finally { TestExecutionContext.Restore(); //context.ReverseChanges(); //context = context.prior; } return(testResult); }
public ApplyChangesToContextCommand(TestCommand innerCommand, IApplyToContext[] changes) : base(innerCommand) { _changes = changes; }
/// <summary> /// Initializes a new instance of the <see cref="MaxTimeCommand"/> class. /// </summary> /// <param name="innerCommand">The inner command.</param> /// <param name="maxTime">The max time allowed in milliseconds</param> public MaxTimeCommand(TestCommand innerCommand, int maxTime) : base(innerCommand) { this.maxTime = maxTime; }
/// <summary> /// Construct a simple work item for a test command. /// </summary> /// <param name="command">The command to be executed</param> public SimpleWorkItem(TestCommand command, FinallyDelegate fd) : base(command.Test, fd) { _command = command; }
private void InitializeSetUpAndTearDownCommands() { List<SetUpTearDownItem> setUpTearDownItems = _suite.TypeInfo != null ? CommandBuilder.BuildSetUpTearDownList(_suite.TypeInfo.Type, typeof(OneTimeSetUpAttribute), typeof(OneTimeTearDownAttribute)) : new List<SetUpTearDownItem>(); var actionItems = new List<TestActionItem>(); foreach (ITestAction action in Actions) { // Special handling here for ParameterizedMethodSuite is a bit ugly. However, // it is needed because Tests are not supposed to know anything about Action // Attributes (or any attribute) and Attributes don't know where they were // initially applied unless we tell them. // // ParameterizedMethodSuites and individual test cases both use the same // MethodInfo as a source of attributes. We handle the Test and Default targets // in the test case, so we don't want to doubly handle it here. bool applyToSuite = (action.Targets & ActionTargets.Suite) == ActionTargets.Suite || action.Targets == ActionTargets.Default && !(Test is ParameterizedMethodSuite); bool applyToTest = (action.Targets & ActionTargets.Test) == ActionTargets.Test && !(Test is ParameterizedMethodSuite); if (applyToSuite) actionItems.Add(new TestActionItem(action)); if (applyToTest) Context.UpstreamActions.Add(action); } _setupCommand = CommandBuilder.MakeOneTimeSetUpCommand(_suite, setUpTearDownItems, actionItems); _teardownCommand = CommandBuilder.MakeOneTimeTearDownCommand(_suite, setUpTearDownItems, actionItems); }
/// <summary> /// Construct a simple work item for a test command. /// </summary> /// <param name="command">The command to be executed</param> /// <param name="context">The execution context in which the test is to be run</param> public SimpleWorkItem(TestCommand command, TestExecutionContext context) : base(command.Test, context) { _command = command; }
/// <summary> /// Construct a simple work item for a test. /// </summary> /// <param name="test">The test to be executed</param> /// <param name="context">The execution context to be used</param> public SimpleWorkItem(TestMethod test, TestExecutionContext context) : base(test, context) { _command = test.MakeTestCommand(); }
public ExpectedExceptionCommand(TestCommand innerCommand, Type expectedType) : base(innerCommand) { _expectedType = expectedType; }
private TestCommand ApplyDecoratorsToCommand(TestCommand command) { CommandDecoratorList decorators = new CommandDecoratorList(); // Add Standard stuff decorators.Add(new SetUpTearDownDecorator()); // Add Decorators supplied by attributes foreach (ICommandDecoratorSource source in Method.GetCustomAttributes(typeof(ICommandDecoratorSource), true)) foreach (ICommandDecorator decorator in source.GetDecorators()) decorators.Add(decorator); // Add Decorators from the parameter set if (parms != null) foreach (ICommandDecorator decorator in parms.GetDecorators()) decorators.Add(decorator); decorators.OrderByStage(); foreach (ICommandDecorator decorator in decorators) { command = decorator.Decorate(command); } return command; }
/// <summary> /// Initializes a new instance of the <see cref="RepeatedTestCommand"/> class. /// TODO: Add a comment about where the repeat count is retrieved. /// </summary> /// <param name="innerCommand">The inner command.</param> public RepeatedTestCommand(TestCommand innerCommand) : base(innerCommand) { this.repeatCount = Test.Properties.GetSetting(PropertyNames.RepeatCount, 1); }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return new MaxTimeCommand(command); }
/// <summary> /// Gets a test command to be used in executing this test /// </summary> /// <param name="filter"></param> /// <returns></returns> public TestCommand GetTestCommand(ITestFilter filter) { if (testCommand == null) testCommand = runState != RunState.Runnable && runState != RunState.Explicit ? new SkipCommand(this) : MakeTestCommand(filter); return testCommand; }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return new ExpectedExceptionCommand(command, exceptionData); }
/// <summary> /// Construct a simple work item for a test. /// </summary> /// <param name="test">The test to be executed</param> public SimpleWorkItem(TestMethod test) : base(test) { _command = test.MakeTestCommand(); }
/// <summary> /// Construct a simple work item for a test command. /// </summary> /// <param name="command">The command to be executed</param> public SimpleWorkItem(TestCommand command) : base(command.Test) { _command = command; }
TestCommand ICommandDecorator.Decorate(TestCommand command) { return(new FlakyTestRetriesCommand(command)); }