Best Vstest code snippet using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.TestLoggerManager.Initialize
TestLoggerManagerTests.cs
Source:TestLoggerManagerTests.cs
...25 {26 private static int counter = 0;27 private static EventWaitHandle waitHandle = new AutoResetEvent(false);28 private string loggerUri = "testlogger://logger";29 [TestInitialize]30 public void Initialize()31 {32 TestPluginCacheHelper.SetupMockExtensions(33 new string[] { typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location },34 () => { });35 }36 [TestCleanup]37 public void TestCleanup()38 {39 TestPluginCacheHelper.ResetExtensionsCache();40 }41 [TestMethod]42 public void TryGetUriFromFriendlyNameShouldReturnUriIfLoggerIsAdded()43 {44 var testLoggerManager = new DummyTestLoggerManager();45 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());46 testLoggerManager.TryGetUriFromFriendlyName("TestLoggerExtension", out var uri);47 Assert.AreEqual(uri.ToString(), new Uri(loggerUri).ToString());48 }49 [TestMethod]50 public void TryGetUriFromFriendlyNameShouldNotReturnUriIfLoggerIsNotAdded()51 {52 var testLoggerManager = new DummyTestLoggerManager();53 testLoggerManager.TryGetUriFromFriendlyName("TestLoggerExtension1", out var uri);54 Assert.IsNull(uri);55 }56 [TestMethod]57 public void GetResultsDirectoryShouldReturnNullIfRunSettingsIsNull()58 {59 var testLoggerManager = new DummyTestLoggerManager();60 string result = testLoggerManager.GetResultsDirectory(null);61 Assert.IsNull(result);62 }63 [TestMethod]64 public void GetResultsDirectoryShouldReadResultsDirectoryFromSettingsIfSpecified()65 {66 string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>67 <RunSettings>68 <RunConfiguration>69 <MaxCpuCount>0</MaxCpuCount>70 <ResultsDirectory>DummyTestResultsFolder</ResultsDirectory>71 <TargetPlatform> x64 </TargetPlatform>72 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>73 </RunConfiguration>74 </RunSettings> ";75 var testLoggerManager = new DummyTestLoggerManager();76 string result = testLoggerManager.GetResultsDirectory(runSettingsXml);77 Assert.AreEqual(0, string.Compare("DummyTestResultsFolder", result));78 }79 [TestMethod]80 public void GetResultsDirectoryShouldReturnDefaultPathIfResultsDirectoryIsNotProvidedInRunSettings()81 {82 string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>83 <RunSettings>84 <RunConfiguration>85 <MaxCpuCount>0</MaxCpuCount>86 <TargetPlatform> x64 </TargetPlatform>87 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>88 </RunConfiguration>89 </RunSettings> ";90 var testLoggerManager = new DummyTestLoggerManager();91 string result = testLoggerManager.GetResultsDirectory(runSettingsXml);92 Assert.AreEqual(0, string.Compare(Constants.DefaultResultsDirectory, result));93 }94 [TestMethod]95 public void GetTargetFrameworkShouldReturnFrameworkProvidedInRunSettings()96 {97 string runSettingsXml = @"<?xml version=""1.0"" encoding=""utf-8""?>98 <RunSettings>99 <RunConfiguration>100 <MaxCpuCount>0</MaxCpuCount>101 <TargetPlatform> x64 </TargetPlatform>102 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>103 </RunConfiguration>104 </RunSettings> ";105 var testLoggerManager = new DummyTestLoggerManager();106 var framework = testLoggerManager.GetTargetFramework(runSettingsXml);107 Assert.AreEqual(".NETFramework,Version=v4.5", framework.Name);108 }109 [TestMethod]110 public void HandleTestRunMessageShouldInvokeTestRunMessageHandlerOfLoggers()111 {112 counter = 0;113 waitHandle.Reset();114 var testLoggerManager = new DummyTestLoggerManager();115 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());116 testLoggerManager.EnableLogging();117 testLoggerManager.HandleTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Informational, "TestRunMessage"));118 waitHandle.WaitOne();119 Assert.AreEqual(1, counter);120 }121 [TestMethod]122 public void HandleTestRunMessageShouldNotInvokeTestRunMessageHandlerOfLoggersIfDisposed()123 {124 counter = 0;125 waitHandle.Reset();126 var testLoggerManager = new DummyTestLoggerManager();127 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());128 testLoggerManager.EnableLogging();129 testLoggerManager.Dispose();130 testLoggerManager.HandleTestRunMessage(new TestRunMessageEventArgs(TestMessageLevel.Informational, "TestRunMessage"));131 Assert.AreEqual(0, counter);132 }133 [TestMethod]134 public void HandleTestRunCompleteShouldInvokeTestRunCompleteHandlerOfLoggers()135 {136 counter = 0;137 waitHandle.Reset();138 // setup TestLogger139 var testLoggerManager = new DummyTestLoggerManager();140 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());141 testLoggerManager.EnableLogging();142 testLoggerManager.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, new TimeSpan()));143 waitHandle.WaitOne();144 Assert.AreEqual(1, counter);145 }146 [TestMethod]147 public void HandleTestRunCompleteShouldNotInvokeTestRunCompleteHandlerOfLoggersIfDisposed()148 {149 counter = 0;150 waitHandle.Reset();151 // setup TestLogger152 var testLoggerManager = new DummyTestLoggerManager();153 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());154 testLoggerManager.EnableLogging();155 testLoggerManager.Dispose();156 testLoggerManager.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, new TimeSpan()));157 Assert.AreEqual(0, counter);158 }159 [TestMethod]160 public void HandleTestRunCompleteShouldDisposeLoggerManager()161 {162 counter = 0;163 waitHandle.Reset();164 // setup TestLogger165 var testLoggerManager = new DummyTestLoggerManager();166 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());167 testLoggerManager.EnableLogging();168 testLoggerManager.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, new TimeSpan()));169 testLoggerManager.HandleTestRunComplete(new TestRunCompleteEventArgs(null, false, false, null, null, new TimeSpan())); // count should not increase because of second call.170 Assert.AreEqual(1, counter);171 }172 [TestMethod]173 public void HandleTestRunStatsChangeShouldInvokeTestRunChangedHandlerOfLoggers()174 {175 counter = 0;176 waitHandle.Reset();177 // setup TestLogger178 var testLoggerManager = new DummyTestLoggerManager();179 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());180 testLoggerManager.EnableLogging();181 testLoggerManager.HandleTestRunStatsChange(182 new TestRunChangedEventArgs(183 null,184 new List<ObjectModel.TestResult>()185 {186 new ObjectModel.TestResult(187 new TestCase(188 "This is a string.",189 new Uri("some://uri"),190 "This is a string."))191 },192 null));193 waitHandle.WaitOne();194 Assert.AreEqual(1, counter);195 }196 [TestMethod]197 public void HandleTestRunStatsChangeShouldNotInvokeTestRunChangedHandlerOfLoggersIfDisposed()198 {199 counter = 0;200 waitHandle.Reset();201 // setup TestLogger202 var testLoggerManager = new DummyTestLoggerManager();203 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());204 testLoggerManager.EnableLogging();205 testLoggerManager.Dispose();206 testLoggerManager.HandleTestRunStatsChange(207 new TestRunChangedEventArgs(208 null,209 new List<ObjectModel.TestResult>()210 {211 new ObjectModel.TestResult(212 new TestCase(213 "This is a string.",214 new Uri("some://uri"),215 "This is a string."))216 },217 null));218 Assert.AreEqual(0, counter);219 }220 [TestMethod]221 public void AddLoggerShouldNotThrowExceptionIfUriIsNull()222 {223 var testLoggerManager = new DummyTestLoggerManager();224 Assert.ThrowsException<ArgumentNullException>(225 () =>226 {227 testLoggerManager.InitializeLoggerByUri(null, null);228 });229 }230 [TestMethod]231 public void AddLoggerShouldNotThrowExceptionIfUriIsNonExistent()232 {233 var testLoggerManager = new DummyTestLoggerManager();234 Assert.IsFalse(testLoggerManager.InitializeLoggerByUri(new Uri("logger://NotALogger"), null));235 }236 [TestMethod]237 public void AddLoggerShouldAddDefaultLoggerParameterForTestLoggerWithParameters()238 {239 ValidLoggerWithParameters.Reset();240 var mockRequestData = new Mock<IRequestData>();241 var mockMetricsCollection = new Mock<IMetricsCollection>();242 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);243 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;244 string settingsXml =245 @"<?xml version=""1.0"" encoding=""utf-8""?>246 <RunSettings>247 <RunConfiguration>248 <MaxCpuCount>0</MaxCpuCount>249 <TargetPlatform> x64 </TargetPlatform>250 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>251 </RunConfiguration>252 <LoggerRunSettings>253 <Loggers>254 <Logger friendlyName=""TestLoggerExtension"" />255 <Logger uri=""test-logger-with-parameter://logger"" enabled=""true""></Logger>256 </Loggers>257 </LoggerRunSettings>258 </RunSettings>";259 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);260 testLoggerManager.Initialize(settingsXml);261 Assert.IsNotNull(ValidLoggerWithParameters.parameters, "parameters not getting passed");262 Assert.IsTrue(263 ValidLoggerWithParameters.parameters.ContainsKey(DefaultLoggerParameterNames.TestRunDirectory),264 $"{DefaultLoggerParameterNames.TestRunDirectory} not added to parameters");265 Assert.IsFalse(266 string.IsNullOrWhiteSpace(267 ValidLoggerWithParameters.parameters[DefaultLoggerParameterNames.TestRunDirectory]),268 $"parameter {DefaultLoggerParameterNames.TestRunDirectory} should not be null, empty or whitespace");269 }270 [TestMethod]271 public void DisposeShouldNotThrowExceptionIfCalledMultipleTimes()272 {273 // Dispose the logger manager multiple times and verify that no exception is thrown.274 var testLoggerManager = new DummyTestLoggerManager();275 testLoggerManager.Dispose();276 testLoggerManager.Dispose();277 }278 [TestMethod]279 public void AddLoggerShouldThrowObjectDisposedExceptionAfterDisposedIsCalled()280 {281 var testLoggerManager = new DummyTestLoggerManager();282 testLoggerManager.Dispose();283 Assert.ThrowsException<ObjectDisposedException>(284 () =>285 {286 testLoggerManager.InitializeLoggerByUri(new Uri("some://uri"), null);287 });288 }289 [TestMethod]290 public void EnableLoggingShouldThrowObjectDisposedExceptionAfterDisposedIsCalled()291 {292 var testLoggerManager = new DummyTestLoggerManager();293 testLoggerManager.Dispose();294 Assert.ThrowsException<ObjectDisposedException>(295 () =>296 {297 testLoggerManager.EnableLogging();298 });299 }300 [TestMethod]301 public void LoggerInitialzeShouldCollectLoggersForTelemetry()302 {303 var mockRequestData = new Mock<IRequestData>();304 var mockMetricsCollection = new Mock<IMetricsCollection>();305 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);306 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);307 testLoggerManager.InitializeLoggerByUri(new Uri(this.loggerUri), new Dictionary<string, string>());308 // Act.309 testLoggerManager.Initialize(null);310 // Verify311 mockMetricsCollection.Verify(312 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger"));313 }314 /// <summary>315 /// DiscoveryStart event handler of loggers should be called only if discovery events are registered.316 /// </summary>317 [TestMethod]318 public void HandleDiscoveryStartShouldInvokeDiscoveryStartHandlerOfLoggers()319 {320 counter = 0;321 waitHandle.Reset();322 DiscoveryCriteria discoveryCriteria = new DiscoveryCriteria() { TestCaseFilter = "Name=Test1" };323 DiscoveryStartEventArgs discoveryStartEventArgs = new DiscoveryStartEventArgs(discoveryCriteria);324 // setup TestLogger325 var testLoggerManager = new DummyTestLoggerManager();326 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());327 testLoggerManager.EnableLogging();328 testLoggerManager.HandleDiscoveryStart(discoveryStartEventArgs);329 // Assertions when discovery events registered330 waitHandle.WaitOne();331 Assert.AreEqual(1, counter);332 }333 /// <summary>334 /// DiscoveryStart event handler of loggers should be called only if discovery events are registered.335 /// </summary>336 [TestMethod]337 public void HandleDiscoveryStartShouldNotInvokeDiscoveryStartHandlerOfLoggersIfDisposed()338 {339 counter = 0;340 waitHandle.Reset();341 DiscoveryCriteria discoveryCriteria = new DiscoveryCriteria() { TestCaseFilter = "Name=Test1" };342 DiscoveryStartEventArgs discoveryStartEventArgs = new DiscoveryStartEventArgs(discoveryCriteria);343 // setup TestLogger344 var testLoggerManager = new DummyTestLoggerManager();345 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());346 testLoggerManager.EnableLogging();347 testLoggerManager.Dispose();348 testLoggerManager.HandleDiscoveryStart(discoveryStartEventArgs);349 // Assertions when discovery events registered350 Assert.AreEqual(0, counter);351 }352 /// <summary>353 /// DiscoveredTests event handler of loggers should be called only if discovery events are registered.354 /// </summary>355 [TestMethod]356 public void HandleDiscoveredTestsShouldInvokeDiscoveredTestsHandlerOfLoggers()357 {358 counter = 0;359 waitHandle.Reset();360 List<TestCase> testCases = new List<TestCase> { new TestCase("This is a string.", new Uri("some://uri"), "DummySourceFileName") };361 DiscoveredTestsEventArgs discoveredTestsEventArgs = new DiscoveredTestsEventArgs(testCases);362 // setup TestLogger363 var testLoggerManager = new DummyTestLoggerManager();364 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());365 testLoggerManager.EnableLogging();366 testLoggerManager.HandleDiscoveredTests(discoveredTestsEventArgs);367 // Assertions when discovery events registered368 waitHandle.WaitOne();369 Assert.AreEqual(1, counter);370 }371 [TestMethod]372 public void HandleDiscoveredTestsShouldNotInvokeDiscoveredTestsHandlerOfLoggersIfDisposed()373 {374 counter = 0;375 waitHandle.Reset();376 List<TestCase> testCases = new List<TestCase> { new TestCase("This is a string.", new Uri("some://uri"), "DummySourceFileName") };377 DiscoveredTestsEventArgs discoveredTestsEventArgs = new DiscoveredTestsEventArgs(testCases);378 // setup TestLogger379 var testLoggerManager = new DummyTestLoggerManager();380 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());381 testLoggerManager.EnableLogging();382 testLoggerManager.Dispose();383 testLoggerManager.HandleDiscoveredTests(discoveredTestsEventArgs);384 // Assertions when discovery events registered385 Assert.AreEqual(0, counter);386 }387 /// <summary>388 /// TestRunStart event handler of loggers should be called only if test run events are registered.389 /// </summary>390 [TestMethod]391 public void HandleTestRunStartShouldInvokeTestRunStartHandlerOfLoggers()392 {393 counter = 0;394 waitHandle.Reset();395 TestRunCriteria testRunCriteria = new TestRunCriteria(new List<string> { @"x:dummy\foo.dll" }, 10, false, string.Empty, TimeSpan.MaxValue, null, "Name=Test1", null);396 TestRunStartEventArgs testRunStartEventArgs = new TestRunStartEventArgs(testRunCriteria);397 // setup TestLogger398 var testLoggerManager = new DummyTestLoggerManager();399 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());400 testLoggerManager.EnableLogging();401 testLoggerManager.HandleTestRunStart(testRunStartEventArgs);402 // Assertions when test run events registered403 waitHandle.WaitOne();404 Assert.AreEqual(1, counter);405 }406 /// <summary>407 /// TestRunStart event handler of loggers should be called only if test run events are registered.408 /// </summary>409 [TestMethod]410 public void HandleTestRunStartShouldNotInvokeTestRunStartHandlerOfLoggersIfDisposed()411 {412 counter = 0;413 waitHandle.Reset();414 TestRunCriteria testRunCriteria = new TestRunCriteria(new List<string> { @"x:dummy\foo.dll" }, 10, false, string.Empty, TimeSpan.MaxValue, null, "Name=Test1", null);415 TestRunStartEventArgs testRunStartEventArgs = new TestRunStartEventArgs(testRunCriteria);416 // setup TestLogger417 var testLoggerManager = new DummyTestLoggerManager();418 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());419 testLoggerManager.EnableLogging();420 testLoggerManager.Dispose();421 testLoggerManager.HandleTestRunStart(testRunStartEventArgs);422 // Assertions when test run events registered423 Assert.AreEqual(0, counter);424 }425 /// <summary>426 /// DiscoveryComplete event handler of loggers should be called only if discovery events are registered.427 /// </summary>428 [TestMethod]429 public void HandleDiscoveryCompleteShouldInvokeDiscoveryCompleteHandlerOfLoggers()430 {431 counter = 0;432 waitHandle.Reset();433 DiscoveryCompleteEventArgs discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(2, false);434 // setup TestLogger435 var testLoggerManager = new DummyTestLoggerManager();436 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());437 testLoggerManager.EnableLogging();438 testLoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs);439 // Assertions when discovery events registered440 waitHandle.WaitOne();441 Assert.AreEqual(1, counter);442 }443 /// <summary>444 /// DiscoveryComplete event handler of loggers should be called only if discovery events are registered.445 /// </summary>446 [TestMethod]447 public void HandleDiscoveryCompleteShouldNotInvokeDiscoveryCompleteHandlerOfLoggersIfDisposed()448 {449 counter = 0;450 waitHandle.Reset();451 var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(2, false);452 // setup TestLogger453 var testLoggerManager = new DummyTestLoggerManager();454 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());455 testLoggerManager.EnableLogging();456 testLoggerManager.Dispose();457 testLoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs);458 // Assertions when discovery events registered459 Assert.AreEqual(0, counter);460 }461 [TestMethod]462 public void HandleDiscoveryCompleteShouldDisposeLoggerManager()463 {464 counter = 0;465 waitHandle.Reset();466 // setup TestLogger467 var testLoggerManager = new DummyTestLoggerManager();468 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());469 testLoggerManager.EnableLogging();470 var discoveryCompleteEventArgs = new DiscoveryCompleteEventArgs(2, false);471 testLoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs);472 testLoggerManager.HandleDiscoveryComplete(discoveryCompleteEventArgs); // count should not increase because of second call.473 Assert.AreEqual(1, counter);474 }475 /// <summary>476 /// DiscoveryMessage event handler of loggers should be called only if discovery events are registered.477 /// </summary>478 [TestMethod]479 public void HandleDiscoveryMessageShouldInvokeDiscoveryMessageHandlerOfLoggers()480 {481 counter = 0;482 waitHandle.Reset();483 string message = "This is the test message";484 TestRunMessageEventArgs testRunMessageEventArgs = new TestRunMessageEventArgs(TestMessageLevel.Informational, message);485 // setup TestLogger486 var testLoggerManager = new DummyTestLoggerManager();487 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());488 testLoggerManager.EnableLogging();489 testLoggerManager.HandleDiscoveryMessage(testRunMessageEventArgs);490 // Assertions when discovery events registered491 waitHandle.WaitOne();492 Assert.AreEqual(1, counter);493 }494 /// <summary>495 /// DiscoveryMessage event handler of loggers should be called only if discovery events are registered.496 /// </summary>497 [TestMethod]498 public void HandleDiscoveryMessageShouldNotInvokeDiscoveryMessageHandlerOfLoggersIfDisposed()499 {500 counter = 0;501 waitHandle.Reset();502 string message = "This is the test message";503 TestRunMessageEventArgs testRunMessageEventArgs = new TestRunMessageEventArgs(TestMessageLevel.Informational, message);504 // setup TestLogger505 var testLoggerManager = new DummyTestLoggerManager();506 testLoggerManager.InitializeLoggerByUri(new Uri(loggerUri), new Dictionary<string, string>());507 testLoggerManager.EnableLogging();508 testLoggerManager.Dispose();509 testLoggerManager.HandleDiscoveryMessage(testRunMessageEventArgs);510 Assert.AreEqual(0, counter);511 }512 [TestMethod]513 public void InitializeShouldInitializeLoggerFromFriendlyNameWhenOnlyFriendlyNamePresent()514 {515 ValidLoggerWithParameters.Reset();516 var mockRequestData = new Mock<IRequestData>();517 var mockMetricsCollection = new Mock<IMetricsCollection>();518 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);519 string settingsXml =520 @"<?xml version=""1.0"" encoding=""utf-8""?>521 <RunSettings>522 <LoggerRunSettings>523 <Loggers>524 <Logger friendlyName=""TestLoggerWithParameterExtension""></Logger>525 </Loggers>526 </LoggerRunSettings>527 </RunSettings>";528 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);529 testLoggerManager.Initialize(settingsXml);530 Assert.AreEqual(1, ValidLoggerWithParameters.counter);531 mockMetricsCollection.Verify(532 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));533 }534 [TestMethod]535 public void InitializeShouldInitializeLoggerFromUriWhenOnlyUriPresent()536 {537 ValidLoggerWithParameters.Reset();538 var mockRequestData = new Mock<IRequestData>();539 var mockMetricsCollection = new Mock<IMetricsCollection>();540 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);541 string settingsXml =542 @"<?xml version=""1.0"" encoding=""utf-8""?>543 <RunSettings>544 <LoggerRunSettings>545 <Loggers>546 <Logger uri=""test-logger-with-parameter://logger""></Logger>547 </Loggers>548 </LoggerRunSettings>549 </RunSettings>";550 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);551 testLoggerManager.Initialize(settingsXml);552 Assert.AreEqual(1, ValidLoggerWithParameters.counter);553 mockMetricsCollection.Verify(554 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));555 }556 [TestMethod]557 public void InitializeShouldInitializeLoggerFromAssemblyNameWhenAssemblyNameAndCodeBasePresent()558 {559 ValidLoggerWithParameters.Reset();560 var mockRequestData = new Mock<IRequestData>();561 var mockMetricsCollection = new Mock<IMetricsCollection>();562 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);563 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;564 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;565 string settingsXml =566 @"<?xml version=""1.0"" encoding=""utf-8""?>567 <RunSettings>568 <LoggerRunSettings>569 <Loggers>570 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>571 </Loggers>572 </LoggerRunSettings>573 </RunSettings>";574 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);575 testLoggerManager.Initialize(settingsXml);576 Assert.AreEqual(1, ValidLoggerWithParameters.counter);577 mockMetricsCollection.Verify(578 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));579 }580 [TestMethod]581 public void InitializeShouldNotInitializeLoggersWhenOnlyAssemblyNameIsPresent()582 {583 ValidLoggerWithParameters.Reset();584 var mockRequestData = new Mock<IRequestData>();585 var mockMetricsCollection = new Mock<IMetricsCollection>();586 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);587 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;588 string settingsXml =589 @"<?xml version=""1.0"" encoding=""utf-8""?>590 <RunSettings>591 <LoggerRunSettings>592 <Loggers>593 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @"""></Logger>594 </Loggers>595 </LoggerRunSettings>596 </RunSettings>";597 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);598 Assert.ThrowsException<InvalidLoggerException>(() =>599 {600 testLoggerManager.Initialize(settingsXml);601 });602 Assert.AreEqual(0, ValidLoggerWithParameters.counter);603 }604 [TestMethod]605 public void InitializeShouldNotInitializeLoggersFromAssemblyNameWhenInterfaceDoesNotMatch()606 {607 ValidLoggerWithParameters.Reset();608 var mockRequestData = new Mock<IRequestData>();609 var mockMetricsCollection = new Mock<IMetricsCollection>();610 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);611 var assemblyQualifiedName = typeof(InvalidLogger).AssemblyQualifiedName;612 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;613 string settingsXml =614 @"<?xml version=""1.0"" encoding=""utf-8""?>615 <RunSettings>616 <LoggerRunSettings>617 <Loggers>618 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>619 </Loggers>620 </LoggerRunSettings>621 </RunSettings>";622 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);623 Assert.ThrowsException<InvalidLoggerException>(() =>624 {625 testLoggerManager.Initialize(settingsXml);626 });627 Assert.AreEqual(0, InvalidLogger.counter);628 }629 [TestMethod]630 public void InitializeShouldNotInitializeLoggersWhenAssemblyNameInvalid()631 {632 ValidLoggerWithParameters.Reset();633 var mockRequestData = new Mock<IRequestData>();634 var mockMetricsCollection = new Mock<IMetricsCollection>();635 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);636 var assemblyQualifiedName = "invalid";637 string settingsXml =638 @"<?xml version=""1.0"" encoding=""utf-8""?>639 <RunSettings>640 <LoggerRunSettings>641 <Loggers>642 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @"""></Logger>643 </Loggers>644 </LoggerRunSettings>645 </RunSettings>";646 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);647 Assert.ThrowsException<InvalidLoggerException>(() =>648 {649 testLoggerManager.Initialize(settingsXml);650 });651 Assert.AreEqual(0, ValidLoggerWithParameters.counter);652 }653 [TestMethod]654 public void InitializeShouldNotInitializeLoggersWhenCodeBaseInvalid()655 {656 ValidLoggerWithParameters.Reset();657 var mockRequestData = new Mock<IRequestData>();658 var mockMetricsCollection = new Mock<IMetricsCollection>();659 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);660 var assemblyQualifiedName = typeof(InvalidLogger).AssemblyQualifiedName;661 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;662 string settingsXml =663 @"<?xml version=""1.0"" encoding=""utf-8""?>664 <RunSettings>665 <LoggerRunSettings>666 <Loggers>667 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>668 </Loggers>669 </LoggerRunSettings>670 </RunSettings>";671 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);672 Assert.ThrowsException<InvalidLoggerException>(() =>673 {674 testLoggerManager.Initialize(settingsXml);675 });676 Assert.AreEqual(0, ValidLoggerWithParameters.counter);677 }678 [TestMethod]679 public void InitializeShouldInitializeLoggerOnceWhenMultipleLoggersWithSameAssemblyNamePresent()680 {681 // Duplicate loggers should be ignored682 ValidLoggerWithParameters.Reset();683 var mockRequestData = new Mock<IRequestData>();684 var mockMetricsCollection = new Mock<IMetricsCollection>();685 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);686 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;687 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;688 string settingsXml =689 @"<?xml version=""1.0"" encoding=""utf-8""?>690 <RunSettings>691 <LoggerRunSettings>692 <Loggers>693 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>694 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>695 </Loggers>696 </LoggerRunSettings>697 </RunSettings>";698 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);699 testLoggerManager.Initialize(settingsXml);700 Assert.AreEqual(1, ValidLoggerWithParameters.counter);701 mockMetricsCollection.Verify(702 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));703 }704 [TestMethod]705 public void InitializeShouldInitializeLoggerOnce()706 {707 // Duplicate loggers should be ignored708 ValidLoggerWithParameters.Reset();709 var mockRequestData = new Mock<IRequestData>();710 var mockMetricsCollection = new Mock<IMetricsCollection>();711 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);712 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;713 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;714 string settingsXml =715 @"<?xml version=""1.0"" encoding=""utf-8""?>716 <RunSettings>717 <LoggerRunSettings>718 <Loggers>719 <Logger friendlyName=""TestLoggerWithParameterExtension""></Logger>720 <Logger uri=""test-logger-with-parameter://logger""></Logger>721 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>722 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>723 </Loggers>724 </LoggerRunSettings>725 </RunSettings>";726 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);727 testLoggerManager.Initialize(settingsXml);728 Assert.AreEqual(1, ValidLoggerWithParameters.counter);729 mockMetricsCollection.Verify(730 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));731 }732 [TestMethod]733 public void InitializeShouldNotConsiderLoggerAsInitializedWhenInitializationErrorOccurs()734 {735 ValidLoggerWithParameters.Reset();736 var mockRequestData = new Mock<IRequestData>();737 var mockMetricsCollection = new Mock<IMetricsCollection>();738 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);739 var assemblyQualifiedName = typeof(LoggerWithInitializationError).AssemblyQualifiedName;740 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;741 string settingsXml =742 @"<?xml version=""1.0"" encoding=""utf-8""?>743 <RunSettings>744 <LoggerRunSettings>745 <Loggers>746 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>747 </Loggers>748 </LoggerRunSettings>749 </RunSettings>";750 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);751 Assert.ThrowsException<InvalidLoggerException>(() =>752 {753 testLoggerManager.Initialize(settingsXml);754 });755 }756 [TestMethod]757 public void InitializeShouldThrowWhenLoggerManagerAlreadyDisposed()758 {759 ValidLoggerWithParameters.Reset();760 var mockRequestData = new Mock<IRequestData>();761 var mockMetricsCollection = new Mock<IMetricsCollection>();762 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);763 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;764 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;765 string settingsXml =766 @"<?xml version=""1.0"" encoding=""utf-8""?>767 <RunSettings>768 <LoggerRunSettings>769 <Loggers>770 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>771 </Loggers>772 </LoggerRunSettings>773 </RunSettings>";774 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);775 testLoggerManager.Dispose();776 Assert.ThrowsException<ObjectDisposedException>(() => testLoggerManager.Initialize(settingsXml));777 }778 [TestMethod]779 public void InitializeShouldInitilaizeMultipleLoggersIfPresent()780 {781 ValidLoggerWithParameters.Reset();782 var mockRequestData = new Mock<IRequestData>();783 var mockMetricsCollection = new Mock<IMetricsCollection>();784 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);785 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;786 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;787 string settingsXml =788 @"<?xml version=""1.0"" encoding=""utf-8""?>789 <RunSettings>790 <LoggerRunSettings>791 <Loggers>792 <Logger friendlyName=""TestLoggerExtension"" />793 <Logger uri=""testlogger://logger2""></Logger>794 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>795 </Loggers>796 </LoggerRunSettings>797 </RunSettings>";798 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);799 testLoggerManager.Initialize(settingsXml);800 Assert.AreEqual(1, ValidLoggerWithParameters.counter);801 mockMetricsCollection.Verify(802 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));803 }804 [TestMethod]805 public void AreLoggersInitializedShouldReturnTrueWhenLoggersInitialized()806 {807 ValidLoggerWithParameters.Reset();808 var mockRequestData = new Mock<IRequestData>();809 var mockMetricsCollection = new Mock<IMetricsCollection>();810 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);811 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;812 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;813 string settingsXml =814 @"<?xml version=""1.0"" encoding=""utf-8""?>815 <RunSettings>816 <LoggerRunSettings>817 <Loggers>818 <Logger friendlyName=""TestLoggerExtension"" />819 <Logger uri=""testlogger://logger2""></Logger>820 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>821 </Loggers>822 </LoggerRunSettings>823 </RunSettings>";824 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);825 testLoggerManager.Initialize(settingsXml);826 Assert.IsTrue(testLoggerManager.LoggersInitialized);827 }828 [TestMethod]829 public void AreLoggersInitializedShouldReturnFalseWhenLoggersNotInitialized()830 {831 ValidLoggerWithParameters.Reset();832 var mockRequestData = new Mock<IRequestData>();833 var mockMetricsCollection = new Mock<IMetricsCollection>();834 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);835 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;836 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;837 string settingsXml =838 @"<?xml version=""1.0"" encoding=""utf-8""?>839 <RunSettings>840 <LoggerRunSettings>841 <Loggers>842 <Logger friendlyName=""TestLoggerExtension"" />843 <Logger uri=""testlogger://logger2""></Logger>844 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @"""></Logger>845 </Loggers>846 </LoggerRunSettings>847 </RunSettings>";848 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);849 Assert.IsFalse(testLoggerManager.LoggersInitialized);850 }851 [TestMethod]852 public void AreLoggersInitializedShouldReturnFalseWhenNoLoggersPresent()853 {854 ValidLoggerWithParameters.Reset();855 var mockRequestData = new Mock<IRequestData>();856 var mockMetricsCollection = new Mock<IMetricsCollection>();857 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);858 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;859 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;860 string settingsXml =861 @"<?xml version=""1.0"" encoding=""utf-8""?>862 <RunSettings>863 <LoggerRunSettings>864 <Loggers>865 </Loggers>866 </LoggerRunSettings>867 </RunSettings>";868 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);869 testLoggerManager.Initialize(settingsXml);870 Assert.IsFalse(testLoggerManager.LoggersInitialized);871 }872 [TestMethod]873 public void InitializeShouldPassConfigurationElementAsParameters()874 {875 ValidLoggerWithParameters.Reset();876 var mockRequestData = new Mock<IRequestData>();877 var mockMetricsCollection = new Mock<IMetricsCollection>();878 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);879 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;880 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;881 string settingsXml =882 @"<?xml version=""1.0"" encoding=""utf-8""?>883 <RunSettings>884 <LoggerRunSettings>885 <Loggers>886 <Logger friendlyName=""TestLoggerExtension"" />887 <Logger uri=""testlogger://logger2""></Logger>888 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @""">889 <Configuration>890 <Key1>Value1</Key1>891 <Key2>Value2</Key2>892 </Configuration>893 </Logger>894 </Loggers>895 </LoggerRunSettings>896 </RunSettings>";897 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);898 testLoggerManager.Initialize(settingsXml);899 Assert.AreEqual(1, ValidLoggerWithParameters.counter);900 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework901 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);902 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);903 mockMetricsCollection.Verify(904 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));905 }906 [TestMethod]907 public void InitializeShouldSkipEmptyConfigurationValueInParameters()908 {909 ValidLoggerWithParameters.Reset();910 var mockRequestData = new Mock<IRequestData>();911 var mockMetricsCollection = new Mock<IMetricsCollection>();912 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);913 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;914 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;915 string settingsXml =916 @"<?xml version=""1.0"" encoding=""utf-8""?>917 <RunSettings>918 <LoggerRunSettings>919 <Loggers>920 <Logger friendlyName=""TestLoggerExtension"" />921 <Logger uri=""testlogger://logger2""></Logger>922 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @""">923 <Configuration>924 <Key1> </Key1>925 <Key2>Value2</Key2>926 </Configuration>927 </Logger>928 </Loggers>929 </LoggerRunSettings>930 </RunSettings>";931 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);932 testLoggerManager.Initialize(settingsXml);933 Assert.AreEqual(1, ValidLoggerWithParameters.counter);934 Assert.AreEqual(3, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework935 Assert.IsFalse(ValidLoggerWithParameters.parameters.TryGetValue("Key1", out var key1Value));936 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);937 mockMetricsCollection.Verify(938 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));939 }940 [TestMethod]941 public void InitializeShouldUseLastValueInParametersForDuplicateConfigurationValue()942 {943 ValidLoggerWithParameters.Reset();944 var mockRequestData = new Mock<IRequestData>();945 var mockMetricsCollection = new Mock<IMetricsCollection>();946 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);947 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;948 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;949 string settingsXml =950 @"<?xml version=""1.0"" encoding=""utf-8""?>951 <RunSettings>952 <LoggerRunSettings>953 <Loggers>954 <Logger friendlyName=""TestLoggerExtension"" />955 <Logger uri=""testlogger://logger2""></Logger>956 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @""">957 <Configuration>958 <Key1>Value1</Key1>959 <Key2>Value2</Key2>960 <Key1>Value3</Key1>961 </Configuration>962 </Logger>963 </Loggers>964 </LoggerRunSettings>965 </RunSettings>";966 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);967 testLoggerManager.Initialize(settingsXml);968 Assert.AreEqual(1, ValidLoggerWithParameters.counter);969 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework970 Assert.AreEqual("Value3", ValidLoggerWithParameters.parameters["Key1"]);971 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);972 mockMetricsCollection.Verify(973 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));974 }975 [TestMethod]976 public void InitializeShouldNotInitializeDisabledLoggers()977 {978 ValidLoggerWithParameters.Reset();979 var mockRequestData = new Mock<IRequestData>();980 var mockMetricsCollection = new Mock<IMetricsCollection>();981 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);982 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;983 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;984 string settingsXml =985 @"<?xml version=""1.0"" encoding=""utf-8""?>986 <RunSettings>987 <LoggerRunSettings>988 <Loggers>989 <Logger friendlyName=""TestLoggerExtension"" />990 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>991 <Logger assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @""" enabled=""false""></Logger>992 </Loggers>993 </LoggerRunSettings>994 </RunSettings>";995 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);996 testLoggerManager.Initialize(settingsXml);997 Assert.AreEqual(0, ValidLoggerWithParameters.counter);998 mockMetricsCollection.Verify(999 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2"));1000 }1001 [TestMethod]1002 public void InitializeShouldInitializeFromAssemblyNameIfAllAttributesPresent()1003 {1004 ValidLoggerWithParameters.Reset();1005 var mockRequestData = new Mock<IRequestData>();1006 var mockMetricsCollection = new Mock<IMetricsCollection>();1007 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1008 var assemblyQualifiedName = typeof(ValidLoggerWithParameters).AssemblyQualifiedName;1009 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1010 string settingsXml =1011 @"<?xml version=""1.0"" encoding=""utf-8""?>1012 <RunSettings>1013 <LoggerRunSettings>1014 <Loggers>1015 <Logger friendlyName=""TestLoggerExtension"" />1016 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1017 <Logger friendlyName=""invalidName"" uri=""invalid://invalidUri"" assemblyQualifiedName=""" + assemblyQualifiedName + @""" codeBase=""" + codeBase + @""">1018 <Configuration>1019 <Key1>Value1</Key1>1020 <Key2>Value2</Key2>1021 </Configuration>1022 </Logger>1023 </Loggers>1024 </LoggerRunSettings>1025 </RunSettings>";1026 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1027 testLoggerManager.Initialize(settingsXml);1028 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1029 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1030 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1031 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1032 mockMetricsCollection.Verify(1033 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1034 }1035 [TestMethod]1036 public void InitializeShouldInitializeFromUriIfUriAndNamePresent()1037 {1038 ValidLoggerWithParameters.Reset();1039 var mockRequestData = new Mock<IRequestData>();1040 var mockMetricsCollection = new Mock<IMetricsCollection>();1041 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1042 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1043 string settingsXml =1044 @"<?xml version=""1.0"" encoding=""utf-8""?>1045 <RunSettings>1046 <LoggerRunSettings>1047 <Loggers>1048 <Logger friendlyName=""TestLoggerExtension"" />1049 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1050 <Logger friendlyName=""invalidName"" uri=""test-logger-with-parameter://logger"" codeBase=""" + codeBase + @""">1051 <Configuration>1052 <Key1>Value1</Key1>1053 <Key2>Value2</Key2>1054 </Configuration>1055 </Logger>1056 </Loggers>1057 </LoggerRunSettings>1058 </RunSettings>";1059 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1060 testLoggerManager.Initialize(settingsXml);1061 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1062 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1063 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1064 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1065 mockMetricsCollection.Verify(1066 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1067 }1068 [TestMethod]1069 public void InitializeShouldInitializeFromUriIfUnableToFromAssemblyName()1070 {1071 ValidLoggerWithParameters.Reset();1072 var mockRequestData = new Mock<IRequestData>();1073 var mockMetricsCollection = new Mock<IMetricsCollection>();1074 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1075 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1076 string settingsXml =1077 @"<?xml version=""1.0"" encoding=""utf-8""?>1078 <RunSettings>1079 <LoggerRunSettings>1080 <Loggers>1081 <Logger friendlyName=""TestLoggerExtension"" />1082 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1083 <Logger friendlyName=""invalidName"" uri=""test-logger-with-parameter://logger"" assemblyQualifiedName=""invalidAssembly"" codeBase=""" + codeBase + @""">1084 <Configuration>1085 <Key1>Value1</Key1>1086 <Key2>Value2</Key2>1087 </Configuration>1088 </Logger>1089 </Loggers>1090 </LoggerRunSettings>1091 </RunSettings>";1092 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1093 testLoggerManager.Initialize(settingsXml);1094 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1095 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1096 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1097 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1098 mockMetricsCollection.Verify(1099 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1100 }1101 [TestMethod]1102 public void InitializeShouldInitializeFromNameIfUnableToFromUri()1103 {1104 ValidLoggerWithParameters.Reset();1105 var mockRequestData = new Mock<IRequestData>();1106 var mockMetricsCollection = new Mock<IMetricsCollection>();1107 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1108 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1109 string settingsXml =1110 @"<?xml version=""1.0"" encoding=""utf-8""?>1111 <RunSettings>1112 <LoggerRunSettings>1113 <Loggers>1114 <Logger friendlyName=""TestLoggerExtension"" />1115 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1116 <Logger friendlyName=""TestLoggerWithParameterExtension"" uri=""invalid://invalid"" assemblyQualifiedName=""invalidAssembly"" codeBase=""" + codeBase + @""">1117 <Configuration>1118 <Key1>Value1</Key1>1119 <Key2>Value2</Key2>1120 </Configuration>1121 </Logger>1122 </Loggers>1123 </LoggerRunSettings>1124 </RunSettings>";1125 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1126 testLoggerManager.Initialize(settingsXml);1127 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1128 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1129 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1130 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1131 mockMetricsCollection.Verify(1132 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1133 }1134 [TestMethod]1135 public void InitializeShouldInitializeLoggersWithTestRunDirectoryIfPresentInRunSettings()1136 {1137 ValidLoggerWithParameters.Reset();1138 var mockRequestData = new Mock<IRequestData>();1139 var mockMetricsCollection = new Mock<IMetricsCollection>();1140 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1141 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1142 string settingsXml =1143 @"<?xml version=""1.0"" encoding=""utf-8""?>1144 <RunSettings>1145 <RunConfiguration>1146 <MaxCpuCount>0</MaxCpuCount>1147 <ResultsDirectory>DummyTestResultsFolder</ResultsDirectory>1148 <TargetPlatform> x64 </TargetPlatform>1149 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>1150 </RunConfiguration>1151 <LoggerRunSettings>1152 <Loggers>1153 <Logger friendlyName=""TestLoggerExtension"" />1154 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1155 <Logger friendlyName=""TestLoggerWithParameterExtension"" uri=""invalid://invalid"" assemblyQualifiedName=""invalidAssembly"" codeBase=""" + codeBase + @""">1156 <Configuration>1157 <Key1>Value1</Key1>1158 <Key2>Value2</Key2>1159 </Configuration>1160 </Logger>1161 </Loggers>1162 </LoggerRunSettings>1163 </RunSettings>";1164 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1165 testLoggerManager.Initialize(settingsXml);1166 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1167 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1168 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1169 Assert.AreEqual("DummyTestResultsFolder", ValidLoggerWithParameters.parameters["testRunDirectory"]);1170 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1171 mockMetricsCollection.Verify(1172 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1173 }1174 [TestMethod]1175 public void InitializeShouldInitializeLoggersWithDefaultTestRunDirectoryIfNotPresentInRunSettings()1176 {1177 ValidLoggerWithParameters.Reset();1178 var mockRequestData = new Mock<IRequestData>();1179 var mockMetricsCollection = new Mock<IMetricsCollection>();1180 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1181 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1182 string settingsXml =1183 @"<?xml version=""1.0"" encoding=""utf-8""?>1184 <RunSettings>1185 <RunConfiguration>1186 <MaxCpuCount>0</MaxCpuCount>1187 <TargetPlatform> x64 </TargetPlatform>1188 <TargetFrameworkVersion> Framework45 </TargetFrameworkVersion>1189 </RunConfiguration>1190 <LoggerRunSettings>1191 <Loggers>1192 <Logger friendlyName=""TestLoggerExtension"" />1193 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1194 <Logger friendlyName=""TestLoggerWithParameterExtension"" uri=""invalid://invalid"" assemblyQualifiedName=""invalidAssembly"" codeBase=""" + codeBase + @""">1195 <Configuration>1196 <Key1>Value1</Key1>1197 <Key2>Value2</Key2>1198 </Configuration>1199 </Logger>1200 </Loggers>1201 </LoggerRunSettings>1202 </RunSettings>";1203 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1204 testLoggerManager.Initialize(settingsXml);1205 Assert.AreEqual(1, ValidLoggerWithParameters.counter);1206 Assert.AreEqual(4, ValidLoggerWithParameters.parameters.Count); // Two additional because of testRunDirectory and targetFramework1207 Assert.AreEqual("Value1", ValidLoggerWithParameters.parameters["Key1"]);1208 Assert.AreEqual(Constants.DefaultResultsDirectory, ValidLoggerWithParameters.parameters["testRunDirectory"]);1209 Assert.AreEqual("Value2", ValidLoggerWithParameters.parameters["Key2"]);1210 mockMetricsCollection.Verify(1211 rd => rd.Add(TelemetryDataConstants.LoggerUsed, "TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLogger2,TestPlatform.CrossPlatEngine.UnitTests.TestLoggerManagerTests+ValidLoggerWithParameters"));1212 }1213 [TestMethod]1214 public void InitializeShouldNotInitializeIfUnableToFromName()1215 {1216 ValidLoggerWithParameters.Reset();1217 var mockRequestData = new Mock<IRequestData>();1218 var mockMetricsCollection = new Mock<IMetricsCollection>();1219 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1220 var codeBase = typeof(TestLoggerManagerTests).GetTypeInfo().Assembly.Location;1221 string settingsXml =1222 @"<?xml version=""1.0"" encoding=""utf-8""?>1223 <RunSettings>1224 <LoggerRunSettings>1225 <Loggers>1226 <Logger friendlyName=""TestLoggerExtension"" />1227 <Logger uri=""testlogger://logger2"" enabled=""true""></Logger>1228 <Logger friendlyName=""invalid"" uri=""invalid://invalid"" assemblyQualifiedName=""invalidAssembly"" codeBase=""" + codeBase + @""">1229 <Configuration>1230 <Key1>Value1</Key1>1231 <Key2>Value2</Key2>1232 </Configuration>1233 </Logger>1234 </Loggers>1235 </LoggerRunSettings>1236 </RunSettings>";1237 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1238 Assert.ThrowsException<InvalidLoggerException>(() =>1239 {1240 testLoggerManager.Initialize(settingsXml);1241 });1242 Assert.AreEqual(0, ValidLoggerWithParameters.counter);1243 }1244 [TestMethod]1245 public void InitializeShouldNotInitializeAnyLoggerIfNoLoggerPresent()1246 {1247 ValidLoggerWithParameters.Reset();1248 var mockRequestData = new Mock<IRequestData>();1249 var mockMetricsCollection = new Mock<IMetricsCollection>();1250 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1251 string settingsXml =1252 @"<?xml version=""1.0"" encoding=""utf-8""?>1253 <RunSettings>1254 </RunSettings>";1255 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1256 testLoggerManager.Initialize(settingsXml);1257 Assert.AreEqual(0, ValidLoggerWithParameters.counter);1258 mockMetricsCollection.Verify(1259 rd => rd.Add(TelemetryDataConstants.LoggerUsed, ""));1260 }1261 [TestMethod]1262 public void InitializeShouldNotInitializeAnyLoggerIfEmptyLoggerRunSettings()1263 {1264 ValidLoggerWithParameters.Reset();1265 var mockRequestData = new Mock<IRequestData>();1266 var mockMetricsCollection = new Mock<IMetricsCollection>();1267 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1268 string settingsXml =1269 @"<?xml version=""1.0"" encoding=""utf-8""?>1270 <RunSettings>1271 <LoggerRunSettings>1272 </LoggerRunSettings>1273 </RunSettings>";1274 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1275 testLoggerManager.Initialize(settingsXml);1276 Assert.AreEqual(0, ValidLoggerWithParameters.counter);1277 mockMetricsCollection.Verify(1278 rd => rd.Add(TelemetryDataConstants.LoggerUsed, ""));1279 }1280 [TestMethod]1281 public void InitializeShouldNotThrowWhenLoggersNotPresentInRunSettings()1282 {1283 ValidLoggerWithParameters.Reset();1284 var mockRequestData = new Mock<IRequestData>();1285 var mockMetricsCollection = new Mock<IMetricsCollection>();1286 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1287 string settingsXml =1288 @"<?xml version=""1.0"" encoding=""utf-8""?>1289 <RunSettings>1290 </RunSettings>";1291 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1292 testLoggerManager.Initialize(settingsXml);1293 Assert.AreEqual(0, ValidLoggerWithParameters.counter);1294 mockMetricsCollection.Verify(1295 rd => rd.Add(TelemetryDataConstants.LoggerUsed, ""));1296 }1297 [TestMethod]1298 public void InitializeShouldNotInitializeAnyLoggerIfEmptyLoggersNode()1299 {1300 ValidLoggerWithParameters.Reset();1301 var mockRequestData = new Mock<IRequestData>();1302 var mockMetricsCollection = new Mock<IMetricsCollection>();1303 mockRequestData.Setup(rd => rd.MetricsCollection).Returns(mockMetricsCollection.Object);1304 string settingsXml =1305 @"<?xml version=""1.0"" encoding=""utf-8""?>1306 <RunSettings>1307 <LoggerRunSettings>1308 <Loggers>1309 </Loggers>1310 </LoggerRunSettings>1311 </RunSettings>";1312 var testLoggerManager = new DummyTestLoggerManager(mockRequestData.Object);1313 testLoggerManager.Initialize(settingsXml);1314 Assert.AreEqual(0, ValidLoggerWithParameters.counter);1315 mockMetricsCollection.Verify(1316 rd => rd.Add(TelemetryDataConstants.LoggerUsed, ""));1317 }1318 [ExtensionUri("testlogger://logger")]1319 [FriendlyName("TestLoggerExtension")]1320 private class ValidLogger : ITestLogger1321 {1322 public void Initialize(TestLoggerEvents events, string testRunDirectory)1323 {1324 events.TestRunMessage += TestMessageHandler;1325 events.TestRunComplete += Events_TestRunComplete;1326 events.TestResult += Events_TestResult;1327 events.TestRunStart += TestRunStartHandler;1328 events.DiscoveryStart += DiscoveryStartHandler;1329 events.DiscoveryMessage += DiscoveryMessageHandler;1330 events.DiscoveredTests += DiscoveredTestsHandler;1331 events.DiscoveryComplete += DiscoveryCompleteHandler;1332 }1333 private void Events_TestResult(object sender, TestResultEventArgs e)1334 {1335 TestLoggerManagerTests.counter++;1336 TestLoggerManagerTests.waitHandle.Set();1337 }1338 private void Events_TestRunComplete(object sender, TestRunCompleteEventArgs e)1339 {1340 TestLoggerManagerTests.counter++;1341 TestLoggerManagerTests.waitHandle.Set();1342 }1343 private void TestMessageHandler(object sender, TestRunMessageEventArgs e)1344 {1345 if (e.Message.Equals("TestRunMessage"))1346 {1347 TestLoggerManagerTests.counter++;1348 TestLoggerManagerTests.waitHandle.Set();1349 }1350 }1351 private void TestRunStartHandler(object sender, TestRunStartEventArgs e)1352 {1353 TestLoggerManagerTests.counter++;1354 TestLoggerManagerTests.waitHandle.Set();1355 }1356 private void DiscoveryMessageHandler(object sender, TestRunMessageEventArgs e)1357 {1358 TestLoggerManagerTests.counter++;1359 TestLoggerManagerTests.waitHandle.Set();1360 }1361 private void DiscoveryStartHandler(object sender, DiscoveryStartEventArgs e)1362 {1363 TestLoggerManagerTests.counter++;1364 TestLoggerManagerTests.waitHandle.Set();1365 }1366 private void DiscoveredTestsHandler(object sender, DiscoveredTestsEventArgs e)1367 {1368 TestLoggerManagerTests.counter++;1369 TestLoggerManagerTests.waitHandle.Set();1370 }1371 private void DiscoveryCompleteHandler(object sender, DiscoveryCompleteEventArgs e)1372 {1373 TestLoggerManagerTests.counter++;1374 TestLoggerManagerTests.waitHandle.Set();1375 }1376 }1377 [ExtensionUri("testlogger://logger2")]1378 [FriendlyName("TestLoggerExtension2")]1379 private class ValidLogger2 : ITestLogger1380 {1381 public void Initialize(TestLoggerEvents events, string testRunDirectory)1382 {1383 }1384 }1385 [ExtensionUri("testlogger://invalidLogger")]1386 [FriendlyName("InvalidTestLoggerExtension")]1387 private class InvalidLogger1388 {1389 public static int counter = 0;1390 public void Initialize(TestLoggerEvents events, string testRunDirectory)1391 {1392 counter++;1393 }1394 }1395 [ExtensionUri("testlogger://loggerWithError")]1396 [FriendlyName("ErroredTestLoggerExtension")]1397 private class LoggerWithInitializationError : ITestLogger1398 {1399 public void Initialize(TestLoggerEvents events, string testRunDirectory)1400 {1401 throw new Exception();1402 }1403 }1404 [ExtensionUri("test-logger-with-parameter://logger")]1405 [FriendlyName("TestLoggerWithParameterExtension")]1406 private class ValidLoggerWithParameters : ITestLoggerWithParameters1407 {1408 public static Dictionary<string, string> parameters;1409 public static int counter = 0;1410 public void Initialize(TestLoggerEvents events, string testRunDirectory)1411 {1412 counter += 2;1413 }1414 public void Initialize(TestLoggerEvents events, Dictionary<string, string> parameters)1415 {1416 counter++;1417 ValidLoggerWithParameters.parameters = parameters;1418 }1419 public static void Reset()1420 {1421 counter = 0;1422 ValidLoggerWithParameters.parameters = null;1423 }1424 }1425 internal class DummyTestLoggerManager : TestLoggerManager1426 {1427 public DummyTestLoggerManager() : base(null, TestSessionMessageLogger.Instance, new InternalTestLoggerEvents(TestSessionMessageLogger.Instance))1428 {...
Initialize
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel;3using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;4using System;5using System.Collections.Generic;6using System.Linq;7using System.Text;8using System.Threading.Tasks;9{10 {11 static void Main(string[] args)12 {13 TestLoggerManager logManager = new TestLoggerManager();14 logManager.Initialize("testLogger", null, null, null, null);15 }16 }17}
Initialize
Using AI Code Generation
1using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;2using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;3using System;4using System.Collections.Generic;5using System.Linq;6using System.Text;7using System.Threading.Tasks;8{9 {10 static void Main(string[] args)11 {12 TestLoggerManager testLoggerManager = new TestLoggerManager();13 testLoggerManager.Initialize(new List<string>() { "TestLogger.dll" });14 }15 }16}17var extensions = TestExtensionManager.Instance.GetTestExtensions();18var extensions = TestPluginCache.Instance.GetTestExtensions();19var extensions = TestLoggerManager.Instance.GetTestExtensions();20var extensions = TestLoggerManager.Instance.GetTestExtensions();21var extensions = TestLoggerManager.Instance.GetTestExtensions();22var extensions = TestLoggerManager.Instance.GetTestExtensions();23var extensions = TestLoggerManager.Instance.GetTestExtensions();
Initialize
Using AI Code Generation
1using System;2using System.Collections.Generic;3using System.Linq;4using System.Text;5using Microsoft.VisualStudio.TestPlatform.Common.Logging;6using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;7using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;8using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;9{10 {11 static void Main(string[] args)12 {13 TestLoggerManager testLoggerManager = new TestLoggerManager();14 testLoggerManager.Initialize(new TestLoggerEvents(), new List<ILogger>());15 }16 }17}18using System;19using System.Collections.Generic;20using System.Linq;21using System.Text;22using Microsoft.VisualStudio.TestPlatform.Common.Logging;23using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;24using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;25using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;26{27 {28 static void Main(string[] args)29 {30 TestLoggerManager testLoggerManager = new TestLoggerManager();31 testLoggerManager.Initialize(new TestLoggerEvents(), new List<ILogger>());32 }33 }34}35using System;36using System.Collections.Generic;37using System.Linq;38using System.Text;39using Microsoft.VisualStudio.TestPlatform.Common.Logging;40using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;41using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;42using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;43{44 {45 static void Main(string[] args)46 {47 TestLoggerManager testLoggerManager = new TestLoggerManager();48 testLoggerManager.Initialize(new TestLoggerEvents(), new List<ILogger>());49 }50 }51}52using System;53using System.Collections.Generic;54using System.Linq;55using System.Text;56using Microsoft.VisualStudio.TestPlatform.Common.Logging;57using Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client;58using Microsoft.VisualStudio.TestPlatform.ObjectModel.Client;59using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;60{
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!