From 9d3fbce5226564e5da99a01250e2bddce922ce06 Mon Sep 17 00:00:00 2001 From: Sarabjot Singh Date: Mon, 11 Sep 2017 20:46:47 +0530 Subject: [PATCH] Highest version filtering for extensions. (#1051) * Changes for filtering in case multiple extensions with same name are found. Keep only the highest versioned extensions. --- .../Helpers/FileHelper.cs | 10 +++ .../Helpers/Interfaces/IFileHelper.cs | 9 ++ ...icrosoft.TestPlatform.CoreUtilities.csproj | 7 +- .../Microsoft.TestPlatform.ObjectModel.csproj | Bin 7458 -> 3642 bytes .../Hosting/DefaultTestHostManager.cs | 81 +++++++++++++++++- .../Hosting/DotnetTestHostManager.cs | 5 +- .../Resources/Resources.Designer.cs | 12 ++- .../Resources/Resources.resx | 4 + .../Resources/xlf/Resources.cs.xlf | 7 ++ .../Resources/xlf/Resources.de.xlf | 7 ++ .../Resources/xlf/Resources.es.xlf | 7 ++ .../Resources/xlf/Resources.fr.xlf | 7 ++ .../Resources/xlf/Resources.it.xlf | 7 ++ .../Resources/xlf/Resources.ja.xlf | 7 ++ .../Resources/xlf/Resources.ko.xlf | 7 ++ .../Resources/xlf/Resources.pl.xlf | 7 ++ .../Resources/xlf/Resources.pt-BR.xlf | 7 ++ .../Resources/xlf/Resources.ru.xlf | 7 ++ .../Resources/xlf/Resources.tr.xlf | 7 ++ .../Resources/xlf/Resources.xlf | 7 ++ .../Resources/xlf/Resources.zh-Hans.xlf | 7 ++ .../Resources/xlf/Resources.zh-Hant.xlf | 7 ++ .../Hosting/DefaultTestHostManagerTests.cs | 58 ++++++++++++- 23 files changed, 277 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs index ba0070cae9..10ea025a47 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/FileHelper.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers { using System; using System.Collections.Generic; + using System.Diagnostics; using System.IO; using System.Linq; @@ -15,6 +16,8 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers /// public class FileHelper : IFileHelper { + private static readonly Version DefaultFileVersion = new Version(0, 0); + /// public DirectoryInfo CreateDirectory(string path) { @@ -69,6 +72,13 @@ public FileAttributes GetFileAttributes(string path) return new FileInfo(path).Attributes; } + /// + public Version GetFileVersion(string path) + { + var currentFileVersion = FileVersionInfo.GetVersionInfo(path)?.FileVersion; + return Version.TryParse(currentFileVersion, out var currentVersion) ? currentVersion : DefaultFileVersion; + } + /// public void CopyFile(string sourcePath, string destinationPath) { diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs index 8127237c83..5c9631ed67 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs +++ b/src/Microsoft.TestPlatform.CoreUtilities/Helpers/Interfaces/IFileHelper.cs @@ -3,7 +3,9 @@ namespace Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces { + using System; using System.Collections.Generic; + using System.Diagnostics; using System.IO; /// @@ -63,6 +65,13 @@ public interface IFileHelper /// Attributes of the file. FileAttributes GetFileAttributes(string path); + /// + /// Gets the version information of the file. + /// + /// Full path to the file. + /// File Version information of the file. + Version GetFileVersion(string path); + /// /// Copy a file in the file system. /// diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj index e369d739e8..b51c04cd12 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj +++ b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj @@ -9,7 +9,7 @@ netstandard1.4;net451 - + @@ -19,6 +19,11 @@ + + + 4.3.0 + + True diff --git a/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj b/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj index fd454c6acf61501b1bc603370f5924d3d87140ec..67806f0b608e6cd29deb1c42082b20290cb56e4a 100644 GIT binary patch literal 3642 zcmcgvUvJws5P#375QG6IUR?ss>;Bmep9Z}-h}6k1!5DiC~Z56Qr`fct_4d^5Haz3vas z?Kj?uJCov9@U=B(Phe(zB52wUE)h z5Zamu&H|lU`{Bp-+gH|jZ1sA!N5~R?uG3aX?Km$Cxzi{XQd_x~W4q(i%9lZ`m9t8M zkTpI`=AbnOtca#^16tXZvp1kCr65{`yE__zR{`-cPzep^I$?nzb+5^Xl>zQnFbG|z zu{%d7wfR=!_kI)dNqHRf=xq2J|CFYjQOSm6giy5gvh6eKKhX_LSiKoKTuww330|(#*9ErDv~I~QSM>t1 zdYH#%*spqNiDVe{thDejl6zQ##KNulH{U6=KpvwoH~Cq$`-JNt0xSg?&@lL&niBmF z8;?-^tV&f$lldnq<6PO@2UFf&cY@bKE|GqLyw*8V2*NwyAgLD8TfnnkKonztV)?%f zLMY$4PWhOb!j12#(kT6q=s3~deq$1=z;&A1S+P3C->iqrgs02K3QgsW+>utKg$k=i zp-+T_2OWgSE})K5BEE`|*N((G@0|{x@=_~mXv#Gp6=ErE10NL0qbGX_jvu$o$Ts39k39LgT9V}sT3z{;jX_f!N#*myHX>xBB9^I@pCaaqE za2Q=pNoF#LFvnX^FJt<;Fd}!5#~Ib142xU~KZ$_X8mRzsLO_0(D(&$y91u}N7P^^l# z*AN3|SY8iUa9-PJ#^Oz#oR)IW55`fB2=ZMbsLUPb`=JEAIQtyVlrdbTs2ZW@+M}7T z6Fdf%(ykfX#Jh~BW1yRa*Yj6owK;d&S*;~v&xmeEooBf%?kL;R+w7oM_G}rjIWrsw zLo+cOK}Ez8Njko6)jyrmA0v L(yyDljCb-cW5&Zj literal 7458 zcmds6TW`}?5T56i_CG`jY2l$xfKq`7L0k&z3Q9!-;vp{~7dDWaVuvlD{p-8?eKS7t z?buF3vRk33abwS!GxN>;_@BSq@<=XZCR1t17a7S)LYc@y=JHUk$t?+_g=+&(<}$$j zA)e0Vqdr|rBx5-M)e&eONk@K_U!*N(;IfcUSTg`cL(Z}4v#xlB)dPJRf?|xPft<>* zba6GRYcZDw);Uf~l`E33@MheU)ng+L^q;J`0uNDXw#sKT2tM zU2b6a>a{l^%R_t`@*6&sFuzBfIW_Ho{nX!{&` zn}mO=H9kY04san7hjJI*{~-QF|Ld!darIE6=TP_U;=V)A&o8_G8R!RynZ6=^0$zS} zw!y&1+wD$_%+u<+3e00%V>Lwy`d6AD*7AQJbNa&3gGP#aa^q7s|YhbJiE2!yL-~CQDE1 zvHJZilg|>LNc{Gla&=vE2R%U`cktIz&&xk`KIOcvPSfm;?6cCH!FI^7hA>*$om;OT zz&F^>^ihc!@%@s#kk^Lu!9H}|CgOHqiT(YYzcTN_E}PcXKzlUSUyE+eZS2XjzG5Dh zx7bzpPU}|KwGhz=_0)AR&k&CT)B|=MjOESsZGp$FD;kZ~t8&g`&7oeddKrfqrm z3DDrwG!)J-UvY162?X{Lqvl^f?)TLQbfGI}5u4tL2IpaZZ*KpqtbMlbRCUvV{0__0 zPkt87eRas$`&fHT`o62I|96JlrY2=Gayy<(m&n_!zYTP0%edl}&%brk>@#p8MjwF{ z42Vi~GmgnJ?mQozp?WBmbh5mU~yi(-)ot{5Nk+s&;oV nN!ym|p6Iim_gX#J&Ar#^RlFJE$%cCmlYNVo$nV}9nauwJuKLGT diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index cc7f30a153..0e0527d6ad 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -6,14 +6,15 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using System; using System.Collections.Generic; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; using System.Reflection; using System.Text; using System.Threading; using System.Threading.Tasks; - using Microsoft.TestPlatform.TestHostProvider.Hosting; + using Microsoft.TestPlatform.TestHostProvider.Resources; using Microsoft.VisualStudio.TestPlatform.CoreUtilities.Extensions; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers; using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Helpers.Interfaces; @@ -194,6 +195,8 @@ public IEnumerable GetTestPlatformExtensions(IEnumerable sources extensions = extensions.Concat(sources.SelectMany(s => this.fileHelper.EnumerateFiles(Path.GetDirectoryName(s), SearchOption.TopDirectoryOnly, TestAdapterEndsWithPattern))); } + extensions = this.FilterExtensionsBasedOnVersion(extensions); + return extensions; } @@ -250,6 +253,82 @@ public Task CleanTestHostAsync(CancellationToken cancellationToken) return Task.FromResult(true); } + /// + /// Filter duplicate extensions, include only the highest versioned extension + /// + /// Entire list of extensions + /// Filtered list of extensions + private IEnumerable FilterExtensionsBasedOnVersion(IEnumerable extensions) + { + Dictionary selectedExtensions = new Dictionary(); + Dictionary highestFileVersions = new Dictionary(); + Dictionary conflictingExtensions = new Dictionary(); + + foreach (var extensionFullPath in extensions) + { + // assemblyName is the key + var extensionAssemblyName = Path.GetFileNameWithoutExtension(extensionFullPath); + + if (selectedExtensions.TryGetValue(extensionAssemblyName, out var oldExtensionPath)) + { + // This extension is duplicate + var currentVersion = this.GetAndLogFileVersion(extensionFullPath); + + var oldVersionFound = highestFileVersions.TryGetValue(extensionAssemblyName, out var oldVersion); + if (!oldVersionFound) + { + oldVersion = this.GetAndLogFileVersion(oldExtensionPath); + } + + // If the version of current file is higher than the one in the map + // replace the older with the current file + if (currentVersion > oldVersion) + { + highestFileVersions[extensionAssemblyName] = currentVersion; + conflictingExtensions[extensionAssemblyName] = currentVersion; + selectedExtensions[extensionAssemblyName] = extensionFullPath; + } + else + { + if (currentVersion < oldVersion) + { + conflictingExtensions[extensionAssemblyName] = oldVersion; + } + + if (!oldVersionFound) + { + highestFileVersions.Add(extensionAssemblyName, oldVersion); + } + } + } + else + { + selectedExtensions.Add(extensionAssemblyName, extensionFullPath); + } + } + + // Log warning if conflicting version extensions are found + if (conflictingExtensions.Any()) + { + var extensionsString = string.Join("\n", conflictingExtensions.Select(kv => string.Format(" {0} : {1}", kv.Key, kv.Value))); + string message = string.Format(CultureInfo.CurrentCulture, Resources.MultipleFileVersions, extensionsString); + this.messageLogger.SendMessage(TestMessageLevel.Warning, message); + } + + return selectedExtensions.Values; + } + + private Version GetAndLogFileVersion(string path) + { + var fileVersion = this.fileHelper.GetFileVersion(path); + if (EqtTrace.IsVerboseEnabled) + { + EqtTrace.Verbose("FileVersion for {0} : {1}", path, fileVersion); + } + + return fileVersion; + } + /// /// Raises HostLaunched event /// diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs index 791fdc848b..8d260b3ce0 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DotnetTestHostManager.cs @@ -6,12 +6,12 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using System; using System.Collections.Generic; using System.Diagnostics; + using System.Globalization; using System.IO; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; - using Microsoft.Extensions.DependencyModel; using Microsoft.TestPlatform.TestHostProvider.Hosting; using Microsoft.TestPlatform.TestHostProvider.Resources; @@ -28,7 +28,6 @@ namespace Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting using Microsoft.VisualStudio.TestPlatform.Utilities; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers; using Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces; - using Newtonsoft.Json; using Newtonsoft.Json.Linq; @@ -227,7 +226,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( } else { - string message = string.Format(Resources.NoTestHostFileExist, sourcePath); + string message = string.Format(CultureInfo.CurrentCulture, Resources.NoTestHostFileExist, sourcePath); EqtTrace.Verbose("DotnetTestHostmanager: " + message); throw new FileNotFoundException(message); } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs index 1e232de908..30df3ba2ba 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs @@ -20,7 +20,7 @@ namespace Microsoft.TestPlatform.TestHostProvider.Resources { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resources { @@ -61,6 +61,16 @@ internal Resources() { } } + /// + /// Looks up a localized string similar to Multiple versions of same extension found. Selecting the highest version. + ///{0}. + /// + internal static string MultipleFileVersions { + get { + return ResourceManager.GetString("MultipleFileVersions", resourceCulture); + } + } + /// /// Looks up a localized string similar to No test is available in {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again.. /// diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx index f8f036cc75..bfe9ef97c9 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx @@ -117,6 +117,10 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Multiple versions of same extension found. Selecting the highest version. +{0} + No test is available in {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk" and framework version settings are appropriate and try again. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf index 08f6303091..9a2e4c3eb5 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf @@ -7,6 +7,13 @@ V {0} není k dispozici žádný test. Ověřte, jestli má testovací projekt odkaz na balíček nuget Microsoft.NET.Test.Sdk a jestli je nastavení verze rozhraní správné. Pak to zkuste znovu. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf index 5d9beec2a9..c3b04a2b71 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf @@ -7,6 +7,13 @@ In {0} ist kein Test verfügbar. Stellen Sie sicher, dass das Testprojekt über einen NuGet-Verweis des Pakets "Microsoft.NET.Test.Sdk" verfügt und die Einstellungen für die Frameworkversion korrekt sind, und versuchen Sie es anschließend noch mal. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf index 9ec697f2cd..37e9c697f9 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf @@ -7,6 +7,13 @@ No hay pruebas disponibles en {0}. Asegúrese de que el proyecto tiene una referencia NuGet del paquete "Microsoft.NET.Test.Sdk" y de que la configuración de la versión del marco es correcta e inténtelo de nuevo. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf index 015eaaa26b..99ec9c91bc 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf @@ -7,6 +7,13 @@ Aucun test n'est disponible dans {0}. Vérifiez que le projet de test a une référence NuGet de package "Microsoft.NET.Test.Sdk" et que les paramètres de version du framework sont corrects, puis réessayez. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf index b2e946b936..c32b2b45f8 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf @@ -7,6 +7,13 @@ Non ci sono test disponibili in {0}. Assicurarsi che il progetto di test contenga un riferimento NuGet del pacchetto "Microsoft.NET.Test.Sdk" e che le impostazioni relative alla versione del framework siano appropriate, quindi riprovare. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf index cdce648189..2a633db7a3 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf @@ -7,6 +7,13 @@ {0} で使用できるテストはありません。テスト プロジェクトにパッケージ "Microsoft.NET.Test.Sdk" の NuGet 参照があることを確認し、フレームワークのバージョン設定が適切であることを確認して、もう一度お試しください。 + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf index c7d4bbdd72..8bc3dee88b 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf @@ -7,6 +7,13 @@ {0}에서 테스트를 사용할 수 없습니다. 테스트 프로젝트에 “Microsoft.NET.Test.Sdk” 패키지의 nuget 참조가 있고 프레임워크 버전 설정이 적절한지 확인한 후 다시 시도하세요. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf index ae1a75cf67..58bc0a7258 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf @@ -7,6 +7,13 @@ W elemencie {0} nie są dostępne żadne testy. Upewnij się, że projekt testowy ma odwołanie nuget do pakietu „Microsoft.NET.Test.Sdk” oraz że ustawienia wersji platformy i struktury są odpowiednie, a następnie spróbuj ponownie. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf index 01ca4865c1..e7f4bff929 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf @@ -7,6 +7,13 @@ Nenhum teste disponível em {0}. Verifique se o projeto de teste tem uma referência NuGet do pacote "Microsoft.NET.Test.Sdk" e se as configurações de versão da estrutura são apropriadas e tente novamente. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf index fc289cec05..bab3da86e8 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf @@ -7,6 +7,13 @@ Нет доступных тестов в {0}. Убедитесь, что в проекте теста есть ссылка NuGet для пакета "Microsoft.NET.Test.Sdk", а параметры версий платформ верны, и повторите попытку. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf index 370446d5de..53db912796 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf @@ -7,6 +7,13 @@ {0} içinde kullanılabilir test yok. Test projesinde "Microsoft.NET.Test.Sdk" paketine bir NuGet başvurusu olduğundan ve çerçeve sürümü ayarlarının doğru olduğundan emin olup tekrar deneyin. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.xlf index bb2007e457..f8bdb4ca04 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.xlf @@ -7,6 +7,13 @@ Could not find testhost.dll for source '{0}'. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdkt". And also check the framework passed when running test. + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf index 98d11bb36e..d4d2a5446d 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf @@ -7,6 +7,13 @@ {0} 中没有可用的测试。请确保测试项目具有包“Microsoft.NET.Test.Sdk”的 nuget 参考并确保框架版本设置适当,然后重试。 + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf index 413f2baabf..24878340ca 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf @@ -7,6 +7,13 @@ {0} 中沒有可用的測試。請確定測試專案具有套件 "Microsoft.NET.Test.Sdk" 的 NuGet 參考,且架構的版本設定適當,然後再試一次。 + + Multiple versions of same extension found. Selecting the highest version. +{0} + Multiple extensions with different file versions found. Selected extensions with version: +{0} + + \ No newline at end of file diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index ed7f67b6bf..b8d2500ed3 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -236,6 +236,62 @@ public void GetTestPlatformExtensionsShouldIncludeOutputDirectoryExtensionsIfTes List extensionsList1 = new List { @"C:\Source1\ext1.TestAdapter.dll", @"C:\Source1\ext2.TestAdapter.dll" }; List extensionsList2 = new List { @"C:\Source2\ext1.TestAdapter.dll", @"C:\Source2\ext2.TestAdapter.dll" }; + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[0])).Returns(new Version(2, 0)); + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[1])).Returns(new Version(5, 5)); + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList2[0])).Returns(new Version(2, 2)); + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList2[1])).Returns(new Version(5, 0)); + + this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[0], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList1); + this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[1], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList2); + + this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Framework.DefaultFramework} "); + + // Act + var resultExtensions = this.testHostManager.GetTestPlatformExtensions(sources, new List()).ToList(); + + // Verify + List expectedList = new List { @"C:\Source2\ext1.TestAdapter.dll", @"C:\Source1\ext2.TestAdapter.dll" }; + CollectionAssert.AreEqual(expectedList, resultExtensions); + this.mockMessageLogger.Verify(ml => ml.SendMessage(TestMessageLevel.Warning, "Multiple versions of same extension found. Selecting the highest version.\n ext1.TestAdapter : 2.2\n ext2.TestAdapter : 5.5"), Times.Once); + } + + [TestMethod] + public void GetTestPlatformExtensionsShouldReturnPathTheHigherVersionedFileExtensions() + { + List sourcesDir = new List { "C:\\Source1", "C:\\Source2" }; + List sources = new List { @"C:\Source1\source1.dll", @"C:\Source2\source2.dll" }; + + List extensionsList1 = new List { @"C:\Source1\ext1.TestAdapter.dll" }; + List extensionsList2 = new List { @"C:\Source2\ext1.TestAdapter.dll" }; + + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[0])).Returns(new Version(2, 0)); + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList2[0])).Returns(new Version(2, 2)); + + this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[0], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList1); + this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[1], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList2); + + this.testHostManager.Initialize(this.mockMessageLogger.Object, $" {Framework.DefaultFramework} "); + + // Act + var resultExtensions = this.testHostManager.GetTestPlatformExtensions(sources, new List()).ToList(); + + // Verify + CollectionAssert.AreEqual(extensionsList2, resultExtensions); + this.mockMessageLogger.Verify(ml => ml.SendMessage(TestMessageLevel.Warning, "Multiple versions of same extension found. Selecting the highest version.\n ext1.TestAdapter : 2.2"), Times.Once); + } + + [TestMethod] + public void GetTestPlatformExtensionsShouldReturnPathToSingleFileExtensionOfATypeIfVersionsAreSame() + { + List sourcesDir = new List { "C:\\Source1", "C:\\Source2" }; + List sources = new List { @"C:\Source1\source1.dll", @"C:\Source2\source2.dll" }; + + List extensionsList1 = new List { @"C:\Source1\ext1.TestAdapter.dll" }; + List extensionsList2 = new List { @"C:\Source2\ext1.TestAdapter.dll" }; + + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList1[0])).Returns(new Version(2, 0)); + this.mockFileHelper.Setup(fh => fh.GetFileVersion(extensionsList2[0])).Returns(new Version(2, 0)); + this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[0], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList1); this.mockFileHelper.Setup(fh => fh.EnumerateFiles(sourcesDir[1], SearchOption.TopDirectoryOnly, "TestAdapter.dll")).Returns(extensionsList2); @@ -245,8 +301,8 @@ public void GetTestPlatformExtensionsShouldIncludeOutputDirectoryExtensionsIfTes var resultExtensions = this.testHostManager.GetTestPlatformExtensions(sources, new List()).ToList(); // Verify - extensionsList1.AddRange(extensionsList2); CollectionAssert.AreEqual(extensionsList1, resultExtensions); + this.mockMessageLogger.Verify(ml => ml.SendMessage(TestMessageLevel.Warning, It.IsAny()), Times.Never); } [TestMethod]