コード例 #1
0
 public void IsValidTestClassShouldReportWarningsForNestedNonPublicTestClasses()
 {
     this.SetupTestClass();
     this.typeValidator.IsValidTestClass(typeof(OuterClass.NestedInternalClass), this.warnings);
     Assert.AreEqual(1, this.warnings.Count);
     CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(OuterClass.NestedInternalClass).FullName));
 }
コード例 #2
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);
        }
コード例 #3
0
 public void IsValidTestClassShouldReportWarningsForTestClassesWithInvalidTestContextSignature()
 {
     this.SetupTestClass();
     this.typeValidator.IsValidTestClass(typeof(ClassWithTestContextGetterOnly), this.warnings);
     Assert.AreEqual(1, this.warnings.Count);
     CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorInValidTestContextSignature, typeof(ClassWithTestContextGetterOnly).FullName));
 }
コード例 #4
0
        public void GetTestsShouldReturnNullIfSourceFileDoesNotExistInContext()
        {
            var assemblyName = "DummyAssembly.dll";

            // Setup mocks.
            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.GetFullFilePath(assemblyName))
            .Returns(assemblyName);
            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.DoesFileExist(assemblyName))
            .Returns(false);

            Assert.IsNull(this.testableAssemblyEnumeratorWrapper.GetTests(assemblyName, null, out this.warnings));

            // Also validate that we give a warning when this happens.
            Assert.IsNotNull(this.warnings);
            var innerMessage = string.Format(
                CultureInfo.CurrentCulture,
                Resource.TestAssembly_FileDoesNotExist,
                assemblyName);
            var message = string.Format(
                CultureInfo.CurrentCulture,
                Resource.TestAssembly_AssemblyDiscoveryFailure,
                assemblyName,
                innerMessage);

            CollectionAssert.Contains(this.warnings.ToList(), message);
        }
コード例 #5
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");
        }
コード例 #6
0
        public void EnumerateAssemblyShouldHandleExceptionsWhileEnumeratingAType()
        {
            var mockAssembly = CreateMockTestableAssembly();
            var testableAssemblyEnumerator = new TestableAssemblyEnumerator();
            var exception = new Exception("TypeEnumerationException");

            // Setup mocks
            mockAssembly.Setup(a => a.DefinedTypes)
            .Returns(new List <TypeInfo>()
            {
                typeof(InternalTestClass).GetTypeInfo()
            });
            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("DummyAssembly", false))
            .Returns(mockAssembly.Object);
            testableAssemblyEnumerator.MockTypeEnumerator.Setup(te => te.Enumerate(out this.warnings)).Throws(exception);

            testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly", out this.warnings);

            CollectionAssert.Contains(
                this.warnings.ToList(),
                string.Format(
                    CultureInfo.CurrentCulture,
                    Resource.CouldNotInspectTypeDuringDiscovery,
                    typeof(InternalTestClass),
                    "DummyAssembly",
                    exception.Message));
        }
コード例 #7
0
 public void IsValidTestClassShouldReportWarningsForNonAbstractGenericTypes()
 {
     this.SetupTestClass();
     this.typeValidator.IsValidTestClass(typeof(GenericClass <>), this.warnings);
     Assert.AreEqual(1, this.warnings.Count);
     CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(GenericClass <>).FullName));
 }
コード例 #8
0
        public void AddPropertyShouldAddPropertiesToThePropertyBag()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
            this.testContextImplementation.AddProperty("SomeNewProperty", "SomeValue");

            CollectionAssert.Contains(
                this.testContextImplementation.Properties,
                new KeyValuePair <string, object>("SomeNewProperty", "SomeValue"));
        }
コード例 #9
0
        public void AddResultFileShouldAddFiletoResultsFiles()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            this.testContextImplementation.AddResultFile("C:\\temp.txt");

            var resultsFiles = this.testContextImplementation.GetResultFiles();

            CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp.txt");
        }
コード例 #10
0
        public void AddResultFileShouldAddMultipleFilestoResultsFiles()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties);

            this.testContextImplementation.AddResultFile("C:\\temp.txt");
            this.testContextImplementation.AddResultFile("C:\\temp2.txt");

            var resultsFiles = this.testContextImplementation.GetResultFiles();

            CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp.txt");
            CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp2.txt");
        }
コード例 #11
0
        public void IsValidTestMethodShouldReportWarningsForGenericTestMethodDefinitions()
        {
            this.SetupTestMethod();
            this.mockMethodInfo.Setup(mi => mi.IsGenericMethodDefinition).Returns(true);
            this.mockMethodInfo.Setup(mi => mi.DeclaringType.FullName).Returns("DummyTestClass");
            this.mockMethodInfo.Setup(mi => mi.Name).Returns("DummyTestMethod");

            this.testMethodValidator.IsValidTestMethod(this.mockMethodInfo.Object, this.type, this.warnings);

            Assert.AreEqual(1, this.warnings.Count);
            CollectionAssert.Contains(this.warnings, string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorGenericTestMethod, "DummyTestClass", "DummyTestMethod"));
        }
コード例 #12
0
        public void RunTestsForSourceShouldRunTestsInASource()
        {
            var sources = new List <string> {
                Assembly.GetExecutingAssembly().Location
            };

            this.TestExecutionManager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken);

            CollectionAssert.Contains(this.frameworkHandle.TestCaseStartList, "PassingTest");
            CollectionAssert.Contains(this.frameworkHandle.TestCaseEndList, "PassingTest:Passed");
            CollectionAssert.Contains(this.frameworkHandle.ResultsList, "PassingTest  Passed");
        }
コード例 #13
0
        public void PropertiesShouldReturnPropertiesPassedToTestContext()
        {
            var property1 = new KeyValuePair <string, object>("IntProperty", 1);
            var property2 = new KeyValuePair <string, object>("DoubleProperty", 2.023);

            this.properties.Add(property1);
            this.properties.Add(property2);

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            CollectionAssert.Contains(this.testContextImplementation.Properties, property1);
            CollectionAssert.Contains(this.testContextImplementation.Properties, property2);
        }
コード例 #14
0
        public void TestContextConstructorShouldInitializeDefaultProperties()
        {
            this.testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
            this.testMethod.Setup(tm => tm.Name).Returns("M");

            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            Assert.IsNotNull(this.testContextImplementation.Properties);

            CollectionAssert.Contains(
                this.testContextImplementation.Properties,
                new KeyValuePair <string, object>("FullyQualifiedTestClassName", "A.C.M"));
            CollectionAssert.Contains(
                this.testContextImplementation.Properties,
                new KeyValuePair <string, object>("TestName", "M"));
        }
コード例 #15
0
        public void GetTypesShouldLogWarningsWhenReflectionFailsWithLoaderExceptions()
        {
            Mock <TestableAssembly> mockAssembly = new Mock <TestableAssembly>();
            var exceptions = new Exception[] { new Exception("DummyLoaderException") };

            // Setup mocks
            mockAssembly.Setup(a => a.DefinedTypes).Throws(new ReflectionTypeLoadException(null, exceptions));

            var types = this.assemblyEnumerator.GetTypes(mockAssembly.Object, "DummyAssembly", this.warnings);

            Assert.AreEqual(1, this.warnings.Count);
            CollectionAssert.Contains(
                this.warnings.ToList(),
                string.Format(CultureInfo.CurrentCulture, Resource.TypeLoadFailed, "DummyAssembly", "System.Exception: DummyLoaderException\r\n"));

            this.testablePlatformServiceProvider.MockTraceLogger.Verify(tl => tl.LogWarning("{0}", exceptions[0]), Times.Once);
        }
コード例 #16
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");
        }
コード例 #17
0
        public void RunTestsForTestShouldPassInTestRunParametersInformationAsPropertiesToTheTest()
        {
            var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest");

            TestCase[] tests = new[] { testCase };
            this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
                @"<RunSettings> 
                                            <TestRunParameters>
                                              <Parameter name=""webAppUrl"" value=""http://localhost"" />
                                              <Parameter name = ""webAppUserName"" value=""Admin"" />
                                              </TestRunParameters>
                                            </RunSettings>");

            this.TestExecutionManager.RunTests(tests, this.runContext, this.frameworkHandle, new TestRunCancellationToken());

            CollectionAssert.Contains(
                DummyTestClass.TestContextProperties.ToList(),
                new KeyValuePair <string, object>("webAppUrl", "http://localhost"));
        }
コード例 #18
0
        public void RunTestsForSourceShouldPassInTestRunParametersInformationAsPropertiesToTheTest()
        {
            var sources = new List <string> {
                Assembly.GetExecutingAssembly().Location
            };

            this.runContext.MockRunSettings.Setup(rs => rs.SettingsXml).Returns(
                @"<RunSettings> 
                                            <TestRunParameters>
                                              <Parameter name=""webAppUrl"" value=""http://localhost"" />
                                              <Parameter name = ""webAppUserName"" value=""Admin"" />
                                              </TestRunParameters>
                                            </RunSettings>");

            this.TestExecutionManager.RunTests(sources, this.runContext, this.frameworkHandle, this.cancellationToken);

            CollectionAssert.Contains(
                DummyTestClass.TestContextProperties.ToList(),
                new KeyValuePair <string, object>("webAppUrl", "http://localhost"));
        }
コード例 #19
0
 public void ValidSourceExtensionsShouldContainAppxExtensions()
 {
     CollectionAssert.Contains(this.testSource.ValidSourceExtensions.ToList(), ".appx");
 }
コード例 #20
0
 public void ValidSourceExtensionsShouldContainExeExtensions()
 {
     CollectionAssert.Contains(this.testSourceValidator.ValidSourceExtensions.ToList(), ".exe");
 }