Skip to content

Commit

Permalink
DataCollector check with only Uri in Runsettings (#2177)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
hvinett authored and singhsarab committed Oct 1, 2019
1 parent 9703a28 commit f0cd370
Show file tree
Hide file tree
Showing 20 changed files with 187 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ protected virtual bool TryGetUriFromFriendlyName(string friendlyName, out string
return false;
}

protected virtual bool IsUriValid(string uri)
{
if (string.IsNullOrEmpty(uri))
{
return false;
}

var extensionManager = this.dataCollectorExtensionManager;
foreach (var extension in extensionManager.TestExtensions)
{
if (string.Compare(uri, extension.Metadata.ExtensionUri, StringComparison.OrdinalIgnoreCase) == 0)
{
return true;
}
}
return false;
}

/// <summary>
/// Gets the extension using uri.
/// </summary>
Expand Down Expand Up @@ -421,8 +439,12 @@ private void LoadAndInitialize(DataCollectorSettings dataCollectorSettings, stri
{
// Look up the extension and initialize it if one is found.
var extensionManager = this.DataCollectorExtensionManager;
var dataCollectorUri = string.Empty;
this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri);
var dataCollectorUri = dataCollectorSettings.Uri?.ToString();

if (!IsUriValid(dataCollectorUri) && !this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri))
{
this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.UnableToFetchUriString, dataCollectorSettings.FriendlyName));
}

DataCollector dataCollector = null;
if (!string.IsNullOrWhiteSpace(dataCollectorUri))
Expand Down Expand Up @@ -699,4 +721,4 @@ private void LogAttachments(List<AttachmentSet> attachmentSets)
}
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@
<data name="TestCaseFilterFormatException" xml:space="preserve">
<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>
</data>
<data name="UnableToFetchUriString" xml:space="preserve">
<value>Unable to find a datacollector with friendly name '[0}'.</value>
</data>
<data name="VSInstallationNotFound" xml:space="preserve">
<value>This option works only with vstest.console.exe installed as part of Visual Studio.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Operace se ruší na základě žádosti.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Der Vorgang wird gemäß Anforderung abgebrochen.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">La operación se cancelará como se ha solicitado.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Annulation de l'opération, comme demandé.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">L'operazione verrà annullata come richiesto.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">操作のキャンセルが要求されたため、キャンセルしています。</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">요청한 대로 작업을 취소하는 중입니다.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Anulowanie operacji zgodnie z żądaniem.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Cancelando a operação conforme solicitado.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Операция отменяется в соответствии с запросом.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">İşlem istek üzerine iptal ediliyor.</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@
<target state="new">Cancelling the operation as requested.</target>
<note></note>
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">按要求取消该操作。</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@
<target state="translated">正在應要求取消作業。</target>
<note />
</trans-unit>
<trans-unit id="UnableToFetchUriString">
<source>Unable to find a datacollector with friendly name '[0}'.</source>
<target state="new">Unable to find a datacollector with friendly name '[0}'.</target>
<note></note>
</trans-unit>
<trans-unit id="FailedToLoadAdapaterFile">
<source>Failed to load extensions from file '{0}'. Please use /diag for more information.</source>
<target state="new">TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information.</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal static IDataCollectionLauncher GetDataCollectorLauncher(IProcessHelper
var dataCollectionRunSettings = XmlRunSettingsUtilities.GetDataCollectionRunSettings(settingsXml);
foreach (var dataCollectorSettings in dataCollectionRunSettings.DataCollectorSettingsList)
{
if (dataCollectorSettings.FriendlyName.ToLower().Equals("event log"))
if (string.Equals(dataCollectorSettings.FriendlyName, "event Log", StringComparison.OrdinalIgnoreCase) || string.Equals(dataCollectorSettings.Uri?.ToString(), @"datacollector://Microsoft/EventLog/2.0", StringComparison.OrdinalIgnoreCase))
{
return new DefaultDataCollectionLauncher();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,6 @@ internal static DataCollectorSettings FromXml(XmlReader reader)

}

if (string.IsNullOrWhiteSpace(settings.FriendlyName))
{
throw new SettingsException(
String.Format(CultureInfo.CurrentCulture, Resources.Resources.MissingDataCollectorAttributes, "FriendlyName"));
}

reader.Read();
if (!empty)
{
Expand Down
Loading

0 comments on commit f0cd370

Please sign in to comment.