Skip to content

Commit f0cd370

Browse files
hvinettsinghsarab
authored andcommitted
DataCollector check with only Uri in Runsettings (#2177)
* Removed friendly name null check * removed redundant code and added tests for the datacollection manager * added warning message if friendlyname is incorrect * Given prority to Uri * changed naming in resources * added tests and verified behavior * changed member variables to functional variables * added datacollectorsettings as member variable again
1 parent 9703a28 commit f0cd370

20 files changed

+187
-36
lines changed

src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs

+25-3
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,24 @@ protected virtual bool TryGetUriFromFriendlyName(string friendlyName, out string
391391
return false;
392392
}
393393

394+
protected virtual bool IsUriValid(string uri)
395+
{
396+
if (string.IsNullOrEmpty(uri))
397+
{
398+
return false;
399+
}
400+
401+
var extensionManager = this.dataCollectorExtensionManager;
402+
foreach (var extension in extensionManager.TestExtensions)
403+
{
404+
if (string.Compare(uri, extension.Metadata.ExtensionUri, StringComparison.OrdinalIgnoreCase) == 0)
405+
{
406+
return true;
407+
}
408+
}
409+
return false;
410+
}
411+
394412
/// <summary>
395413
/// Gets the extension using uri.
396414
/// </summary>
@@ -421,8 +439,12 @@ private void LoadAndInitialize(DataCollectorSettings dataCollectorSettings, stri
421439
{
422440
// Look up the extension and initialize it if one is found.
423441
var extensionManager = this.DataCollectorExtensionManager;
424-
var dataCollectorUri = string.Empty;
425-
this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri);
442+
var dataCollectorUri = dataCollectorSettings.Uri?.ToString();
443+
444+
if (!IsUriValid(dataCollectorUri) && !this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri))
445+
{
446+
this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.UnableToFetchUriString, dataCollectorSettings.FriendlyName));
447+
}
426448

427449
DataCollector dataCollector = null;
428450
if (!string.IsNullOrWhiteSpace(dataCollectorUri))
@@ -699,4 +721,4 @@ private void LogAttachments(List<AttachmentSet> attachmentSets)
699721
}
700722
}
701723
}
702-
}
724+
}

src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.TestPlatform.Common/Resources/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@
213213
<data name="TestCaseFilterFormatException" xml:space="preserve">
214214
<value>Incorrect format for TestCaseFilter {0}. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.</value>
215215
</data>
216+
<data name="UnableToFetchUriString" xml:space="preserve">
217+
<value>Unable to find a datacollector with friendly name '[0}'.</value>
218+
</data>
216219
<data name="VSInstallationNotFound" xml:space="preserve">
217220
<value>This option works only with vstest.console.exe installed as part of Visual Studio.</value>
218221
</data>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Operace se ruší na základě žádosti.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Der Vorgang wird gemäß Anforderung abgebrochen.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">La operación se cancelará como se ha solicitado.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Annulation de l'opération, comme demandé.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">L'operazione verrà annullata come richiesto.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">操作のキャンセルが要求されたため、キャンセルしています。</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">요청한 대로 작업을 취소하는 중입니다.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Anulowanie operacji zgodnie z żądaniem.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Cancelando a operação conforme solicitado.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">Операция отменяется в соответствии с запросом.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">İşlem istek üzerine iptal ediliyor.</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,11 @@
146146
<target state="new">Cancelling the operation as requested.</target>
147147
<note></note>
148148
</trans-unit>
149+
<trans-unit id="UnableToFetchUriString">
150+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
151+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
152+
<note></note>
153+
</trans-unit>
149154
<trans-unit id="FailedToLoadAdapaterFile">
150155
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
151156
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">按要求取消该操作。</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,11 @@
269269
<target state="translated">正在應要求取消作業。</target>
270270
<note />
271271
</trans-unit>
272+
<trans-unit id="UnableToFetchUriString">
273+
<source>Unable to find a datacollector with friendly name '[0}'.</source>
274+
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
275+
<note></note>
276+
</trans-unit>
272277
<trans-unit id="FailedToLoadAdapaterFile">
273278
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
274279
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>

src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ internal static IDataCollectionLauncher GetDataCollectorLauncher(IProcessHelper
2828
var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settingsXml);
2929
foreach (var dataCollectorSettings in dataCollectionRunSettings.DataCollectorSettingsList)
3030
{
31-
if (dataCollectorSettings.FriendlyName.ToLower().Equals("event log"))
31+
if (string.Equals(dataCollectorSettings.FriendlyName, "event Log", StringComparison.OrdinalIgnoreCase) || string.Equals(dataCollectorSettings.Uri?.ToString(), @"datacollector://Microsoft/EventLog/2.0", StringComparison.OrdinalIgnoreCase))
3232
{
3333
return new DefaultDataCollectionLauncher();
3434
}

src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs

-6
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,6 @@ internal static DataCollectorSettings FromXml(XmlReader reader)
201201

202202
}
203203

204-
if (string.IsNullOrWhiteSpace(settings.FriendlyName))
205-
{
206-
throw new SettingsException(
207-
String.Format(CultureInfo.CurrentCulture, Resources.Resources.MissingDataCollectorAttributes, "FriendlyName"));
208-
}
209-
210204
reader.Read();
211205
if (!empty)
212206
{

0 commit comments

Comments
 (0)