public void ExecuteShouldKillTheThreadExecutingAsyncOnTimeout()
        {
            ManualResetEvent timeoutMutex = new ManualResetEvent(false);
            var hasReachedEnd             = false;
            var isThreadAbortThrown       = false;

            Action action = () =>
            {
                try
                {
                    timeoutMutex.WaitOne();
                    hasReachedEnd = true;
                }
                catch (ThreadAbortException)
                {
                    isThreadAbortThrown = true;

                    // Resetting abort because there is a warning being thrown in the tests pane.
                    Thread.ResetAbort();
                }
            };

            Assert.IsFalse(this.asyncOperations.Execute(action, 1));
            timeoutMutex.Set();

            Assert.IsFalse(hasReachedEnd);
            Assert.IsTrue(isThreadAbortThrown);
        }
예제 #2
0
        public void PopulateSettingsShouldFillInSettingsFromSettingsObject()
        {
            string runsettingsXml =
                @"<RunSettings>
                 <MSTest>
                   <CaptureTraceOutput>False</CaptureTraceOutput> 
                   <MapInconclusiveToFailed>True</MapInconclusiveToFailed>
                   <MapNotRunnableToFailed>True</MapNotRunnableToFailed>
                   <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                   <ForcedLegacyMode>true</ForcedLegacyMode>
                   <EnableBaseClassTestMethodsFromOtherAssemblies>true</EnableBaseClassTestMethodsFromOtherAssemblies>
                   <TreatClassAndAssemblyCleanupWarningsAsErrors>true</TreatClassAndAssemblyCleanupWarningsAsErrors>
                 </MSTest>
               </RunSettings>";

            var settings = MSTestSettings.GetSettings(runsettingsXml, MSTestSettings.SettingsName);

            MSTestSettings.PopulateSettings(settings);

            Assert.IsFalse(MSTestSettings.CurrentSettings.CaptureDebugTraces);
            Assert.IsTrue(MSTestSettings.CurrentSettings.MapInconclusiveToFailed);
            Assert.IsTrue(MSTestSettings.CurrentSettings.MapNotRunnableToFailed);
            Assert.IsTrue(MSTestSettings.CurrentSettings.ForcedLegacyMode);
            Assert.IsTrue(MSTestSettings.CurrentSettings.EnableBaseClassTestMethodsFromOtherAssemblies);
            Assert.IsTrue(MSTestSettings.CurrentSettings.TreatClassAndAssemblyCleanupWarningsAsErrors);
            Assert.IsFalse(string.IsNullOrEmpty(MSTestSettings.CurrentSettings.TestSettingsFile));
        }
예제 #3
0
        public void TestClassInfoHasExecutableCleanupMethodShouldReturnFalseIfClassInitializeThrowsAnException()
        {
            this.testClassInfo.ClassCleanupMethod           = this.testClassType.GetMethods().First();
            this.testClassInfo.ClassInitializationException = new NotImplementedException();

            Assert.IsFalse(this.testClassInfo.HasExecutableCleanupMethod);
        }
예제 #4
0
        public void PopulateSettingsShouldInitializeSettingsFromMSTestSection()
        {
            string runSettingxml =
                @"<RunSettings>
                 <MSTest>
                   <MapInconclusiveToFailed>True</MapInconclusiveToFailed>
                   <MapNotRunnableToFailed>True</MapNotRunnableToFailed>
                   <SettingsFile>DummyPath\\TestSettings1.testsettings</SettingsFile>
                   <ForcedLegacyMode>true</ForcedLegacyMode>
                   <EnableBaseClassTestMethodsFromOtherAssemblies>true</EnableBaseClassTestMethodsFromOtherAssemblies>
                 </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;

            Assert.IsNotNull(adapterSettings);

            Assert.IsTrue(adapterSettings.MapInconclusiveToFailed);
            Assert.IsTrue(adapterSettings.MapNotRunnableToFailed);
            Assert.IsTrue(adapterSettings.ForcedLegacyMode);
            Assert.IsTrue(adapterSettings.EnableBaseClassTestMethodsFromOtherAssemblies);
            Assert.IsFalse(string.IsNullOrEmpty(adapterSettings.TestSettingsFile));
        }
예제 #5
0
        public void DeployShouldReturnFalseWhenNoDeploymentItemsOnTestCase()
        {
            var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");

            testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null);
            var testRunDirectories = new TestRunDirectories(RootDeploymentDirectory);

            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(It.IsAny <string>()))
            .Returns(new List <string> {
            });

            Assert.IsFalse(
                this.deploymentUtility.Deploy(
                    new List <TestCase> {
                testCase
            },
                    testCase.Source,
                    this.mockRunContext.Object,
                    this.mocktestExecutionRecorder.Object,
                    testRunDirectories));
        }
예제 #6
0
        public void IsValidTestMethodShouldReturnFalseForGenericTestMethods()
        {
            this.SetupTestMethod();
            Action action = () => new DummyTestClassWithGenericMethods().GenericMethod <int>();

            Assert.IsFalse(this.testMethodValidator.IsValidTestMethod(action.Method, typeof(DummyTestClassWithGenericMethods), this.warnings));
        }
        public void ExecuteShouldKillTheThreadExecutingAsyncOnTimeout()
        {
            ManualResetEvent timeoutMutex    = new ManualResetEvent(false);
            ManualResetEvent actionCompleted = new ManualResetEvent(false);
            var hasReachedEnd           = false;
            var isThreadAbortThrown     = false;
            var cancellationTokenSource = new CancellationTokenSource();

            void action()
            {
                try
                {
                    timeoutMutex.WaitOne();
                    hasReachedEnd = true;
                }
                catch (ThreadAbortException)
                {
                    isThreadAbortThrown = true;

                    // Resetting abort because there is a warning being thrown in the tests pane.
                    Thread.ResetAbort();
                }
                finally
                {
                    actionCompleted.Set();
                }
            }

            Assert.IsFalse(this.asyncOperations.Execute(action, 1, cancellationTokenSource.Token));
            timeoutMutex.Set();
            actionCompleted.WaitOne();

            Assert.IsFalse(hasReachedEnd, "Execution Completed successfully");
            Assert.IsTrue(isThreadAbortThrown, "ThreadAbortException not thrown");
        }
        public void CheckResolutionPathsDoNotContainPrivateAssembliesPathTest()
        {
            TestSourceHost isolatedHost = new TestSourceHost(null, null, null);
            List <string>  paths        = isolatedHost.GetResolutionPaths(Assembly.GetExecutingAssembly().FullName, true);

            Assert.IsFalse(paths.Contains(Constants.PublicAssemblies) || paths.Contains(Constants.PrivateAssemblies));
        }
예제 #9
0
        public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploymentItems()
        {
            var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");

            testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null);
            var testDeployment = new TestDeployment(
                new DeploymentItemUtility(this.mockReflectionUtility.Object),
                new DeploymentUtility(),
                this.mockFileUtility.Object);

            string runSettingxml =
                @"<DeploymentEnabled>True</DeploymentEnabled>";
            StringReader           stringReader           = new StringReader(runSettingxml);
            XmlReader              reader                 = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
            MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider();

            mstestSettingsProvider.Load(reader);

            // Deployment should not happen
            Assert.IsFalse(testDeployment.Deploy(new List <TestCase> {
                testCase
            }, null, null));

            // Deployment directories should get created
            Assert.IsNotNull(testDeployment.GetDeploymentDirectory());
        }
예제 #10
0
        public void GetTestsShouldNotReturnHiddenTestMethodsFromAnyLevel()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummySecondHidingTestClass), Assembly.GetExecutingAssembly().FullName);

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

            Assert.IsNotNull(tests);
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "BaseTestMethod"),
                "DummySecondHidingTestClass hides BaseTestMethod so it should be discovered.");
            Assert.AreEqual(
                1,
                tests.Count(t => t.TestMethod.Name == "DerivedTestMethod"),
                "DummySecondHidingTestClass hides DerivedTestMethod so it should be discovered.");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyBaseTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyHidingTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
            Assert.IsFalse(
                tests.Any(t => t.TestMethod.DeclaringClassFullName == typeof(DummyOverridingTestClass).FullName),
                "DummySecondHidingTestClass hides all base test methods so declaring class should not be any base class");
        }
예제 #11
0
        public void GetFilterExpressionForNullRunContextReturnsNull()
        {
            TestableTestExecutionRecorder recorder = new TestableTestExecutionRecorder();
            var filterExpression = this.TestMethodFilter.GetFilterExpression(null, recorder, out var filterHasError);

            Assert.IsNull(filterExpression);
            Assert.IsFalse(filterHasError);
        }
        public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsEmpty()
        {
            string warning;

            Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(string.Empty, this.defaultDeploymentItemOutputDirectory, out warning));

            StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning);
        }
        public void HasDeployItemsShouldReturnFalseForNoDeploymentItems()
        {
            TestCase testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");

            testCase.SetPropertyValue(DeploymentItemsProperty, null);

            Assert.IsFalse(this.deploymentItemUtility.HasDeploymentItems(testCase));
        }
        public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsNull()
        {
            string warning;

            Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, null, out warning));

            StringAssert.Contains(Resource.DeploymentItemOutputDirectoryCannotBeNull, warning);
        }
예제 #15
0
        public void WhenInternalDiscoveryIsEnabledIsValidTestClassShouldReturnFalseForInaccessibleTestClasses()
        {
            var typeValidator = new TypeValidator(this.mockReflectHelper.Object, true);

            var inaccessibleClassType = Assembly.GetExecutingAssembly().GetTypes().First(t => t.Name == "InaccessiblePublicClass");

            this.SetupTestClass();
            Assert.IsFalse(typeValidator.IsValidTestClass(inaccessibleClassType, this.warnings));
        }
예제 #16
0
        public void IsValidTestMethodShouldReturnFalseForAbstractMethods()
        {
            this.SetupTestMethod();
            var methodInfo = typeof(DummyTestClass).GetMethod(
                "AbstractTestMethod",
                BindingFlags.Instance | BindingFlags.Public);

            Assert.IsFalse(this.testMethodValidator.IsValidTestMethod(methodInfo, typeof(DummyTestClass), this.warnings));
        }
예제 #17
0
        public void IsValidTestMethodShouldReturnFalseForGenericTestMethodDefinitions()
        {
            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");

            Assert.IsFalse(this.testMethodValidator.IsValidTestMethod(this.mockMethodInfo.Object, this.type, this.warnings));
        }
예제 #18
0
        public void IsValidTestMethodShouldReturnFalseForMethodsWithNonVoidReturnType()
        {
            this.SetupTestMethod();
            var methodInfo = typeof(DummyTestClass).GetMethod(
                "MethodWithIntReturnType",
                BindingFlags.Instance | BindingFlags.Public);

            Assert.IsFalse(this.testMethodValidator.IsValidTestMethod(methodInfo, typeof(DummyTestClass), this.warnings));
        }
예제 #19
0
        public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);

            object propValue;

            Assert.IsFalse(this.testContextImplementation.TryGetPropertyValue("Random", out propValue));
            Assert.IsNull(propValue);
        }
예제 #20
0
        public void GetFilterExpressionForDiscoveryContextWithoutGetTestCaseFilterReturnsNullTestCaseFilterExpression()
        {
            TestableTestExecutionRecorder recorder = new TestableTestExecutionRecorder();
            TestableDiscoveryContextWithoutGetTestCaseFilter discoveryContext = new TestableDiscoveryContextWithoutGetTestCaseFilter();
            var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out var filterHasError);

            Assert.IsNull(filterExpression);
            Assert.IsFalse(filterHasError);
        }
예제 #21
0
        public void IsIgnoreAttributeOnTestClassReturnsFalseIfIgnoreIsNotSetOnTestClass()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameType: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");

            // Setup mocks
            this.mockReflectHelper.Setup(rh => rh.IsAttributeDefined(typeof(DummyTestClass), typeof(UTF.IgnoreAttribute), It.IsAny <bool>())).Returns(false);

            Assert.IsFalse(typeEnumerator.IsIgnoreAttributeOnTestClass);
        }
예제 #22
0
        public void CurrentSettingShouldReturnDefaultSettingsIfNotSet()
        {
            MSTestSettings.Reset();
            var adapterSettings = MSTestSettings.CurrentSettings;

            Assert.IsNotNull(adapterSettings);

            // Validating the default value of a random setting.
            Assert.IsFalse(adapterSettings.ForcedLegacyMode);
        }
예제 #23
0
        public void IsUnitTestAssertExceptionReturnsFalseIfExceptionIsNotAssertException()
        {
            var exception = new NotImplementedException();

            UTF.UnitTestOutcome outcome          = UTF.UnitTestOutcome.Unknown;
            string exceptionMessage              = null;
            StackTraceInformation stackTraceInfo = null;

            Assert.IsFalse(exception.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out stackTraceInfo));
        }
예제 #24
0
        public void GetFilterExpressionForDiscoveryContextWithGetTestCaseFilterReturnsValidTestCaseFilterExpression()
        {
            TestableTestExecutionRecorder recorder = new TestableTestExecutionRecorder();
            var dummyFilterExpression = new TestableTestCaseFilterExpression();
            TestableDiscoveryContextWithGetTestCaseFilter discoveryContext = new TestableDiscoveryContextWithGetTestCaseFilter(() => dummyFilterExpression);
            var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out var filterHasError);

            Assert.AreEqual(dummyFilterExpression, filterExpression);
            Assert.IsFalse(filterHasError);
        }
예제 #25
0
        public void AreValidSourcesShouldReturnFalseIfValidSourceExtensionsIsEmpty()
        {
            this.testablePlatformServiceProvider.MockTestSourceValidator.SetupGet(ts => ts.ValidSourceExtensions).Returns(new List <string> {
            });
            MSTestDiscoverer discoverer = new MSTestDiscoverer();

            Assert.IsFalse(discoverer.AreValidSources(new List <string> {
                "dummy.te"
            }));
        }
예제 #26
0
        public void PopulateSettingsShouldInitializeDefaultSettingsWhenRunSettingsIsNull()
        {
            MSTestSettings.PopulateSettings(this.mockDiscoveryContext.Object);

            MSTestSettings adapterSettings = MSTestSettings.CurrentSettings;

            Assert.IsTrue(adapterSettings.CaptureDebugTraces);
            Assert.IsFalse(adapterSettings.MapInconclusiveToFailed);
            Assert.IsTrue(adapterSettings.MapNotRunnableToFailed);
            Assert.IsTrue(adapterSettings.EnableBaseClassTestMethodsFromOtherAssemblies);
        }
예제 #27
0
        public void GetFilterExpressionForValidRunContextReturnsValidTestCaseFilterExpression()
        {
            TestableTestExecutionRecorder recorder = new TestableTestExecutionRecorder();
            var dummyFilterExpression     = new TestableTestCaseFilterExpression();
            TestableRunContext runContext = new TestableRunContext(() => dummyFilterExpression);
            bool filterHasError;
            var  filterExpression = this.TestMethodFilter.GetFilterExpression(runContext, recorder, out filterHasError);

            Assert.AreEqual(dummyFilterExpression, filterExpression);
            Assert.IsFalse(filterHasError);
        }
예제 #28
0
        public void GetResolutionPathsShouldAddTestPlatformFolderPath()
        {
            // Setup
            TestSourceHost sut = new TestSourceHost(null, null, null);

            // Execute
            List <string> result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: false);

            // Assert
            Assert.IsFalse(result.Contains(typeof(AssemblyHelper).Assembly.Location));
        }
예제 #29
0
        public void WhenDiscoveryOfInternalsIsEnabledIsValidTestMethodShouldReturnFalseForPrivateMethods()
        {
            this.SetupTestMethod();
            var methodInfo = typeof(DummyTestClass).GetMethod(
                "PrivateTestMethod",
                BindingFlags.Instance | BindingFlags.NonPublic);

            var testMethodValidator = new TestMethodValidator(this.mockReflectHelper.Object, true);

            Assert.IsFalse(testMethodValidator.IsValidTestMethod(methodInfo, typeof(DummyTestClass), this.warnings));
        }
예제 #30
0
        public void DisableParallelizationShouldBeFalseByDefault()
        {
            string runSettingxml =
                @"<RunSettings>
                  </RunSettings>";

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

            Assert.IsFalse(MSTestSettings.CurrentSettings.DisableParallelization);
        }