예제 #1
0
 /// <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;
 }
예제 #2
0
        /// <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));
        }
예제 #3
0
 /// <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;
 }
예제 #4
0
        /// <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));
 }
예제 #8
0
 public TestCommand Wrap(TestCommand command)
 {
     return new ExpectedExceptionCommand(command, _expectedExceptionType);
 }
예제 #9
0
 /// <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;
 }
예제 #11
0
 public TimeoutCommand(TestCommand innerCommand, int timeout) : this(innerCommand, timeout, new DebuggerProxy())
 {
 }
예제 #12
0
 TestCommand ICommandDecorator.Decorate(TestCommand command)
 {
     return new RepeatedTestCommand(command);
 }
예제 #13
0
 /// <summary>
 /// Construct a BeforeCommand
 /// </summary>
 public BeforeTestCommand(TestCommand innerCommand) : base(innerCommand)
 {
 }
예제 #14
0
 /// <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");
 }
예제 #15
0
 /// <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);
 }
예제 #16
0
 public ApplyChangesToContextCommand(TestCommand innerCommand, IEnumerable <IApplyToContext> changes)
     : base(innerCommand)
 {
     _changes = changes;
 }
예제 #17
0
 /// <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)
 {
 }
예제 #18
0
 /// <summary>
 /// Construct an AfterCommand
 /// </summary>
 public AfterTestCommand(TestCommand innerCommand) : base(innerCommand)
 {
 }
예제 #19
0
 /// <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;
 }
예제 #20
0
 /// <summary>
 /// Constructs a TheoryResultCommand
 /// </summary>
 /// <param name="command">The command to be wrapped by this one</param>
 public TheoryResultCommand(TestCommand command) : base(command)
 {
 }
예제 #21
0
 TestCommand ICommandDecorator.Decorate(TestCommand command)
 {
     return(new SetUpTearDownCommand(command));
 }
예제 #22
0
 TestCommand ICommandDecorator.Decorate(TestCommand command)
 {
     return new SetUpTearDownCommand(command);
 }
예제 #23
0
 /// <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;
 }
예제 #24
0
        /// <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);
        }
예제 #25
0
 /// <summary>
 /// TODO: Documentation needed for constructor
 /// </summary>
 /// <param name="innerCommand"></param>
 protected DelegatingTestCommand(TestCommand innerCommand)
     : base(innerCommand.Test)
 {
     this.innerCommand = innerCommand;
 }
 public ApplyChangesToContextCommand(TestCommand innerCommand, IApplyToContext[] changes)
     : base(innerCommand)
 {
     _changes = changes;
 }
예제 #27
0
 /// <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;
 }
예제 #28
0
 /// <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;
 }
예제 #29
0
        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);
        }
예제 #30
0
 /// <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;
 }
예제 #31
0
 /// <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();
 }
예제 #32
0
 /// <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;
 }
예제 #33
0
 /// <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);
 }
예제 #34
0
 public ExpectedExceptionCommand(TestCommand innerCommand, Type expectedType)
     : base(innerCommand)
 {
     _expectedType = expectedType;
 }
예제 #35
0
 /// <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");
 }
예제 #36
0
        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;
        }
예제 #37
0
 /// <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);
 }
예제 #38
0
 /// <summary>
 /// Constructs a TheoryResultCommand 
 /// </summary>
 /// <param name="command">The command to be wrapped by this one</param>
 public TheoryResultCommand(TestCommand command) : base(command) { }
예제 #39
0
 TestCommand ICommandDecorator.Decorate(TestCommand command)
 {
     return new MaxTimeCommand(command);
 }
 /// <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;
 }
예제 #41
0
        /// <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);
 }
예제 #43
0
 /// <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();
 }
 public ApplyChangesToContextCommand(TestCommand innerCommand, IApplyToContext[] changes)
     : base(innerCommand)
 {
     _changes = changes;
 }
예제 #45
0
 /// <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;
 }
예제 #46
0
 /// <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;
 }
예제 #47
0
 TestCommand ICommandDecorator.Decorate(TestCommand command)
 {
     return(new FlakyTestRetriesCommand(command));
 }