Esempio n. 1
0
        public void RunTestMethodShouldSetResultFilesIfPresentForDataDrivenTests()
        {
            UTF.TestResult testResult = new UTF.TestResult
            {
                ResultFiles = new List <string>()
                {
                    "C:\\temp.txt"
                }
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int dummyIntData1 = 1;
            int dummyIntData2 = 2;

            UTF.DataRowAttribute dataRowAttribute1 = new UTF.DataRowAttribute(dummyIntData1);
            UTF.DataRowAttribute dataRowAttribute2 = new UTF.DataRowAttribute(dummyIntData2);

            var attribs = new Attribute[] { dataRowAttribute1, dataRowAttribute2 };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            CollectionAssert.Contains(results[0].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(results[1].ResultFiles.ToList(), "C:\\temp.txt");
        }
Esempio n. 2
0
        public void RunTestMethodShoudlRunOnlyDataSourceTestsWhenBothDataSourceAndDataRowAreProvided()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult());
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            UTF.DataSourceAttribute dataSourceAttribute = new UTF.DataSourceAttribute("DummyConnectionString", "DummyTableName");
            int    dummyIntData    = 2;
            string dummyStringData = "DummyString";

            UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(
                dummyIntData,
                dummyStringData);

            var attribs = new Attribute[] { dataSourceAttribute, dataRowAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.GetData(testMethodInfo, this.testContextImplementation)).Returns(new object[] { 1, 2, 3 });

            var results = testMethodRunner.RunTestMethod();

            // check for datarowIndex as only DataSource Tests are Run
            Assert.AreEqual(0, results[0].DatarowIndex);
            Assert.AreEqual(1, results[1].DatarowIndex);
            Assert.AreEqual(2, results[2].DatarowIndex);
        }
Esempio n. 3
0
        public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataRowAttribute()
        {
            UTF.TestResult testResult = new UTF.TestResult
            {
                Outcome = UTF.UnitTestOutcome.Inconclusive
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int    dummyIntData    = 2;
            string dummyStringData = "DummyString";

            UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(
                dummyIntData,
                dummyStringData);

            var attribs = new Attribute[] { dataRowAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            Assert.AreEqual(AdapterTestOutcome.Inconclusive, results[0].Outcome);
        }
Esempio n. 4
0
        public void RunTestMethodShouldReturnParentResultForDataRowDataDrivenTestsContainingSingleTest()
        {
            UTF.TestResult testResult = new UTF.TestResult
            {
                ResultFiles = new List <string>()
                {
                    "C:\\temp.txt"
                }
            };

            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int dummyIntData1 = 1;

            UTF.DataRowAttribute dataRowAttribute1 = new UTF.DataRowAttribute(dummyIntData1);

            var attribs = new Attribute[] { dataRowAttribute1 };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            CollectionAssert.Contains(results[1].ResultFiles.ToList(), "C:\\temp.txt");

            // Parent result should exist.
            Assert.AreEqual(2, results.Length);
            Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId);
            Assert.AreEqual(Guid.Empty, results[0].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[1].ParentExecId);
        }
Esempio n. 5
0
        public void RunTestMethodShouldFillInDisplayNameWithDataRowDisplayNameIfProvidedForDataDrivenTests()
        {
            UTF.TestResult testResult       = new UTF.TestResult();
            var            testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => testResult);
            var            testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int    dummyIntData    = 2;
            string dummyStringData = "DummyString";

            UTF.DataRowAttribute dataRowAttribute = new UTF.DataRowAttribute(dummyIntData, dummyStringData)
            {
                DisplayName = "DataRowTestDisplayName"
            };

            var attribs = new Attribute[] { dataRowAttribute };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(ro => ro.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            // 1st results should be parent result.
            Assert.AreEqual(2, results.Length);
            Assert.AreEqual("DataRowTestDisplayName", results[1].DisplayName);
        }
Esempio n. 6
0
        public void RunTestMethodShouldSetParentResultOutcomeProperlyForDataRowDataDrivenTests()
        {
            var testExecutedCount = 0;
            var testMethodInfo    = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () =>
            {
                return((testExecutedCount++ == 0) ?
                       new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Failed
                } :
                       new UTF.TestResult {
                    Outcome = UTF.UnitTestOutcome.Passed
                });
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false, this.mockReflectHelper.Object);

            int dummyIntData1 = 1;
            int dummyIntData2 = 2;

            UTF.DataRowAttribute dataRowAttribute1 = new UTF.DataRowAttribute(dummyIntData1);
            UTF.DataRowAttribute dataRowAttribute2 = new UTF.DataRowAttribute(dummyIntData2);

            var attribs = new Attribute[] { dataRowAttribute1, dataRowAttribute2 };

            // Setup mocks
            this.testablePlatformServiceProvider.MockReflectionOperations.Setup(rf => rf.GetCustomAttributes(this.methodInfo, It.IsAny <Type>(), It.IsAny <bool>())).Returns(attribs);

            var results = testMethodRunner.RunTestMethod();

            // Parent result should exist.
            Assert.AreEqual(3, results.Length);
            Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId);
            Assert.AreEqual(results[0].ExecutionId, results[2].ParentExecId);
            Assert.AreEqual(Guid.Empty, results[0].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[1].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[2].ParentExecId);

            // Check for aggregate outcome.
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Failed, results[1].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[2].Outcome);
        }