Пример #1
0
        public void RunStepAndVerifyOutcome_ExecutionWithIncorrectOutcome()
        {
            bool        ran     = false;
            TestContext context = null;

            AssertionFailure[] failures = AssertionHelper.Eval(() =>
            {
                context = TestStep.RunStepAndVerifyOutcome("Abc", () =>
                {
                    ran = true;
                    Assert.Inconclusive();
                }, TestOutcome.Passed);
            }, AssertionFailureBehavior.CaptureAndContinue);

            Assert.AreEqual(1, failures.Length);
            Assert.AreEqual("The test step did not produce the expected outcome.", failures[0].Description);
            Assert.AreEqual("Expected Outcome", failures[0].LabeledValues[0].Label);
            Assert.AreEqual("passed", failures[0].LabeledValues[0].FormattedValue.ToString());
            Assert.AreEqual("Actual Outcome", failures[0].LabeledValues[1].Label);
            Assert.AreEqual("inconclusive", failures[0].LabeledValues[1].FormattedValue.ToString());

            Assert.IsTrue(ran, "Verify that the step ran.");
            Assert.AreEqual(TestOutcome.Inconclusive, context.Outcome,
                            "Verify that the step has the expected outcome.");
            Assert.AreEqual("Abc", context.TestStep.Name);
            Assert.Contains(context.TestStep.CodeElement.CodeReference.MemberName, "RunStepAndVerifyOutcome_ExecutionWithIncorrectOutcome");
            Assert.IsFalse(context.TestStep.IsTestCase);
        }
Пример #2
0
        public void EachTestStepHasItsOwnChildContext()
        {
            TestContext parentContext      = TestContext.CurrentContext;
            TestContext stepRunningContext = null;

            TestContext stepFinishedContext = TestStep.RunStepAndVerifyOutcome("Name", () =>
            {
                stepRunningContext = TestContext.CurrentContext;
            }, TestOutcome.Passed);

            Assert.AreNotSame(parentContext, stepFinishedContext);
            Assert.AreSame(stepFinishedContext, stepRunningContext, "Should return same context on exit from step as was active during step.");
            Assert.AreSame(parentContext, stepFinishedContext.Parent, "Parent context should be containing test.");
        }
Пример #3
0
        public void TestStepsAreIndependentFromContainingMultipleAssertsContext()
        {
            bool failedFast = false;

            TestStep.RunStepAndVerifyOutcome("Fail", () =>
            {
                failedFast = true;
                Assert.Fail("First failure.");

                failedFast = false;
                Assert.Fail("Second failure.");
            }, TestOutcome.Failed);

            Assert.IsTrue(failedFast);
        }
Пример #4
0
        public void RunStepAndVerifyOutcome_ExecutionWithCorrectOutcome()
        {
            bool        ran     = false;
            TestContext context = TestStep.RunStepAndVerifyOutcome("Abc", () =>
            {
                ran = true;
                Assert.Inconclusive();
            }, TestOutcome.Inconclusive);

            Assert.IsTrue(ran, "Verify that the step ran.");
            Assert.AreEqual(TestOutcome.Inconclusive, context.Outcome,
                            "Verify that the step has the expected outcome.");
            Assert.AreEqual("Abc", context.TestStep.Name);
            Assert.AreEqual("RunStepAndVerifyOutcome_ExecutionWithCorrectOutcome", context.TestStep.CodeElement.CodeReference.MemberName);
            Assert.IsFalse(context.TestStep.IsTestCase);
        }
Пример #5
0
        public void EachTestStepHasItsOwnContextDataNotInheritedFromItsParent()
        {
            Key <string> key = new Key <string>("key");

            TestContext.CurrentContext.Data.SetValue(key, "value");
            Assert.AreEqual("value", TestContext.CurrentContext.Data.GetValue(key));

            TestStep.RunStepAndVerifyOutcome("Name", () =>
            {
                Assert.IsFalse(TestContext.CurrentContext.Data.HasValue(key));

                TestContext.CurrentContext.Data.SetValue(key, "new value");
                Assert.AreEqual("new value", TestContext.CurrentContext.Data.GetValue(key));
            }, TestOutcome.Passed);

            Assert.AreEqual("value", TestContext.CurrentContext.Data.GetValue(key));
        }
Пример #6
0
        public void CurrentStepHasCorrectTestName()
        {
            Assert.Like(TestStep.CurrentStep.FullName, "Gallio.Tests/TestStepTest/CurrentStepHasCorrectTestName$");

            string step1Name = null, step2Name = null;

            TestStep.RunStepAndVerifyOutcome("Step1", delegate
            {
                step1Name = TestStep.CurrentStep.FullName;

                TestStep.RunStepAndVerifyOutcome("Step2", delegate
                {
                    step2Name = TestStep.CurrentStep.FullName;
                }, TestOutcome.Passed);
            }, TestOutcome.Passed);

            Assert.Like(step1Name, "Gallio.Tests/TestStepTest/CurrentStepHasCorrectTestName/Step1$");
            Assert.Like(step2Name, "Gallio.Tests/TestStepTest/CurrentStepHasCorrectTestName/Step1/Step2$");
        }