diff --git a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs index 09f6710837..d5e61e98a4 100644 --- a/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs +++ b/src/Microsoft.TestPlatform.Common/DataCollection/DataCollectionManager.cs @@ -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; + } + /// /// Gets the extension using uri. /// @@ -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)) @@ -699,4 +721,4 @@ private void LogAttachments(List attachmentSets) } } } -} +} \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs index 08e4897357..f41b5b64b8 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.Designer.cs @@ -348,6 +348,15 @@ internal class Resources { } } + /// + /// Looks up a localized string similar to Unable to find a datacollector with friendly name '[0}'.. + /// + internal static string UnableToFetchUriString { + get { + return ResourceManager.GetString("UnableToFetchUriString", resourceCulture); + } + } + /// /// Looks up a localized string similar to This option works only with vstest.console.exe installed as part of Visual Studio.. /// diff --git a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx index 8e03b8fcdb..295afaf19e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.Common/Resources/Resources.resx @@ -213,6 +213,9 @@ Incorrect format for TestCaseFilter {0}. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed. + + Unable to find a datacollector with friendly name '[0}'. + This option works only with vstest.console.exe installed as part of Visual Studio. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf index 66e157470b..3fd8021863 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.cs.xlf @@ -269,6 +269,11 @@ Operace se ruší na základě žádosti. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf index 9d6b73864f..be44debddc 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.de.xlf @@ -269,6 +269,11 @@ Der Vorgang wird gemäß Anforderung abgebrochen. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf index 4d3bcaa7e1..0c50da5700 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.es.xlf @@ -269,6 +269,11 @@ La operación se cancelará como se ha solicitado. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf index 0516749dbe..e18e8cf35b 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.fr.xlf @@ -269,6 +269,11 @@ Annulation de l'opération, comme demandé. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf index d5f51a31bf..edb47cc110 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.it.xlf @@ -269,6 +269,11 @@ L'operazione verrà annullata come richiesto. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf index 751f4150bf..ebcae6109e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ja.xlf @@ -269,6 +269,11 @@ 操作のキャンセルが要求されたため、キャンセルしています。 + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf index ffe3f7311b..efb912c67c 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ko.xlf @@ -269,6 +269,11 @@ 요청한 대로 작업을 취소하는 중입니다. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf index 93081acbba..32ec4e8912 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pl.xlf @@ -269,6 +269,11 @@ Anulowanie operacji zgodnie z żądaniem. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf index 85c6c0b355..9347c7b730 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.pt-BR.xlf @@ -269,6 +269,11 @@ Cancelando a operação conforme solicitado. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf index c326d2179d..1b4ad0e227 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.ru.xlf @@ -269,6 +269,11 @@ Операция отменяется в соответствии с запросом. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf index 42bb585f21..9c52e64f1e 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.tr.xlf @@ -269,6 +269,11 @@ İşlem istek üzerine iptal ediliyor. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf index e83ed26f2b..0fb8c3f172 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.xlf @@ -146,6 +146,11 @@ Cancelling the operation as requested. + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf index 9fd21e69a7..01eae8fd53 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hans.xlf @@ -269,6 +269,11 @@ 按要求取消该操作。 + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf index af7b8773d7..2fa9fe9255 100644 --- a/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.Common/Resources/xlf/Resources.zh-Hant.xlf @@ -269,6 +269,11 @@ 正在應要求取消作業。 + + Unable to find a datacollector with friendly name '[0}'. + Unable to find a datacollector with friendly name '[0}'. + + Failed to load extensions from file '{0}'. Please use /diag for more information. TestPluginDiscoverer: Failed to load extensions from file '{0}'. Please use /diag for more information. diff --git a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs index 6c78d15066..b8f96dd1ec 100644 --- a/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs +++ b/src/Microsoft.TestPlatform.CrossPlatEngine/DataCollection/DataCollectionLauncherFactory.cs @@ -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(); } diff --git a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs index df50008fc7..b9f754bffd 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs +++ b/src/Microsoft.TestPlatform.ObjectModel/DataCollector/DataCollectorSettings.cs @@ -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) { diff --git a/test/datacollector.UnitTests/DataCollectionManagerTests.cs b/test/datacollector.UnitTests/DataCollectionManagerTests.cs index 51c419aceb..be2971f7e2 100644 --- a/test/datacollector.UnitTests/DataCollectionManagerTests.cs +++ b/test/datacollector.UnitTests/DataCollectionManagerTests.cs @@ -24,9 +24,8 @@ public class DataCollectionManagerTests private string defaultRunSettings = "\r\n\r\n \r\n {0}\r\n \r\n"; private string defaultDataCollectionSettings = ""; private string dataCollectorSettings; - - private string dataCollectorSettingsWithWrongFriendlyName, dataCollectorSettingsWithoutFriendlyName, dataCollectorSettingsEnabled, dataCollectorSettingsDisabled; - + private string friendlyName; + private string uri; private Mock mockMessageSink; private Mock mockDataCollector; private List> envVarList; @@ -34,18 +33,12 @@ public class DataCollectionManagerTests public DataCollectionManagerTests() { - var friendlyName = "CustomDataCollector"; - var uri = "my://custom/datacollector"; - + this.friendlyName = "CustomDataCollector"; + this.uri = "my://custom/datacollector"; this.envVarList = new List>(); this.mockDataCollector = new Mock(); this.mockDataCollector.As().Setup(x => x.GetTestExecutionEnvironmentVariables()).Returns(this.envVarList); - - 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.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\"")); + this.dataCollectorSettings = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, this.friendlyName, this.uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty)); this.mockMessageSink = new Mock(); this.mockDataCollectionAttachmentManager = new Mock(); this.mockDataCollectionAttachmentManager.SetReturnsDefault>(new List()); @@ -74,7 +67,8 @@ public void InitializeDataCollectorsShouldReturnEmptyDictionaryIfDataCollectorsA [TestMethod] public void InitializeDataCollectorsShouldLoadDataCollector() { - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettings); + var dataCollectorSettings = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty)); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettings); Assert.IsTrue(this.dataCollectionManager.RunDataCollectors.ContainsKey(this.mockDataCollector.Object.GetType())); this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); @@ -83,7 +77,8 @@ public void InitializeDataCollectorsShouldLoadDataCollector() [TestMethod] public void InitializeShouldNotAddDataCollectorIfItIsDisabled() { - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsDisabled); + var dataCollectorSettingsDisabled = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, "enabled=\"false\"")); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsDisabled); Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count); this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); @@ -92,17 +87,72 @@ public void InitializeShouldNotAddDataCollectorIfItIsDisabled() [TestMethod] public void InitializeShouldAddDataCollectorIfItIsEnabled() { - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsEnabled); + var dataCollectorSettingsEnabled = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, "enabled=\"true\"")); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsEnabled); Assert.IsTrue(this.dataCollectionManager.RunDataCollectors.ContainsKey(this.mockDataCollector.Object.GetType())); this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } + [TestMethod] + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsNotCorrectAndUriIsCorrect() + { + var dataCollectorSettingsWithWrongFriendlyName = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, "anyFriendlyName", uri, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty)); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithWrongFriendlyName); + + Assert.AreEqual(1, this.dataCollectionManager.RunDataCollectors.Count); + this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } [TestMethod] - public void InitializeDataCollectorsShouldNotLoadDataCollectorIfFriendlyNameIsNotCorrect() + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsCorrectAndUriIsNotCorrect() { - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithWrongFriendlyName); + var 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)); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithWrongUri); + + Assert.AreEqual(1, this.dataCollectionManager.RunDataCollectors.Count); + this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [TestMethod] + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsCorrectAndUriIsNull() + { + var dataCollectorSettingsWithNullUri = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, string.Empty, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty).Replace("uri=\"\"", string.Empty)); + this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithNullUri); + + Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count); + this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); + } + + [TestMethod] + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsNullAndUriIsCorrect() + { + var dataCollectorSettingsWithNullFriendlyName = 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.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithNullFriendlyName); + + Assert.AreEqual(1, this.dataCollectionManager.RunDataCollectors.Count); + this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); + } + + [TestMethod] + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsCorrectAndUriIsEmpty() + { + var dataCollectorSettingsWithEmptyUri = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, string.Empty, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty)); + Assert.ThrowsException(() => this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithEmptyUri)); + } + + [TestMethod] + public void InitializeDataCollectorsShouldLoadDataCollectorIfFriendlyNameIsEmptyAndUriIsCorrect() + { + var dataCollectorSettingsWithEmptyFriendlyName = string.Format(this.defaultRunSettings, string.Format(this.defaultDataCollectionSettings, friendlyName, string.Empty, this.mockDataCollector.Object.GetType().AssemblyQualifiedName, typeof(DataCollectionManagerTests).GetTypeInfo().Assembly.Location, string.Empty)); + Assert.ThrowsException(() => this.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithEmptyFriendlyName)); + } + + [TestMethod] + public void InitializeDataCollectorsShouldNotLoadDataCollectorIfFriendlyNameIsNotCorrectAndUriIsNotCorrect() + { + var 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.dataCollectionManager.InitializeDataCollectors(dataCollectorSettingsWithWrongFriendlyNameAndWrongUri); Assert.AreEqual(0, this.dataCollectionManager.RunDataCollectors.Count); this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Never); @@ -120,15 +170,6 @@ public void InitializeDataCollectorsShouldNotAddSameDataCollectorMoreThanOnce() this.mockDataCollector.Verify(x => x.Initialize(It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny(), It.IsAny()), Times.Once); } - [TestMethod] - public void InitializeDataCollectorsShouldNotAddDataCollectorIfFriendlyNameIsNotSpecifiedByDataCollector() - { - Assert.ThrowsException(() => - { - this.dataCollectionManager.InitializeDataCollectors(this.dataCollectorSettingsWithoutFriendlyName); - }); - } - [TestMethod] public void InitializeDataCollectorsShouldLoadDataCollectorAndReturnEnvironmentVariables() { @@ -441,6 +482,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"))