How to use GetExtensionPaths method of Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginCache class

Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework.TestPluginCache.GetExtensionPaths

TestPluginCacheTests.cs

Source:TestPluginCacheTests.cs Github

copy

Full Screen

...45 [TestMethod]46 public void UpdateAdditionalExtensionsShouldNotThrowIfExtensionPathIsNull()47 {48 TestPluginCache.Instance.UpdateExtensions(null, true);49 Assert.IsFalse(TestPluginCache.Instance.GetExtensionPaths(string.Empty).Any());50 }51 [TestMethod]52 public void UpdateAdditionalExtensionsShouldNotThrowIfExtensionPathIsEmpty()53 {54 TestPluginCache.Instance.UpdateExtensions(new List<string>(), true);55 Assert.IsFalse(TestPluginCache.Instance.GetExtensionPaths(string.Empty).Any());56 }57 [TestMethod]58 public void UpdateAdditionalExtensionsShouldUpdateAdditionalExtensions()59 {60 var additionalExtensions = new List<string> { typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location };61 TestPluginCache.Instance.UpdateExtensions(additionalExtensions, false);62 var updatedExtensions = TestPluginCache.Instance.GetExtensionPaths(string.Empty);63 Assert.IsNotNull(updatedExtensions);64 CollectionAssert.AreEqual(additionalExtensions, updatedExtensions.ToList());65 }66 [TestMethod]67 public void UpdateAdditionalExtensionsShouldOnlyAddUniqueExtensionPaths()68 {69 var additionalExtensions = new List<string>70 {71 typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location,72 typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location73 };74 TestPluginCache.Instance.UpdateExtensions(additionalExtensions, false);75 var updatedExtensions = TestPluginCache.Instance.GetExtensionPaths(string.Empty);76 Assert.IsNotNull(updatedExtensions);77 Assert.AreEqual(1, updatedExtensions.Count);78 CollectionAssert.AreEqual(new List<string> { additionalExtensions.First() }, updatedExtensions);79 }80 [TestMethod]81 public void UpdateAdditionalExtensionsShouldUpdatePathsThatDoNotExist()82 {83 var additionalExtensions = new List<string> { "foo.dll" };84 TestPluginCache.Instance.UpdateExtensions(additionalExtensions, false);85 var updatedExtensions = TestPluginCache.Instance.GetExtensionPaths(string.Empty);86 Assert.IsNotNull(updatedExtensions);87 Assert.AreEqual(1, updatedExtensions.Count);88 }89 [TestMethod]90 public void UpdateAdditionalExtensionsShouldUpdateUnfilteredExtensionsListWhenSkipFilteringIsTrue()91 {92 var additionalExtensions = new List<string> { "foo.dll" };93 TestPluginCache.Instance.UpdateExtensions(additionalExtensions, true);94 var updatedExtensions = TestPluginCache.Instance.GetExtensionPaths("testadapter.dll");95 // Since the extension is unfiltered, above filter criteria doesn't filter it96 Assert.IsNotNull(updatedExtensions);97 Assert.AreEqual(1, updatedExtensions.Count);98 }99 [Ignore]100 [TestMethod]101 public void UpdateAdditionalExtensionsShouldResetExtensionsDiscoveredFlag()102 {103 }104 #endregion105 #region ClearExtensions106 [TestMethod]107 public void ClearExtensionsShouldClearPathToExtensions()108 {109 TestPluginCache.Instance.UpdateExtensions(new List<string> { @"oldExtension.dll" }, false);110 TestPluginCache.Instance.ClearExtensions();111 Assert.AreEqual(0, TestPluginCache.Instance.GetExtensionPaths(string.Empty).Count);112 }113 #endregion114 #region GetExtensionPaths115 [TestMethod]116 public void GetExtensionPathsShouldConsolidateAllExtensions()117 {118 var expectedExtensions = new[] { "filter.dll", "unfilter.dll" }.Select(Path.GetFullPath).ToList();119 expectedExtensions.Add("default.dll");120 TestPluginCache.Instance.UpdateExtensions(new[] { @"filter.dll" }, false);121 TestPluginCache.Instance.UpdateExtensions(new[] { @"unfilter.dll" }, true);122 TestPluginCache.Instance.DefaultExtensionPaths = new[] { "default.dll" };123 var extensions = TestPluginCache.Instance.GetExtensionPaths("filter.dll");124 CollectionAssert.AreEquivalent(expectedExtensions, extensions);125 }126 [TestMethod]127 public void GetExtensionPathsShouldFilterFilterableExtensions()128 {129 var expectedExtensions = new[] { "filter.dll", "unfilter.dll" }.Select(Path.GetFullPath).ToList();130 expectedExtensions.Add("default.dll");131 TestPluginCache.Instance.UpdateExtensions(new[] { @"filter.dll", @"other.dll" }, false);132 TestPluginCache.Instance.UpdateExtensions(new[] { @"unfilter.dll" }, true);133 TestPluginCache.Instance.DefaultExtensionPaths = new[] { "default.dll" };134 var extensions = TestPluginCache.Instance.GetExtensionPaths("filter.dll");135 CollectionAssert.AreEquivalent(expectedExtensions, extensions);136 }137 [TestMethod]138 public void GetExtensionPathsShouldNotFilterIfEndsWithPatternIsNullOrEmpty()139 {140 var expectedExtensions = new[] { "filter.dll", "other.dll", "unfilter.dll" }.Select(Path.GetFullPath).ToList();141 expectedExtensions.Add("default.dll");142 TestPluginCache.Instance.UpdateExtensions(new[] { @"filter.dll", @"other.dll" }, false);143 TestPluginCache.Instance.UpdateExtensions(new[] { @"unfilter.dll" }, true);144 TestPluginCache.Instance.DefaultExtensionPaths = new[] { "default.dll" };145 var extensions = TestPluginCache.Instance.GetExtensionPaths(string.Empty);146 CollectionAssert.AreEquivalent(expectedExtensions, extensions);147 }148 [TestMethod]149 public void GetExtensionPathsShouldSkipDefaultExtensionsIfSetTrue()150 {151 var expectedExtensions = new[] { "filter.dll", "unfilter.dll" }.Select(Path.GetFullPath).ToList();152 InvokeGetExtensionPaths(expectedExtensions, true);153 }154 [TestMethod]155 public void GetExtensionPathsShouldNotSkipDefaultExtensionsIfSetFalse()156 {157 var expectedExtensions = new[] { "filter.dll", "unfilter.dll" }.Select(Path.GetFullPath).ToList();158 expectedExtensions.Add("default.dll");159 InvokeGetExtensionPaths(expectedExtensions, false);160 }161 #endregion162 #region GetDefaultResolutionPaths tests163 [TestMethod]164 public void GetDefaultResolutionPathsShouldReturnCurrentDirectoryByDefault()165 {166 var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location);167 var expectedDirectories = new List<string> { currentDirectory };168 var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths();169 Assert.IsNotNull(resolutionPaths);170 CollectionAssert.AreEqual(expectedDirectories, resolutionPaths.ToList());171 }172 [TestMethod]173 public void GetDefaultResolutionPathsShouldReturnAdditionalExtensionPathsDirectories()174 {175 var currentDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location);176 var candidateDirectory = Directory.GetParent(currentDirectory).FullName;177 var extensionPaths = new List<string> { Path.Combine(candidateDirectory, "foo.dll") };178 // Setup mocks.179 var mockFileHelper = new Mock<IFileHelper>();180 mockFileHelper.Setup(fh => fh.DirectoryExists(It.IsAny<string>())).Returns(false);181 var testableTestPluginCache = new TestableTestPluginCache();182 TestPluginCache.Instance = testableTestPluginCache;183 TestPluginCache.Instance.UpdateExtensions(extensionPaths, true);184 var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths();185 var expectedExtensions = new List<string> { candidateDirectory, currentDirectory };186 Assert.IsNotNull(resolutionPaths);187 CollectionAssert.AreEqual(expectedExtensions, resolutionPaths.ToList());188 }189 [TestMethod]190 public void GetDefaultResolutionPathsShouldReturnDirectoryFromDefaultExtensionsPath()191 {192 // Setup the testable instance.193 TestPluginCache.Instance = this.testablePluginCache;194 var defaultExtensionsFile = typeof(TestPluginCache).GetTypeInfo().Assembly.Location;195 this.testablePluginCache.DefaultExtensionPaths = new List<string>() { defaultExtensionsFile };196 var resolutionPaths = TestPluginCache.Instance.GetDefaultResolutionPaths();197 Assert.IsNotNull(resolutionPaths);198 Assert.IsTrue(resolutionPaths.Contains(Path.GetDirectoryName(defaultExtensionsFile)));199 }200 #endregion201 #region GetResolutionPaths tests202 [TestMethod]203 public void GetResolutionPathsShouldThrowIfExtensionAssemblyIsNull()204 {205 Assert.ThrowsException<ArgumentNullException>(() => TestPluginCache.Instance.GetResolutionPaths(null));206 }207 [TestMethod]208 public void GetResolutionPathsShouldReturnExtensionAssemblyDirectoryAndTPCommonDirectory()209 {210 var temp = Path.GetTempPath();211 var resolutionPaths = TestPluginCache.Instance.GetResolutionPaths($@"{temp}{Path.DirectorySeparatorChar}Idonotexist.dll").Select(p => p.Replace("/", "\\")).ToList();212 var tpCommonDirectory = Path.GetDirectoryName(typeof(TestPluginCache).GetTypeInfo().Assembly.Location);213 var expectedPaths = new List<string> { temp, tpCommonDirectory }.ConvertAll(p => p.Replace("/", "\\").TrimEnd('\\'));214 CollectionAssert.AreEqual(expectedPaths, resolutionPaths, $"Collection {string.Join(", ", resolutionPaths)}, is not equal to the expected collection {string.Join(", ", expectedPaths)}.");215 }216 [TestMethod]217 public void GetResolutionPathsShouldNotHaveDuplicatePathsIfExtensionIsInSameDirectory()218 {219 var tpCommonlocation = typeof(TestPluginCache).GetTypeInfo().Assembly.Location;220 var resolutionPaths = TestPluginCache.Instance.GetResolutionPaths(tpCommonlocation);221 var expectedPaths = new List<string> { Path.GetDirectoryName(tpCommonlocation) };222 CollectionAssert.AreEqual(expectedPaths, resolutionPaths.ToList());223 }224 #endregion225 #region GetTestExtensions tests226 [TestMethod]227 public void GetTestExtensionsShouldReturnExtensionsInAssembly()228 {229 TestPluginCacheHelper.SetupMockAdditionalPathExtensions(typeof(TestPluginCacheTests));230 TestPluginCache.Instance.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location);231 Assert.IsNotNull(TestPluginCache.Instance.TestExtensions);232 Assert.IsTrue(TestPluginCache.Instance.TestExtensions.TestDiscoverers.Count > 0);233 }234 [TestMethod]235 public void GetTestExtensionsShouldAddTestExtensionsDiscoveredToCache()236 {237 var extensionAssembly = typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location;238 var testDiscovererPluginInfos = this.testablePluginCache.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(extensionAssembly);239 CollectionAssert.AreEqual(240 this.testablePluginCache.TestExtensions.TestDiscoverers.Keys,241 testDiscovererPluginInfos.Keys);242 }243 [TestMethod]244 public void GetTestExtensionsShouldGetTestExtensionsFromCache()245 {246 var extensionAssembly = typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location;247 var testDiscovererPluginInfos = this.testablePluginCache.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(extensionAssembly);248 Assert.IsFalse(testDiscovererPluginInfos.ContainsKey("td"));249 // Set the cache.250 this.testablePluginCache.TestExtensions.TestDiscoverers.Add("td", new TestDiscovererPluginInformation(typeof(TestPluginCacheTests)));251 testDiscovererPluginInfos = this.testablePluginCache.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(extensionAssembly);252 Assert.IsTrue(testDiscovererPluginInfos.ContainsKey("td"));253 }254 [Ignore]255 [TestMethod]256 public void GetTestExtensionsShouldShouldThrowIfDiscovererThrows()257 {258 //TODO : make ITestDiscoverer interface and then mock it in order to make this test case pass.259 var extensionAssembly = typeof(TestPluginCacheTests).GetTypeInfo().Assembly.Location;260 Assert.ThrowsException<Exception>(() => this.testablePluginCache.GetTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(extensionAssembly));261 }262 #endregion263 #region DiscoverTestExtensions tests264 [TestMethod]265 public void DiscoverTestExtensionsShouldDiscoverExtensionsFromExtensionsFolder()266 {267 TestPluginCacheHelper.SetupMockAdditionalPathExtensions(typeof(TestPluginCacheTests));268 TestPluginCache.Instance.DiscoverTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(TestPlatformConstants.TestAdapterEndsWithPattern);269 Assert.IsNotNull(TestPluginCache.Instance.TestExtensions);270 // Validate the discoverers to be absolutely certain.271 Assert.IsTrue(TestPluginCache.Instance.TestExtensions.TestDiscoverers.Count > 0);272 }273 [TestMethod]274 public void DiscoverTestExtensionsShouldSetCachedBoolToTrue()275 {276 TestPluginCacheHelper.SetupMockAdditionalPathExtensions(typeof(TestPluginCacheTests));277 TestPluginCache.Instance.DiscoverTestExtensions<TestDiscovererPluginInformation, ITestDiscoverer>(TestPlatformConstants.TestAdapterEndsWithPattern);278 Assert.IsTrue(TestPluginCache.Instance.TestExtensions.AreTestDiscoverersCached);279 Assert.IsTrue(TestPluginCache.Instance.TestExtensions.AreTestExtensionsCached<TestDiscovererPluginInformation>());280 }281 #endregion282 private void InvokeGetExtensionPaths(List<string> expectedExtensions, bool skipDefaultExtensions)283 {284 TestPluginCache.Instance.UpdateExtensions(new[] { @"filter.dll", @"other.dll" }, false);285 TestPluginCache.Instance.UpdateExtensions(new[] { @"unfilter.dll" }, true);286 TestPluginCache.Instance.DefaultExtensionPaths = new[] { "default.dll" };287 var extensions = TestPluginCache.Instance.GetExtensionPaths("filter.dll", skipDefaultExtensions);288 CollectionAssert.AreEquivalent(expectedExtensions, extensions);289 }290 }291}...

Full Screen

Full Screen

TestExtensionManagerTests.cs

Source:TestExtensionManagerTests.cs Github

copy

Full Screen

...27 public void UseAdditionalExtensionsShouldUpdateAdditionalExtensionsInCache()28 {29 var extensions = new List<string> { typeof(TestExtensionManagerTests).GetTypeInfo().Assembly.Location };30 this.testExtensionManager.UseAdditionalExtensions(extensions, true);31 CollectionAssert.AreEquivalent(extensions, TestPluginCache.Instance.GetExtensionPaths(string.Empty));32 }33 [TestMethod]34 public void ClearExtensionsShouldClearExtensionsInCache()35 {36 var extensions = new List<string> { @"Foo.dll" };37 this.testExtensionManager.UseAdditionalExtensions(extensions, false);38 this.testExtensionManager.ClearExtensions();39 Assert.AreEqual(0, TestPluginCache.Instance.GetExtensionPaths(string.Empty).Count);40 }41 }42}...

Full Screen

Full Screen

GetExtensionPaths

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;7using System.IO;8using System.Reflection;9{10 {11 static void Main(string[] args)12 {13 TestPluginCache testPluginCache = new TestPluginCache();14 List<string> extensions = testPluginCache.GetExtensionPaths();15 foreach (string extension in extensions)16 {17 Console.WriteLine(extension);18 }19 Console.ReadLine();20 }21 }22}23using System;24using System.Collections.Generic;25using System.Linq;26using System.Text;27using System.Threading.Tasks;28using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;29using System.IO;30using System.Reflection;31{32 {33 static void Main(string[] args)34 {35 TestPluginCache testPluginCache = new TestPluginCache();36 List<string> extensions = testPluginCache.GetExtensionPaths();37 foreach (string extension in extensions)38 {39 Console.WriteLine(extension);40 }41 Console.ReadLine();42 }43 }44}45using System;46using System.Collections.Generic;47using System.Linq;48using System.Text;49using System.Threading.Tasks;50using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;51using System.IO;52using System.Reflection;53{54 {55 static void Main(string[] args)56 {57 TestPluginCache testPluginCache = new TestPluginCache();58 List<string> extensions = testPluginCache.GetExtensionPaths();59 foreach (string extension in extensions)60 {61 Console.WriteLine(extension);62 }63 Console.ReadLine();64 }65 }66}67using System;68using System.Collections.Generic;69using System.Linq;70using System.Text;71using System.Threading.Tasks;72using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;73using System.IO;74using System.Reflection;75{76 {77 static void Main(string[] args)78 {79 TestPluginCache testPluginCache = new TestPluginCache();

Full Screen

Full Screen

GetExtensionPaths

Using AI Code Generation

copy

Full Screen

1var testPluginCache = new TestPluginCache();2var testExtensions = testPluginCache.GetExtensionPaths();3foreach (var testExtension in testExtensions)4{5 Console.WriteLine(testExtension);6}7var testPluginCache = new TestPluginCache();8var testExtensions = testPluginCache.GetExtensionPaths();9foreach (var testExtension in testExtensions)10{11 Console.WriteLine(testExtension);12}13var testPluginCache = new TestPluginCache();14var testExtensions = testPluginCache.GetExtensionPaths();15foreach (var testExtension in testExtensions)16{17 Console.WriteLine(testExtension);18}19var testPluginCache = new TestPluginCache();20var testExtensions = testPluginCache.GetExtensionPaths();21foreach (var testExtension in testExtensions)22{23 Console.WriteLine(testExtension);24}25var testPluginCache = new TestPluginCache();26var testExtensions = testPluginCache.GetExtensionPaths();27foreach (var testExtension in testExtensions)28{29 Console.WriteLine(testExtension);30}31var testPluginCache = new TestPluginCache();32var testExtensions = testPluginCache.GetExtensionPaths();33foreach (var testExtension in testExtensions)34{35 Console.WriteLine(testExtension);36}37var testPluginCache = new TestPluginCache();38var testExtensions = testPluginCache.GetExtensionPaths();39foreach (var testExtension in testExtensions)40{41 Console.WriteLine(testExtension);42}43var testPluginCache = new TestPluginCache();44var testExtensions = testPluginCache.GetExtensionPaths();45foreach (var testExtension in testExtensions)46{47 Console.WriteLine(testExtension

Full Screen

Full Screen

GetExtensionPaths

Using AI Code Generation

copy

Full Screen

1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using System.Threading.Tasks;6using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;7using Microsoft.VisualStudio.TestPlatform.ObjectModel;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;9using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;10using System.Reflection;11using System.IO;12{13 [FriendlyName("TestPlatform")]14 {15 public void Cancel()16 {17 throw new NotImplementedException();18 }19 public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)20 {21 throw new NotImplementedException();22 }23 public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)24 {25 throw new NotImplementedException();26 }27 public void RunTests(IEnumerable<string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle, ITestRunSettings runSettings)28 {29 throw new NotImplementedException();30 }31 public void RunTests(IEnumerable<TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle, ITestRunSettings runSettings)32 {33 throw new NotImplementedException();34 }35 public static void Main(string[] args)36 {37 TestPluginCache testPluginCache = new TestPluginCache();38 testPluginCache.Initialize();39 IEnumerable<string> extensionPaths = testPluginCache.GetExtensionPaths();40 foreach (var path in extensionPaths)41 {42 Console.WriteLine("Extension path: {0}", path);43 }44 }45 }46}47using System;48using System.Collections.Generic;49using System.Linq;50using System.Text;51using System.Threading.Tasks;52using Microsoft.VisualStudio.TestPlatform.Common.ExtensionFramework;53using Microsoft.VisualStudio.TestPlatform.ObjectModel;54using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;55using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;56using System.Reflection;57using System.IO;58{59 [FriendlyName("TestPlatform")]60 {61 public void Cancel()62 {63 throw new NotImplementedException();64 }65 public void RunTests(IEnumerable<string>

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Vstest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful