Exemplo n.º 1
0
        public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeploymentItems()
        {
            var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");
            var kvparray = new[]
            {
                new KeyValuePair <string, string>(
                    DefaultDeploymentItemPath,
                    DefaultDeploymentItemOutputDirectory)
            };

            testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvparray);

            var testDeployment = new TestDeployment(
                new DeploymentItemUtility(this.mockReflectionUtility.Object),
                new DeploymentUtility(),
                this.mockFileUtility.Object);

            string runSettingxml =
                @"<DeploymentEnabled>False</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));

            // Deplyment directories should not be created
            Assert.IsNull(testDeployment.GetDeploymentDirectory());
        }
Exemplo n.º 2
0
        public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
        {
            this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new ThreadSafeStringWriter(null, "test"), this.properties);

            Assert.IsFalse(this.testContextImplementation.TryGetPropertyValue("Random", out var propValue));
            Assert.IsNull(propValue);
        }
Exemplo n.º 3
0
        public void GetDeploymentItemsReturnsNullWhenNoDeploymentItems()
        {
            var methodInfo =
                typeof(DesktopTestDeploymentTests).GetMethod("GetDeploymentItemsReturnsNullWhenNoDeploymentItems");

            Assert.IsNull(new TestDeployment().GetDeploymentItems(methodInfo, typeof(DesktopTestDeploymentTests), this.warnings));
        }
 public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems()
 {
     Assert.IsNull(this.deploymentItemUtility.GetDeploymentItems(
                       typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"),
                       null,
                       this.warnings));
 }
        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);
        }
        public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue()
        {
            // Arrange
            DummyClass dummyclass    = new DummyClass();
            string     runSettingxml =
                @"<RunSettings>   
                <RunConfiguration>  
                    <DisableAppDomain>True</DisableAppDomain>   
                </RunConfiguration>  
            </RunSettings>";

            var location        = typeof(TestSourceHost).Assembly.Location;
            var mockRunSettings = new Mock <IRunSettings>();

            mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);

            Mock <TestSourceHost> testSourceHost = new Mock <TestSourceHost>(location, mockRunSettings.Object, null)
            {
                CallBase = true
            };

            try
            {
                // Act
                testSourceHost.Object.SetupHost();
                Assert.IsNull(testSourceHost.Object.AppDomain);
            }
            finally
            {
                testSourceHost.Object.Dispose();
            }
        }
Exemplo n.º 7
0
        public void GetNavigationDataShouldNotThrowOnMissingFileNameField()
        {
            try
            {
                FileOperations.Initialize(
                    typeof(MockDiaSession).AssemblyQualifiedName,
                    typeof(MockDiaNavigationData3).AssemblyQualifiedName);
                var navigationData = new MockDiaNavigationData3()
                {
                    MinLineNumber = 123
                };
                MockDiaSession.DiaNavigationData = navigationData;

                var    diaSession = this.fileOperations.CreateNavigationSession(Assembly.GetExecutingAssembly().Location);
                int    minLineNumber;
                string fileName;
                this.fileOperations.GetNavigationData(
                    diaSession,
                    typeof(PortableFileOperationsTests).FullName,
                    "GetNavigationDataShouldReturnDataFromNavigationSession",
                    out minLineNumber,
                    out fileName);

                Assert.AreEqual(123, minLineNumber);
                Assert.IsNull(fileName);
            }
            finally
            {
                MockDiaSession.Reset();
            }
        }
Exemplo n.º 8
0
        public void StringAssertEndsWithIgnoreCase()
        {
            string actual   = "The quick brown fox jumps over the lazy dog.";
            string inString = "LAZY DOG.";
            var    ex       = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.StringAssert.EndsWith(actual, inString, StringComparison.OrdinalIgnoreCase));

            Assert.IsNull(ex);
        }
Exemplo n.º 9
0
        public void StringAssertContainsIgnoreCase()
        {
            string actual   = "The quick brown fox jumps over the lazy dog.";
            string inString = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG.";
            var    ex       = ActionUtility.PerformActionAndReturnException(() => TestFrameworkV2.StringAssert.Contains(actual, inString, StringComparison.OrdinalIgnoreCase));

            Assert.IsNull(ex);
        }
Exemplo n.º 10
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 ResolveEnvironmentVariableShouldReturnFalseForInvalidPath()
        {
            string path          = @"Z:\Program Files (x86)\MsTest\Adapter";
            string baseDirectory = @"C:\unitTesting";

            string result = new TestableMSTestAdapterSettings().ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);

            Assert.IsNull(result);
        }
Exemplo n.º 12
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);
        }
        public void GetTestsShouldReturnNullIfSourceDoesNotReferenceUnitTestFrameworkAssembly()
        {
            var assemblyName = "DummyAssembly.dll";

            // Setup mocks.
            this.SetupMocks(assemblyName, doesFileExist: true, isAssemblyReferenced: false);

            Assert.IsNull(this.testableAssemblyEnumeratorWrapper.GetTests(assemblyName, null, out this.warnings));
        }
Exemplo n.º 14
0
        public void RunClassCleanupShouldInvokeIfClassCleanupMethod()
        {
            var classcleanupCallCount = 0;

            DummyTestClass.ClassCleanupMethodBody = () => classcleanupCallCount++;
            this.testClassInfo.ClassCleanupMethod = typeof(DummyTestClass).GetMethod("ClassCleanupMethod");
            Assert.IsNull(this.testClassInfo.RunClassCleanup());
            Assert.AreEqual(1, classcleanupCallCount);
        }
Exemplo n.º 15
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);
        }
Exemplo n.º 16
0
        public void TryGetStackTraceInformationReturnsStackTraceForAnException()
        {
            var exception = new DummyExceptionForStackTrace(() => "    at A()\r\n    at B()");

            var stackTraceInformation = exception.TryGetStackTraceInformation();

            StringAssert.StartsWith(stackTraceInformation.ErrorStackTrace, "    at A()");
            Assert.IsNull(stackTraceInformation.ErrorFilePath);
            Assert.AreEqual(0, stackTraceInformation.ErrorLineNumber);
        }
Exemplo n.º 17
0
        public void PropertyProviderValueForSupportedPropertyNameWhichIsNotSetReturnsNull()
        {
            var type     = typeof(DummyTestClassWithTestMethods);
            var fullName = $"{type.FullName}.{"TestMethod"}";

            TestCase testCase = new TestCase(fullName, MSTest.TestAdapter.Constants.ExecutorUri, Assembly.GetExecutingAssembly().FullName);
            var      result   = this.TestMethodFilter.PropertyValueProvider(testCase, "Priority");

            Assert.IsNull(result);
        }
Exemplo n.º 18
0
        public void GetFilterExpressionForDiscoveryContextWithGetTestCaseFilterThrowingExceptionReturnsNullWithFilterHasErrorTrue()
        {
            TestableTestExecutionRecorder recorder = new TestableTestExecutionRecorder();
            TestableDiscoveryContextWithGetTestCaseFilter discoveryContext = new TestableDiscoveryContextWithGetTestCaseFilter(() => { throw new TestPlatformFormatException("DummyException"); });
            var filterExpression = this.TestMethodFilter.GetFilterExpression(discoveryContext, recorder, out var filterHasError);

            Assert.IsNull(filterExpression);
            Assert.IsTrue(filterHasError);
            Assert.AreEqual("DummyException", recorder.Message);
            Assert.AreEqual(TestMessageLevel.Error, recorder.TestMessageLevel);
        }
Exemplo n.º 19
0
        public void SetConfigurationFileShouldSetToCurrentDomainsConfigFileIfSourceDoesNotHaveAConfig()
        {
            AppDomainSetup setup = new AppDomainSetup();

            AppDomainUtilities.SetConfigurationFile(setup, null);

            // Assert Config file being set.
            Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, setup.ConfigurationFile);

            Assert.IsNull(setup.GetConfigurationBytes());
        }
Exemplo n.º 20
0
        public void RunAssemblyCleanupShouldNotInvokeIfAssemblyCleanupIsNull()
        {
            var assemblycleanupCallCount = 0;

            DummyTestClass.AssemblyCleanupMethodBody = () => assemblycleanupCallCount++;

            this.testAssemblyInfo.AssemblyCleanupMethod = null;

            Assert.IsNull(this.testAssemblyInfo.RunAssemblyCleanup());
            Assert.AreEqual(0, assemblycleanupCallCount);
        }
Exemplo n.º 21
0
        public void RunClassCleanupShouldNotInvokeIfClassCleanupIsNull()
        {
            var classcleanupCallCount = 0;

            DummyTestClass.ClassCleanupMethodBody = () => classcleanupCallCount++;

            this.testClassInfo.ClassCleanupMethod = null;

            Assert.IsNull(this.testClassInfo.RunClassCleanup());
            Assert.AreEqual(0, classcleanupCallCount);
        }
Exemplo n.º 22
0
        public void RunAssemblyCleanupShouldInvokeIfAssemblyCleanupMethod()
        {
            var assemblycleanupCallCount = 0;

            DummyTestClass.AssemblyCleanupMethodBody = () => assemblycleanupCallCount++;

            this.testAssemblyInfo.AssemblyCleanupMethod = typeof(DummyTestClass).GetMethod("AssemblyCleanupMethod");

            Assert.IsNull(this.testAssemblyInfo.RunAssemblyCleanup());
            Assert.AreEqual(1, assemblycleanupCallCount);
        }
Exemplo n.º 23
0
        public void DisposeShouldUnloadChildAppDomain()
        {
            this.testSourceHost = new TestSourceHost(this.testSource, null, null);
            this.testSourceHost.SetupHost();

            // Check that child appdmon was indeed created
            Assert.IsNotNull(this.testSourceHost.AppDomain);
            this.testSourceHost.Dispose();

            // Check that child-appdomain is now unloaded.
            Assert.IsNull(this.testSourceHost.AppDomain);
        }
Exemplo n.º 24
0
        public void TestSettingsFileIsByDefaultNullWhenNotSpecified()
        {
            string runSettingxml =
                @"<RunSettings>
                    <MSTest>
                    </MSTest>
                  </RunSettings>";

            MSTestSettings adapterSettings = MSTestSettings.GetSettings(runSettingxml, MSTestSettings.SettingsName);

            Assert.IsNull(adapterSettings.TestSettingsFile);
        }
Exemplo n.º 25
0
        public void GetNavigationDataShouldNotThrowOnNullNavigationSession()
        {
            this.fileOperations.GetNavigationData(
                null,
                typeof(DesktopFileOperationsTests).FullName,
                "GetNavigationDataShouldReturnDataFromNavigationSession",
                out var minLineNumber,
                out var fileName);

            Assert.AreEqual(-1, minLineNumber);
            Assert.IsNull(fileName);
        }
Exemplo n.º 26
0
        public void GetTestFromMethodShouldSetWorkItemIdsToNullIfNotAny()
        {
            this.SetupTestClassAndTestMethods(isValidTestClass: true, isValidTestMethod: true, isMethodFromSameAssembly: true);
            TypeEnumerator typeEnumerator = this.GetTypeEnumeratorInstance(typeof(DummyTestClass), "DummyAssemblyName");
            var            methodInfo     = typeof(DummyTestClass).GetMethod("MethodWithVoidReturnType");

            this.mockReflectHelper.Setup(rh => rh.GetCustomAttributes(methodInfo, typeof(UTF.WorkItemAttribute))).Returns(new Attribute[0]);

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

            Assert.IsNull(testElement.WorkItemIds);
        }
Exemplo n.º 27
0
        public void ToTestCaseShouldSetDeclaringClassNameIfPresent()
        {
            this.testMethod.DeclaringClassFullName = null;
            var testCase = this.unitTestElement.ToTestCase();

            Assert.IsNull(testCase.GetPropertyValue(Constants.DeclaringClassNameProperty));

            this.testMethod.DeclaringClassFullName = "DC";
            testCase = this.unitTestElement.ToTestCase();

            Assert.AreEqual("DC", testCase.GetPropertyValue(Constants.DeclaringClassNameProperty));
        }
Exemplo n.º 28
0
        public void ToUnitTestElementForTestCaseWithNoPropertiesShouldReturnUnitTestElementWithDefaultFields()
        {
            TestCase testCase = new TestCase("DummyClass.DummyMethod", new Uri("DummyUri", UriKind.Relative), Assembly.GetCallingAssembly().FullName);

            testCase.SetPropertyValue(Constants.TestClassNameProperty, "DummyClassName");

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

            // These are set for testCase by default by ObjectModel.
            Assert.IsFalse(resultUnitTestElement.IsAsync);
            Assert.AreEqual(0, resultUnitTestElement.Priority);
            Assert.IsNull(resultUnitTestElement.TestCategory);
        }
Exemplo n.º 29
0
        public void RunBaseClassCleanupEvenIfThereIsNoTopLevelClassCleanup()
        {
            var classcleanupCallCount = 0;

            DummyBaseTestClass.ClassCleanupMethodBody = () => classcleanupCallCount++;

            this.testClassInfo.ClassCleanupMethod = null;
            this.testClassInfo.BaseClassCleanupMethodsStack.Push(typeof(DummyBaseTestClass).GetMethod("CleanupClassMethod"));

            Assert.IsTrue(this.testClassInfo.HasExecutableCleanupMethod);
            Assert.IsNull(this.testClassInfo.RunClassCleanup());
            Assert.AreEqual(1, classcleanupCallCount, "DummyBaseTestClass.CleanupClassMethod call count");
        }
Exemplo n.º 30
0
        public void TestClassInfoClassCleanupMethodShouldNotInvokeWhenNoTestClassInitializedIsCalled()
        {
            var classcleanupCallCount = 0;

            DummyTestClass.ClassCleanupMethodBody = () => classcleanupCallCount++;

            this.testClassInfo.ClassCleanupMethod    = typeof(DummyTestClass).GetMethod("ClassCleanupMethod");
            this.testClassInfo.ClassInitializeMethod = typeof(DummyTestClass).GetMethod("ClassInitializeMethod");

            var ret = this.testClassInfo.RunClassCleanup(); // call cleanup without calling init

            Assert.IsNull(ret);
            Assert.AreEqual(0, classcleanupCallCount);
        }