Beispiel #1
0
        public void ToTestResultForUniTestResultWithStandardOutShouldReturnTestResultWithStdOutMessage()
        {
            UnitTestResult result = new UnitTestResult()
            {
                StandardOut = "DummyOutput"
            };
            TestCase testCase = new TestCase("Foo", new Uri("Uri", UriKind.Relative), Assembly.GetExecutingAssembly().FullName);

            string runSettingxml =
                @"<RunSettings>
                    <MSTestV2>
                    </MSTestV2>
                  </RunSettings>";

            var adapterSettings = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias);

            var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, adapterSettings);

            Assert.IsTrue(testresult.Messages.All(m => m.Text.Contains("DummyOutput") && m.Category.Equals("StdOutMsgs")));
        }
Beispiel #2
0
        public void ToTestResultForUniTestResultWithNoResultFilesShouldReturnTestResultWithNoResultFilesAttachment()
        {
            UnitTestResult result = new UnitTestResult()
            {
                ResultFiles = null
            };
            TestCase testCase = new TestCase("Foo", new Uri("Uri", UriKind.Relative), Assembly.GetExecutingAssembly().FullName);

            string runSettingxml =
                @"<RunSettings>
                    <MSTestV2>
                    </MSTestV2>
                  </RunSettings>";

            var adapterSettings = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsNameAlias);

            var testresult = result.ToTestResult(testCase, DateTimeOffset.Now, DateTimeOffset.Now, adapterSettings);

            Assert.AreEqual(0, testresult.Attachments.Count);
        }
Beispiel #3
0
        public void PopulateSettingsShouldInitializeSettingsToDefaultIfNotSpecified()
        {
            string runSettingxml =
                @"<RunSettings>
                 <FooUnit>   
                  <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                 </FooUnit>
               </RunSettings>";

            this.mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(this.mockRunSettings.Object);
            this.mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
            MSTestSettings.PopulateSettings(this.mockDiscoveryContext.Object);

            var adapterSettings = MSTestSettings.CurrentSettings;

            Assert.IsNotNull(adapterSettings);

            // Validating the default value of a random setting.
            Assert.AreEqual(adapterSettings.ForcedLegacyMode, false);
        }
        public void ToUnitTestResultsForTestResultShouldSetLoggingDataForConvertedUnitTestResults()
        {
            var timespan = default(TimeSpan);
            var results  = new[]
            {
                new UTF.TestResult()
                {
                    DebugTrace = "debugTrace", DisplayName = "displayName", Duration = timespan, LogOutput = "logOutput",
                    LogError   = "logError", DatarowIndex = 1
                }
            };
            var convertedResults = results.ToUnitTestResults();

            Assert.AreEqual("logOutput", convertedResults[0].StandardOut);
            Assert.AreEqual("logError", convertedResults[0].StandardError);
            Assert.AreEqual("displayName", convertedResults[0].DisplayName);
            Assert.AreEqual("debugTrace", convertedResults[0].DebugTrace);
            Assert.AreEqual(timespan, convertedResults[0].Duration);
            Assert.AreEqual(1, convertedResults[0].DatarowIndex);
        }
        public void GetTestFromMethodShouldFillTraitsWithTestOwnerPropertyIfPresent()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");
            var            testProperties = new List <Trait> {
                new Trait("foo", "bar"), new Trait("fooprime", "barprime")
            };
            var ownerTrait = new Trait("owner", "mike");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.GetTestPropertiesAsTraits(methodInfo)).Returns(testProperties);
            this.mockReflectHelper.Setup(rh => rh.GetTestOwnerAsTraits(methodInfo)).Returns(ownerTrait);

            var testElement = typeEnumerator.GetTestFromMethod(methodInfo, this.warnings);

            Assert.IsNotNull(testElement);
            testProperties.Add(ownerTrait);
            CollectionAssert.AreEqual(testProperties, testElement.Traits);
        }
Beispiel #6
0
        public void RunTestMethodRunsDataDrivenTestsWhenDataIsProvided()
        {
            var testMethodInfo   = new TestableTestmethodInfo(this.methodInfo, this.testClassInfo, this.testMethodOptions, () => new UTF.TestResult());
            var testMethodRunner = new TestMethodRunner(testMethodInfo, this.testMethod, this.testContextImplementation, false);

            // Set outcome to be failed
            var result = new UTF.TestResult();

            result.Outcome = UTF.UnitTestOutcome.Failed;

            // setup mocks
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.HasDataDrivenTests(It.IsAny <TestMethodInfo>())).Returns(true);
            this.testablePlatformServiceProvider.MockTestDataSource.Setup(tds => tds.RunDataDrivenTest(It.IsAny <UTFExtension.TestContext>(), It.IsAny <TestMethodInfo>(), It.IsAny <TestMethod>(), It.IsAny <UTF.TestMethodAttribute>()))
            .Returns(new UTF.TestResult[] { result });

            var results = testMethodRunner.Execute();

            // check for outcome
            Assert.AreEqual(AdapterTestOutcome.Failed, results[0].Outcome);
        }
        public void RunCleanupShouldReturnCleanupResultsWithDebugTraceLogsSetIfDebugTraceEnabled()
        {
            this.unitTestRunner = new UnitTestRunner(this.GetSettingsWithDebugTrace(true));
            var type       = typeof(DummyTestClassWithCleanupMethods);
            var methodInfo = type.GetMethod("TestMethod");
            var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());

            StringWriter writer = new StringWriter(new StringBuilder("DummyTrace"));

            this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);

            this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters);

            var cleanupresult = this.unitTestRunner.RunCleanup();

            Assert.AreEqual(cleanupresult.DebugTrace, "DummyTrace");
        }
        public void RunSingleTestShouldReturnTestResultIndicatingFailureIfThereIsAnyTypeInspectionExceptionWhenInspectingTestMethod()
        {
            var type       = typeof(TypeCacheTests.DummyTestClassWithTestMethods);
            var testMethod = new TestMethod("ImaginaryTestMethod", type.FullName, "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());

            var results = this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters);

            var expectedMessage = string.Format(
                "Method {0}.{1} does not exist.",
                testMethod.FullClassName,
                testMethod.Name);

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(UnitTestOutcome.Failed, results[0].Outcome);
            Assert.AreEqual(expectedMessage, results[0].ErrorMessage);
        }
Beispiel #9
0
        public void GetTestsShouldNotReturnHiddenTestMethods()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyHidingTestClass), Assembly.GetExecutingAssembly().FullName);

            var tests = typeEnumerator.Enumerate(out this.warnings);

            Assert.IsNotNull(tests);
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummyHidingTestClass declares BaseTestMethod directly so it should always be discovered.");
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "DerivedTestMethod"),
                "DummyHidingTestClass declares BaseTestMethod directly so it should always be discovered.");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyBaseTestClass).FullName),
                "DummyHidingTestClass hides BaseTestMethod so declaring class should not be the base class");
        }
Beispiel #10
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);
        }
Beispiel #11
0
        public void DeployShouldDeploySatelliteAssemblies()
        {
            TestRunDirectories testRunDirectories;
            var testCase          = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories);
            var assemblyFullPath  = Assembly.GetExecutingAssembly().Location;
            var satelliteFullPath = Path.Combine(Path.GetDirectoryName(assemblyFullPath), "de", "satellite.dll");

            // Setup mocks.
            this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is <string>(s => !(s.EndsWith(".dll") || s.EndsWith(".config"))))).Returns(true);
            this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny <string>())).Returns(true);
            this.mockAssemblyUtility.Setup(
                au => au.GetFullPathToDependentAssemblies(It.IsAny <string>(), It.IsAny <string>(), out this.warnings))
            .Returns(new string[] { });
            this.mockAssemblyUtility.Setup(
                au => au.GetSatelliteAssemblies(assemblyFullPath))
            .Returns(new List <string> {
                satelliteFullPath
            });

            // Act.
            Assert.IsTrue(
                this.deploymentUtility.Deploy(
                    new List <TestCase> {
                testCase
            },
                    testCase.Source,
                    this.mockRunContext.Object,
                    this.mocktestExecutionRecorder.Object,
                    testRunDirectories));

            // Assert.
            string warning;

            this.mockFileUtility.Verify(
                fu =>
                fu.CopyFileOverwrite(
                    It.Is <string>(s => s.Contains(satelliteFullPath)),
                    Path.Combine(testRunDirectories.OutDirectory, "de", Path.GetFileName(satelliteFullPath)),
                    out warning),
                Times.Once);
        }
        public void RunDataDrivenTestsGivesTestResultAsFailedWhenTestMethodFails()
        {
            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("FailingTest");

            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;
                }
                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);
            Assert.AreEqual(result[0].Outcome, TestFrameworkV2.UnitTestOutcome.Failed);
        }
Beispiel #13
0
        public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath()
        {
            string path          = @"\MsTest\Adapter";
            string baseDirectory = @"C:\unitTesting";

            // instead of returning "C:\unitTesting\MsTest\Adapter", it will return "(Drive from where test is running):\MsTest\Adapter",
            // because path is starting with "\"
            // this is how Path.GetFullPath works
            string currentDirectory = Environment.CurrentDirectory;
            string currentDrive     = currentDirectory.Split('\\').First() + "\\";
            string expectedResult   = Path.Combine(currentDrive, @"MsTest\Adapter");

            var adapterSettings = new TestableMSTestAdapterSettings();

            adapterSettings.DoesDirectoryExistSetter = (str) => { return(true); };

            string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);

            Assert.IsNotNull(result);
            Assert.AreEqual(string.Compare(result, expectedResult, true), 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 message = string.Format(
                CultureInfo.CurrentCulture,
                Resource.TestAssembly_FileDoesNotExist,
                assemblyName);

            CollectionAssert.Contains(this.warnings.ToList(), message);
        }
        public void MethodInfoInvokeAsSynchronousTaskExecutesAMethodWhichDoesNotReturnATask()
        {
            var testMethodCalled = false;

            DummyTestClass2.DummyMethodBody = (x, y) =>
            {
                Assert.AreEqual(10, x);
                Assert.AreEqual(20, y);
                testMethodCalled = true;
                return(true);
            };

            var methodInfo = typeof(DummyTestClass).GetMethod("PublicMethod");

            var dummyTestClass = new DummyTestClass2();
            var dummyMethod    = typeof(DummyTestClass2).GetMethod("DummyMethod");

            dummyMethod.InvokeAsSynchronousTask(dummyTestClass, 10, 20);

            Assert.IsTrue(testMethodCalled);
        }
Beispiel #16
0
        public void PopulateSettingsShouldInitializeSettingsFromRunConfigurationSection()
        {
            string runSettingxml =
                @"<RunSettings>
                     <RunConfiguration>
                       <ResultsDirectory>.\TestResults</ResultsDirectory>
                       <CollectSourceInformation>false</CollectSourceInformation>
                     </RunConfiguration>
              </RunSettings>";

            this.mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(this.mockRunSettings.Object);
            this.mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
            MSTestSettings.PopulateSettings(this.mockDiscoveryContext.Object);

            RunConfigurationSettings settings = MSTestSettings.RunConfigurationSettings;

            Assert.IsNotNull(settings);

            // Validating the default value of a random setting.
            Assert.IsFalse(settings.CollectSourceInformation);
        }
        public void CreateInstanceForTypeShouldCreateTheTypeInANewAppDomain()
        {
            // Setup
            DummyClass dummyclass         = new DummyClass();
            int        currentAppDomainId = dummyclass.AppDomainId;

            TestSourceHost sut = new TestSourceHost(Assembly.GetExecutingAssembly().Location, null, null);

            // Execute
            var expectedObject = sut.CreateInstanceForType(typeof(DummyClass), null) as DummyClass;

            int newAppDomainId = currentAppDomainId + 10;  // not equal to currentAppDomainId

            if (expectedObject != null)
            {
                newAppDomainId = expectedObject.AppDomainId;
            }

            // Assert
            Assert.AreNotEqual(currentAppDomainId, newAppDomainId);
        }
Beispiel #18
0
        public void ThrowsExceptionAsyncWithMessageAndParamsShouldThrowAssertionOnWrongException()
        {
            Task t = TestFrameworkV2.Assert.ThrowsExceptionAsync <ArgumentException>(
                async() =>
            {
                await Task.Delay(5);
                throw new FormatException();
            },
                "Happily ever after. {0} {1}.",
                "The",
                "End");
            var ex = ActionUtility.PerformActionAndReturnException(() => t.Wait());

            Assert.IsNotNull(ex);

            var innerException = ex.InnerException;

            Assert.IsNotNull(innerException);
            Assert.AreEqual(typeof(TestFrameworkV2.AssertFailedException), innerException.GetType());
            StringAssert.Contains(innerException.Message, "Assert.ThrowsException failed. Threw exception FormatException, but exception ArgumentException was expected. Happily ever after. The End.");
        }
        public void ToUnitTestElementShouldReturnUnitTestElementWithFieldsSet()
        {
            TestCase testCase = new TestCase("DummyClass.DummyMethod", new Uri("DummyUri", UriKind.Relative), Assembly.GetCallingAssembly().FullName);

            testCase.DisplayName = "DummyDisplayName";
            var testCategories = new[] { "DummyCategory" };

            testCase.SetPropertyValue(Constants.AsyncTestProperty, true);
            testCase.SetPropertyValue(Constants.PriorityProperty, 2);
            testCase.SetPropertyValue(Constants.TestCategoryProperty, testCategories);
            testCase.SetPropertyValue(Constants.TestClassNameProperty, "DummyClassName");

            var resultUnitTestElement = testCase.ToUnitTestElement(testCase.Source);

            Assert.AreEqual(true, resultUnitTestElement.IsAsync);
            Assert.AreEqual(2, resultUnitTestElement.Priority);
            Assert.AreEqual(testCategories, resultUnitTestElement.TestCategory);
            Assert.AreEqual("DummyDisplayName", resultUnitTestElement.TestMethod.Name);
            Assert.AreEqual("DummyClassName", resultUnitTestElement.TestMethod.FullClassName);
            Assert.AreEqual(true, resultUnitTestElement.TestMethod.IsAsync);
        }
Beispiel #20
0
        public void ThrowsExceptionAsyncWithMessageAndParamsShouldThrowAssertionOnNoException()
        {
            Task t = TestFrameworkV2.Assert.ThrowsExceptionAsync <ArgumentException>(
                async() =>
            {
                await Task.Delay(5);
            },
                "The world is not on fire {0}.{1}-{2}.",
                "ta",
                "da",
                123);
            var ex = ActionUtility.PerformActionAndReturnException(() => t.Wait());

            Assert.IsNotNull(ex);

            var innerException = ex.InnerException;

            Assert.IsNotNull(innerException);
            Assert.AreEqual(typeof(TestFrameworkV2.AssertFailedException), innerException.GetType());
            StringAssert.Contains(innerException.Message, "Assert.ThrowsException failed. No exception thrown. ArgumentException exception was expected. The world is not on fire ta.da-123.");
        }
Beispiel #21
0
        public void RunTestsForTestShouldDeployBeforeExecution()
        {
            var testCase = this.GetTestCase(typeof(DummyTestClass), "PassingTest");

            TestCase[] tests = new[] { testCase };

            // Setup mocks.
            var testablePlatformService = this.SetupTestablePlatformService();

            testablePlatformService.MockTestDeployment.Setup(
                td => td.Deploy(tests, this.runContext, this.frameworkHandle)).Callback(() => this.SetCaller("Deploy"));

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

            Assert.AreEqual("Deploy", this.callers[0], "Deploy should be called before execution.");
            Assert.AreEqual("LoadAssembly", this.callers[1], "Deploy should be called before execution.");
        }
Beispiel #22
0
        public void CleanupShouldDeleteRootDeploymentDirectory()
        {
            TestRunDirectories testRunDirectories;
            var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location);

            // Setup mocks.
            var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories);

            var mockRunContext = new Mock <IRunContext>();

            mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);

            Assert.IsTrue(testDeployment.Deploy(new List <TestCase> {
                testCase
            }, mockRunContext.Object, new Mock <IFrameworkHandle>().Object));

            // Act.
            testDeployment.Cleanup();

            this.mockFileUtility.Verify(fu => fu.DeleteDirectories(testRunDirectories.RootDeploymentDirectory), Times.Once);
        }
        public void GetTestContextShouldReturnAValidTestContext()
        {
            // Arrange.
            var testMethod = new Mock <Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod>();
            var writer     = new StringWriter();
            var properties = new Dictionary <string, object> {
                { "prop", "value" }
            };

            testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
            testMethod.Setup(tm => tm.Name).Returns("M");

            // Act.
            var testContext = PlatformServiceProvider.Instance.GetTestContext(testMethod.Object, writer, properties);

            // Assert.
            Assert.AreEqual("A.C.M", testContext.Context.FullyQualifiedTestClassName);
            Assert.AreEqual("M", testContext.Context.TestName);
            Assert.IsTrue(testContext.Context.Properties.Contains(properties.ToArray()[0].Key));
            Assert.IsTrue(((IDictionary <string, object>)testContext.Context.Properties).Contains(properties.ToArray()[0]));
        }
Beispiel #24
0
        public void RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMethodCannotBeRun()
        {
            var type       = typeof(TypeCacheTests.DummyTestClassWithTestMethods);
            var methodInfo = type.GetMethod("TestMethodWithNullCustomPropertyName");
            var testMethod = new TestMethod(methodInfo.Name, type.FullName, "A", isAsync: false);

            this.testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny <bool>()))
            .Returns(Assembly.GetExecutingAssembly());

            var results = this.unitTestRunner.RunSingleTest(testMethod, this.testRunParameters);

            var expectedMessage = string.Format(
                "UTA021: {0}: Null or empty custom property defined on method {1}. The custom property must have a valid name.",
                methodInfo.DeclaringType.FullName,
                methodInfo.Name);

            Assert.IsNotNull(results);
            Assert.AreEqual(1, results.Length);
            Assert.AreEqual(UnitTestOutcome.NotRunnable, results[0].Outcome);
            Assert.AreEqual(expectedMessage, results[0].ErrorMessage);
        }
Beispiel #25
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);
        }
Beispiel #26
0
        public void DisposeNavigationSessionShouldDisposeNavigationSessionInstance()
        {
            var session = this.fileOperations.CreateNavigationSession(Assembly.GetExecutingAssembly().Location);

            this.fileOperations.DisposeNavigationSession(session);
            var  diaSession        = session as DiaSession;
            bool isExceptionThrown = false;

            try
            {
                diaSession.GetNavigationData(
                    typeof(DesktopFileOperationsTests).FullName,
                    "DisposeNavigationSessionShouldDisposeNavigationSessionInstance");
            }
            catch (NullReferenceException)
            {
                isExceptionThrown = true;
            }

            Assert.IsTrue(isExceptionThrown);
        }
Beispiel #27
0
        public void CurrentSettingShouldReturnCachedLoadedSettings()
        {
            string runSettingxml =
                @"<RunSettings>
                 <MSTest>   
                    <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                 </MSTest>
               </RunSettings>";

            this.mockDiscoveryContext.Setup(dc => dc.RunSettings).Returns(this.mockRunSettings.Object);
            this.mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
            MSTestSettings.PopulateSettings(this.mockDiscoveryContext.Object);

            var adapterSettings  = MSTestSettings.CurrentSettings;
            var adapterSettings2 = MSTestSettings.CurrentSettings;

            Assert.IsNotNull(adapterSettings);
            Assert.IsFalse(string.IsNullOrEmpty(adapterSettings.TestSettingsFile));

            Assert.AreEqual(adapterSettings, adapterSettings2);
        }
        public void ExecuteShouldFillInDebugAndTraceLogsFromAssemblyInitialize()
        {
            StringWriter writer = new StringWriter(new StringBuilder());

            DummyTestClass.AssemblyInitializeMethodBody = (UTFExtension.TestContext tc) =>
            {
                writer.Write("AssemblyInit trace");
            };
            this.testClassInfo.Parent.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("DummyAssemblyInit");
            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, true);

            this.testablePlatformServiceProvider.MockTraceListener.Setup(tl => tl.GetWriter()).Returns(writer);

            var results = testMethodRunner.Execute();

            Assert.AreEqual("AssemblyInit trace", results[0].DebugTrace);
        }
Beispiel #29
0
        public void ToUnitTestResultsForTestResultShouldSetParentInfo()
        {
            var executionId       = Guid.NewGuid();
            var parentExecId      = Guid.NewGuid();
            var innerResultsCount = 5;

            var results = new[]
            {
                new UTF.TestResult()
                {
                    ExecutionId       = executionId,
                    ParentExecId      = parentExecId,
                    InnerResultsCount = innerResultsCount
                }
            };

            var convertedResults = results.ToUnitTestResults();

            Assert.AreEqual(executionId, convertedResults[0].ExecutionId);
            Assert.AreEqual(parentExecId, convertedResults[0].ParentExecId);
            Assert.AreEqual(innerResultsCount, convertedResults[0].InnerResultsCount);
        }
Beispiel #30
0
        public void GetLoadExceptionDetailsShouldReturnLoaderExceptionMessagesForMoreThanOneException()
        {
            var loaderException1 = new ArgumentNullException("DummyLoaderExceptionMessage1", (Exception)null);
            var loaderException2 = new AccessViolationException("DummyLoaderExceptionMessage2");
            var exceptions       = new ReflectionTypeLoadException(
                null,
                new Exception[] { loaderException1, loaderException2 });
            StringBuilder errorDetails = new StringBuilder();

            errorDetails.AppendFormat(
                CultureInfo.CurrentCulture,
                Resource.EnumeratorLoadTypeErrorFormat,
                loaderException1.GetType(),
                loaderException1.Message).AppendLine();
            errorDetails.AppendFormat(
                CultureInfo.CurrentCulture,
                Resource.EnumeratorLoadTypeErrorFormat,
                loaderException2.GetType(),
                loaderException2.Message).AppendLine();

            Assert.AreEqual(errorDetails.ToString(), this.assemblyEnumerator.GetLoadExceptionDetails(exceptions));
        }