コード例 #1
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);
        }
コード例 #2
0
        public void RunTestMethodShouldRunDataDrivenTestsWhenDataIsProvidedUsingDataSourceAttribute()
        {
            var testMethodInfo = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult()
            {
                Outcome = UTF.UnitTestOutcome.Passed
            });
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            UTF.DataSourceAttribute dataSourceAttribute = new UTF.DataSourceAttribute("DummyConnectionString", "DummyTableName");

            var attribs = new Attribute[] { dataSourceAttribute };

            TestDataSource testDataSource = new TestDataSource();

            // 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 outcome
            Assert.AreEqual(AdapterTestOutcome.Passed, results[0].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[1].Outcome);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[2].Outcome);
        }
コード例 #3
0
        public void HasDataDrivenTestsReturnsTrueWhenTestIsDataDriven()
        {
            TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute(
                "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);
            this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false))
            .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });

            TestDataSource testDataSource = new TestDataSource();
            bool           result         = testDataSource.HasDataDrivenTests(this.mockTestMethodInfo.Object);

            Assert.AreEqual(result, true);
        }
コード例 #4
0
        public void GetDataShouldSetDataConnectionInTestContextObject()
        {
            var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest");

            TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute(
                "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);

            this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false))
            .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });
            this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);

            TestDataSource       testDataSource = new TestDataSource();
            IEnumerable <object> dataRows       = testDataSource.GetData(this.mockTestMethodInfo.Object, this.mockTestContext.Object);

            this.mockTestContext.Verify(tc => tc.SetDataConnection(It.IsAny <object>()), Times.Once);
        }
コード例 #5
0
        public void RunDataDrivenTestsShouldAttachResultsFilesForEachTestCase()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute(
                "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);

            this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false))
            .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });

            TestFrameworkV2.TestResult testResult = new TestFrameworkV2.TestResult();

            DummyTestClass testClassInstance = new DummyTestClass();
            var            methodInfo        = typeof(DummyTestClass).GetMethod("PassingTest");

            this.mockTestMethodInfo.Setup(ds => ds.Invoke(null)).
            Callback(() =>
            {
                try
                {
                    testClassInstance.TestContext = this.testContextImplementation;

                    var task = methodInfo.Invoke(testClassInstance, null) as Task;
                    task?.GetAwaiter().GetResult();

                    testResult.Outcome     = TestFrameworkV2.UnitTestOutcome.Passed;
                    testResult.ResultFiles = this.testContextImplementation.GetResultFiles();
                }
                catch (Exception ex)
                {
                    testResult.Outcome = TestFrameworkV2.UnitTestOutcome.Failed;
                    testResult.TestFailureException = ex;
                }
            }).Returns(testResult);
            this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);

            TestFrameworkV2.TestMethodAttribute testMethodAttribute = new TestFrameworkV2.TestMethodAttribute();
            TestDataSource testDataSource = new TestDataSource();

            TestFrameworkV2.TestResult[] result = testDataSource.RunDataDrivenTest(this.testContextImplementation, this.mockTestMethodInfo.Object, null, testMethodAttribute);
            CollectionAssert.Contains(result[0].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[1].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[2].ResultFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(result[3].ResultFiles.ToList(), "C:\\temp.txt");
        }
コード例 #6
0
        public void GetDataShouldReadDataFromGivenDataSource()
        {
            var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest");

            TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new TestFrameworkV2.DataSourceAttribute(
                "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);

            this.mockTestMethodInfo.Setup(ds => ds.GetAttributes <TestFrameworkV2.DataSourceAttribute>(false))
            .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });
            this.mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);

            TestDataSource       testDataSource = new TestDataSource();
            IEnumerable <object> dataRows       = testDataSource.GetData(this.mockTestMethodInfo.Object, this.mockTestContext.Object);

            foreach (DataRow dataRow in dataRows)
            {
                Assert.AreEqual("v1", dataRow[3]);
            }
        }
コード例 #7
0
        public void RunTestMethodShouldReturnParentResultForDataSourceDataDrivenTestsContainingSingleTest()
        {
            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");

            var attribs = new Attribute[] { dataSourceAttribute };

            // 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 });

            var results = testMethodRunner.RunTestMethod();

            // 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);
        }
コード例 #8
0
        public void RunTestMethodShouldSetParentResultOutcomeProperlyForDataSourceDataDrivenTests()
        {
            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);

            UTF.DataSourceAttribute dataSourceAttribute = new UTF.DataSourceAttribute("DummyConnectionString", "DummyTableName");

            var attribs = new Attribute[] { dataSourceAttribute };

            // 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 parent result
            Assert.AreEqual(4, results.Length);
            Assert.AreEqual(results[0].ExecutionId, results[1].ParentExecId);
            Assert.AreEqual(Guid.Empty, results[0].ParentExecId);
            Assert.AreNotEqual(Guid.Empty, results[1].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);
            Assert.AreEqual(AdapterTestOutcome.Passed, results[3].Outcome);
        }