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));
        }
Exemplo n.º 2
0
        public void ChildDomainResolutionPathsShouldHaveSearchDirectoriesSpecifiedInRunsettings()
        {
            string runSettingxml =
                @"<RunSettings>   
                <RunConfiguration>  
                    <DisableAppDomain>False</DisableAppDomain>   
                </RunConfiguration>  
                <MSTestV2>
                    <AssemblyResolution>
                        <Directory path = "" % Temp %\directory"" includeSubDirectories = ""true"" />
                        <Directory path = ""C:\windows"" includeSubDirectories = ""false"" />
                        <Directory path = "".\ComponentTests"" />
                    </AssemblyResolution>
                </MSTestV2>
             </RunSettings>";

            var testSource = GetTestAssemblyPath("DesktopTestProjectx86Debug.dll");

            this.testSourceHost = new TestSourceHost(testSource, this.GetMockedIRunSettings(runSettingxml).Object, null);
            this.testSourceHost.SetupHost();

            var assemblyResolution = "ComponentTests\\TestProjectForAssemblyResolution.dll";
            var asm  = Assembly.LoadFrom(assemblyResolution);
            var type = asm.GetType("PlatformServices.Desktop.ComponentTests.TestProjectForAssemblyResolution");

            // Creating instance of TestProjectForAssemblyResolution should not throw.
            // It is present in  <Directory path = ".\ComponentTests" />  specified in runsettings
            AppDomainUtilities.CreateInstance(this.testSourceHost.AppDomain, type, null);
        }
Exemplo n.º 3
0
        public void ParentDomainShouldHonourSearchDirectoriesSpecifiedInRunsettings()
        {
            string runSettingxml =
                @"<RunSettings>   
                <RunConfiguration>  
                    <DisableAppDomain>True</DisableAppDomain>   
                </RunConfiguration>  
                <MSTestV2>
                    <AssemblyResolution>
                        <Directory path = "" % Temp %\directory"" includeSubDirectories = ""true"" />
                        <Directory path = ""C:\windows"" includeSubDirectories = ""false"" />
                        <Directory path = "".\ComponentTests"" />
                    </AssemblyResolution>
                </MSTestV2>
             </RunSettings>";

            var testSource = GetTestAssemblyPath("DesktopTestProjectx86Debug.dll");

            this.testSourceHost = new TestSourceHost(testSource, this.GetMockedIRunSettings(runSettingxml).Object, null);
            this.testSourceHost.SetupHost();

            // Loading TestProjectForAssemblyResolution.dll should not throw.
            // It is present in  <Directory path = ".\ComponentTests" />  specified in runsettings
            Assembly.Load("TestProjectForAssemblyResolution");
        }
Exemplo n.º 4
0
        public void GetResolutionPathsShouldAddTestPlatformFolderPath()
        {
            // Setup
            TestSourceHost sut = new TestSourceHost(null, null, null);

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

            // Assert
            Assert.AreEqual(result.Contains(typeof(AssemblyHelper).Assembly.Location), false);
        }
Exemplo n.º 5
0
        public void GetResolutionPathsShouldAddAdapterFolderPath()
        {
            // Setup
            TestSourceHost sut = new TestSourceHost(null, null, null);

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

            // Assert
            Assert.IsFalse(result.Contains(typeof(TestSourceHost).Assembly.Location));
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an instance to the platform service for a test source host.
        /// </summary>
        /// <param name="source">
        /// The source.
        /// </param>
        /// <param name="runSettings">
        /// The run Settings for the session.
        /// </param>
        /// <param name="frameworkHandle">
        /// The handle to the the test platform.
        /// </param>
        /// <returns>
        /// Returns the host for the source provided.
        /// </returns>
        public ITestSourceHost CreateTestSourceHost(
            string source,
            TestPlatform.ObjectModel.Adapter.IRunSettings runSettings,
            TestPlatform.ObjectModel.Adapter.IFrameworkHandle frameworkHandle)
        {
            var testSourceHost = new TestSourceHost(source, runSettings, frameworkHandle);

            testSourceHost.SetupHost();

            return(testSourceHost);
        }
Exemplo n.º 7
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.º 8
0
        public void GetResolutionPathsShouldNotAddPublicAndPrivateAssemblyPathInPortableMode()
        {
            // Setup
            TestSourceHost sut = new TestSourceHost(null, null, null);

            // Execute
            // It should not return public and private path if it is running in portable mode.
            List <string> result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: true);

            // Assert
            Assert.AreEqual(result.Contains(VSInstallationUtilities.PathToPublicAssemblies), false);
            Assert.AreEqual(result.Contains(VSInstallationUtilities.PathToPrivateAssemblies), false);
        }
Exemplo n.º 9
0
        public void DisposeShouldUnloadChildAppDomain()
        {
            var testSource = GetTestAssemblyPath("DesktopTestProjectx86Debug.dll");

            this.testSourceHost = new TestSourceHost(testSource, null, null);
            this.testSourceHost.SetupHost();

            // Check that child appdomain 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.º 10
0
        public void DisposeShouldSetTestHostShutdownOnIssueWithAppDomainUnload()
        {
            // Arrange
            var frameworkHandle   = new Mock <IFrameworkHandle>();
            var testableAppDomain = new Mock <IAppDomain>();

            testableAppDomain.Setup(ad => ad.CreateDomain(It.IsAny <string>(), It.IsAny <Evidence>(), It.IsAny <AppDomainSetup>())).Returns(AppDomain.CurrentDomain);
            testableAppDomain.Setup(ad => ad.Unload(It.IsAny <AppDomain>())).Throws(new CannotUnloadAppDomainException());
            var sourceHost = new TestSourceHost(typeof(DesktopTestSourceHostTests).Assembly.Location, null, frameworkHandle.Object, testableAppDomain.Object);

            sourceHost.SetupHost();

            // Act
            sourceHost.Dispose();

            // Assert
            frameworkHandle.VerifySet(fh => fh.EnableShutdownAfterTestRun = true);
        }
Exemplo n.º 11
0
        public void GetResolutionPathsShouldAddPublicAndPrivateAssemblyPath()
        {
            // Setup
            TestSourceHost sut = new TestSourceHost(null, null, null);

            // Execute
            // It should return public and private path if it is not running in portable mode.
            List <string> result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: false);

            // Assert
            if (!string.IsNullOrWhiteSpace(VSInstallationUtilities.PathToPublicAssemblies))
            {
                Assert.IsTrue(result.Contains(VSInstallationUtilities.PathToPublicAssemblies));
            }

            if (!string.IsNullOrWhiteSpace(VSInstallationUtilities.PathToPrivateAssemblies))
            {
                Assert.IsTrue(result.Contains(VSInstallationUtilities.PathToPrivateAssemblies));
            }
        }
        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);
        }
Exemplo n.º 13
0
        public void ChildDomainResolutionPathsShouldHaveSearchDirectoriesSpecifiedInRunsettings()
        {
            string runSettingxml =
                @"<RunSettings>   
                <RunConfiguration>  
                    <DisableAppDomain>False</DisableAppDomain>   
                </RunConfiguration>  
                <MSTestV2>
                    <AssemblyResolution>
                        <Directory path = "" % Temp %\directory"" includeSubDirectories = ""true"" />
                        <Directory path = ""C:\windows"" includeSubDirectories = ""false"" />
                        <Directory path = "".\ComponentTests"" />
                    </AssemblyResolution>
                </MSTestV2>
             </RunSettings>";

            this.testSourceHost = new TestSourceHost(this.testSource, this.GetMockedIRunSettings(runSettingxml).Object, null);

            this.testSourceHost.SetupHost();

            // Creating instance of TestProjectForAssemblyResolution should not throw.
            // It is present in  <Directory path = ".\ComponentTests" />  specified in runsettings
            AppDomainUtilities.CreateInstance(this.testSourceHost.AppDomain, typeof(TestProjectForAssemblyResolution), null);
        }
Exemplo n.º 14
0
 public void TestInit()
 {
     this.testSourceHost = new TestSourceHost(null, null, null);
 }