Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataCollector check with only Uri in Runsettings #2177

Merged
Expand Up @@ -422,7 +422,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);

if (!this.TryGetUriFromFriendlyName(dataCollectorSettings.FriendlyName, out dataCollectorUri))
hvinett marked this conversation as resolved.
Show resolved Hide resolved
{
this.LogWarning(string.Format(CultureInfo.CurrentUICulture, Resources.Resources.CannotFetchByFriendlyName, dataCollectorSettings.FriendlyName));
hvinett marked this conversation as resolved.
Show resolved Hide resolved
dataCollectorUri = dataCollectorSettings.Uri?.ToString();
}

DataCollector dataCollector = null;
if (!string.IsNullOrWhiteSpace(dataCollectorUri))
Expand Down
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
Expand Up @@ -120,6 +120,9 @@
<data name="CancellationRequested" xml:space="preserve">
<value>Cancelling the operation as requested.</value>
</data>
<data name="CannotFetchByFriendlyName" xml:space="preserve">
<value>Cannot Fetch Uri with {0}.</value>
</data>
<data name="DataCollectionMessageFormat" xml:space="preserve">
<value>Data collection : {0}</value>
</data>
Expand Down
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Operace se ruší na základě žádosti.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
hvinett marked this conversation as resolved.
Show resolved Hide resolved
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Der Vorgang wird gemäß Anforderung abgebrochen.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
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="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Annulation de l'opération, comme demandé.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">L'operazione verrà annullata come richiesto.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">操作のキャンセルが要求されたため、キャンセルしています。</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">요청한 대로 작업을 취소하는 중입니다.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Anulowanie operacji zgodnie z żądaniem.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Cancelando a operação conforme solicitado.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">Операция отменяется в соответствии с запросом.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">İşlem istek üzerine iptal ediliyor.</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
5 changes: 5 additions & 0 deletions src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf
Expand Up @@ -146,6 +146,11 @@
<target state="new">Cancelling the operation as requested.</target>
<note></note>
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">按要求取消该操作。</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
Expand Up @@ -269,6 +269,11 @@
<target state="translated">正在應要求取消作業。</target>
<note />
</trans-unit>
<trans-unit id="CannotFetchByFriendlyName">
<source>Cannot Fetch Uri with {0}.</source>
<target state="new">Cannot Fetch Uri with {0}.</target>
<note></note>
</trans-unit>
</body>
</file>
</xliff>
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
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
23 changes: 13 additions & 10 deletions test/datacollector.UnitTests/DataCollectionManagerTests.cs
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;

private Mock<IMessageSink> mockMessageSink;
private Mock<DataCollector2> mockDataCollector;
Expand All @@ -43,6 +43,7 @@ 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.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 +101,24 @@ 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 InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsNotCorrectAndURiIsNotCorrect()
{
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 +131,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