Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,19 @@ protected virtual bool TryGetUriFromFriendlyName(string friendlyName, out string
return false;
}

protected virtual bool IsUriValid(string uri)
{
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 +434,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 +716,4 @@ private void LogAttachments(List<AttachmentSet> attachmentSets)
}
}
}
}
}
14 changes: 11 additions & 3 deletions src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs

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 @@ -210,6 +210,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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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>
</body>
</file>
</xliff>
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
45 changes: 35 additions & 10 deletions test/datacollector.UnitTests/DataCollectionManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DataCollectionManagerTests
private string defaultDataCollectionSettings = "<DataCollector friendlyName=\"{0}\" uri=\"{1}\" assemblyQualifiedName=\"{2}\" codebase=\"{3}\" {4} />";
private string dataCollectorSettings;

private string dataCollectorSettingsWithWrongFriendlyName, dataCollectorSettingsWithoutFriendlyName, dataCollectorSettingsEnabled, dataCollectorSettingsDisabled;
private string dataCollectorSettingsWithWrongFriendlyName, dataCollectorSettingsWithWrongFriendlyNameAndWrongUri, dataCollectorSettingsWithoutFriendlyName, dataCollectorSettingsEnabled, dataCollectorSettingsDisabled, dataCollectorSettingsWithWrongUri;

private Mock<IMessageSink> mockMessageSink;
private Mock<DataCollector2> mockDataCollector;
Expand All @@ -43,6 +43,8 @@ public DataCollectionManagerTests()

this.dataCollectorSettings = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty));
this.dataCollectorSettingsWithWrongFriendlyName = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, "anyFriendlyName", uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty));
this.dataCollectorSettingsWithWrongUri = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, "my://custom/WrongDatacollector", this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this.dataCollectorSettingsWithWrongUri [](start = 12, length = 39)

Why do these have to be a member variable?

this.dataCollectorSettingsWithWrongFriendlyNameAndWrongUri = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, "anyFriendlyName", "datacollector://data", this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty));
this.dataCollectorSettingsWithoutFriendlyName = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, string.Empty, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty).Replace("friendlyName=\"\"", string.Empty));
this.dataCollectorSettingsEnabled = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, "enabled=\"true\""));
this.dataCollectorSettingsDisabled = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, "enabled=\"false\""));
Expand Down Expand Up @@ -100,14 +102,33 @@ public void InitializeShouldAddDataCollectorIfItIsEnabled()


[TestMethod]
public void InitializeDataCollectorsShouldNotLoadDataCollectorIfFriendlyNameIsNotCorrect()
public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsNotCorrectAndUriIsCorrect()
{
this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithWrongFriendlyName);

Assert.AreEqual(1, this.dataCollectionManager.RunDataCollectors.Count);
this.mockDataCollector.Verify(x => x.Initialize(It.IsAny<XmlElement>(), It.IsAny<DataCollectionEvents>(), It.IsAny<DataCollectionSink>(), It.IsAny<DataCollectionLogger>(), It.IsAny<DataCollectionEnvironmentContext>()), Times.Once);
}

[TestMethod]
public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsCorrectAndUriIsNotCorrect()
{
this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithWrongUri);

Assert.AreEqual(1, this.dataCollectionManager.RunDataCollectors.Count);
this.mockDataCollector.Verify(x => x.Initialize(It.IsAny<XmlElement>(), It.IsAny<DataCollectionEvents>(), It.IsAny<DataCollectionSink>(), It.IsAny<DataCollectionLogger>(), It.IsAny<DataCollectionEnvironmentContext>()), Times.Once);
}

[TestMethod]
public void InitializeDataCollectorsShouldNotLoadDataCollectorIfFriendlyNameIsNotCorrectAndUriIsNotCorrect()
{
this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithWrongFriendlyNameAndWrongUri);

Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count);
this.mockDataCollector.Verify(x => x.Initialize(It.IsAny<XmlElement>(), It.IsAny<DataCollectionEvents>(), It.IsAny<DataCollectionSink>(), It.IsAny<DataCollectionLogger>(), It.IsAny<DataCollectionEnvironmentContext>()), Times.Never);
}


[TestMethod]
public void InitializeDataCollectorsShouldNotAddSameDataCollectorMoreThanOnce()
{
Expand All @@ -120,14 +141,6 @@ public void InitializeDataCollectorsShouldNotAddSameDataCollectorMoreThanOnce()
this.mockDataCollector.Verify(x => x.Initialize(It.IsAny<XmlElement>(), It.IsAny<DataCollectionEvents>(), It.IsAny<DataCollectionSink>(), It.IsAny<DataCollectionLogger>(), It.IsAny<DataCollectionEnvironmentContext>()), Times.Once);
}

[TestMethod]
public void InitializeDataCollectorsShouldNotAddDataCollectorIfFriendlyNameIsNotSpecifiedByDataCollector()
{
Assert.ThrowsException<SettingsException>(() =>
{
this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithoutFriendlyName);
});
}

[TestMethod]
public void InitializeDataCollectorsShouldLoadDataCollectorAndReturnEnvironmentVariables()
Expand Down Expand Up @@ -441,6 +454,18 @@ protected override bool TryGetUriFromFriendlyName(string friendlyName, out strin
}
}

protected override bool IsUriValid(string uri)
{
if (uri.Equals("my://custom/datacollector"))
{
return true;
}
else
{
return false;
}
}

protected override DataCollector TryGetTestExtension(string extensionUri)
{
if (extensionUri.Equals("my://custom/datacollector"))
Expand Down