SetUpTearDownItem holds the setup and teardown methods for a single level of the inheritance hierarchy.
Exemplo n.º 1
0
        public void SuccessfulThenFailingSetupShouldLetExceptionBubbleUpUnwrapped()
        {
            var item = new SetUpTearDownItem(Success.Concat(Failure).ToList(), Empty);

            Assert.Throws<InvalidOperationException>(() => item.RunSetUp(_context));
            Assert.That(_testObject.SuccessfulAsyncMethodRuns, Is.EqualTo(1));
        }
Exemplo n.º 2
0
        public void SuccessfulSetup()
        {
            var item = new SetUpTearDownItem(Success.ToList(), Empty);
            item.RunSetUp(_context);

            Assert.That(_testObject.SuccessfulAsyncMethodRuns, Is.EqualTo(1));
        }
Exemplo n.º 3
0
        public void SuccessfulThenFailingTeardownShouldRecordFailureInTestContext()
        {
            var item = new SetUpTearDownItem(Empty, Success.Concat(Failure).ToList());

            item.RunSetUp(_context);
            item.RunTearDown(_context);

            Assert.That(_context.CurrentResult.ResultState, Is.EqualTo(ResultState.Error));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Constructs a OneTimeSetUpCommand for a suite
        /// </summary>
        /// <param name="innerCommand">The inner command to which the command applies</param>
        /// <param name="setUpTearDown">A SetUpTearDownList for use by the command</param>
        public OneTimeSetUpCommand(TestCommand innerCommand, SetUpTearDownItem setUpTearDown)
            : base(innerCommand)
        {
            Guard.ArgumentValid(Test is TestSuite && Test.Type != null,
                                "OneTimeSetUpCommand must reference a TestFixture or SetUpFixture", nameof(innerCommand));

            BeforeTest = (context) =>
            {
                setUpTearDown.RunSetUp(context);
            };
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SetUpTearDownCommand"/> class.
        /// </summary>
        /// <param name="innerCommand">The inner command.</param>
        /// <param name="setUpTearDown">List of setup/teardown items</param>
        public SetUpTearDownCommand(TestCommand innerCommand, SetUpTearDownItem setUpTearDown)
            : 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");
            Guard.ArgumentNotNull(setUpTearDown, nameof(setUpTearDown));

            BeforeTest = (context) =>
            {
                setUpTearDown.RunSetUp(context);
            };

            AfterTest = (context) =>
            {
                setUpTearDown.RunTearDown(context);
            };
        }
        /// <summary>
        /// Construct a OneTimeTearDownCommand
        /// </summary>
        /// <param name="innerCommand">The command wrapped by this command</param>
        /// <param name="setUpTearDownItem">A SetUpTearDownList for use by the command</param>
        public OneTimeTearDownCommand(TestCommand innerCommand, SetUpTearDownItem setUpTearDownItem)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestSuite, "OneTimeTearDownCommand may only apply to a TestSuite", "innerCommand");
            Guard.ArgumentNotNull(setUpTearDownItem, nameof(setUpTearDownItem));

            AfterTest = (context) =>
            {
                TestResult suiteResult = context.CurrentResult;

                try
                {
                    setUpTearDownItem.RunTearDown(context);
                }
                catch (Exception ex)
                {
                    suiteResult.RecordTearDownException(ex);
                }
            };
        }
Exemplo n.º 7
0
        public void FailingSetupShouldLetExceptionBubbleUpUnwrapped()
        {
            var item = new SetUpTearDownItem(Failure.ToList(), Empty);

            Assert.Throws<InvalidOperationException>(() => item.RunSetUp(_context));
        }