public void GetReceiver_Returns_Null_IfNoReceivers() { // Arrange IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(MockReceiverName); // Assert Assert.Null(actual); }
public void GetReceiver_Returns_ReceiverWithSingleName(string receiverName) { // Arrange _receivers.Add(_receiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(receiverName); // Assert Assert.Same(_receiver, actual); }
public void GetReceiver_Returns_Null_IfUnknownReceiver() { // Arrange MockReceiver multiReceiver = new MockReceiver("你好", "世界", "unknown"); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(MockReceiverName); // Assert Assert.Null(actual); }
public void GetReceiver_Returns_ReceiverWithMultipleNames(string name1, string name2, string name3) { // Arrange MockReceiver multiReceiver = new MockReceiver(name1, name2, name3); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver(MockReceiverName); // Assert Assert.Same(multiReceiver, actual); }
public void GetReceiver_Throws_IfDuplicateSingleNameReceivers() { // Arrange _receivers.Add(_receiver); _receivers.Add(_receiver); _receivers.Add(_receiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => manager.GetReceiver(MockReceiverName)); // Assert Assert.Contains("Multiple types were found that match the WebHook receiver named 'MockReceiver'. This can happen if multiple receivers are defined with the same name but different casing which is not supported. The request for 'MockReceiver' has found the following matching receivers:", ex.Message); }
public void GetReceiver_Returns_Null_IfUnknownReceiver() { // Arrange MockReceiver multiReceiver = new MockReceiver(); _receivers.Add(multiReceiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act IWebHookReceiver actual = manager.GetReceiver("unknown"); // Assert Assert.Null(actual); }
public void GetReceiver_Throws_IfDuplicateSingleNameReceivers() { // Arrange _receivers.Add(_receiver); _receivers.Add(_receiver); _receivers.Add(_receiver); IWebHookReceiverManager manager = new WebHookReceiverManager(_receivers, _loggerMock.Object); // Act InvalidOperationException ex = Assert.Throws<InvalidOperationException>(() => manager.GetReceiver(MockReceiverName)); // Assert Assert.Contains("Multiple types were found that match the WebHook receiver named 'MockReceiver'. This can happen if multiple receivers are defined with the same name but different casing which is not supported. The request for 'MockReceiver' has found the following matching receivers:", ex.Message); }
/// <summary> /// Gets a default <see cref="IWebHookReceiverManager"/> implementation which is used if none are registered with the /// Dependency Injection engine. /// </summary> /// <returns>A default <see cref="IWebHookReceiverManager"/> instance.</returns> public static IWebHookReceiverManager GetReceiverManager(IEnumerable<IWebHookReceiver> receivers, ILogger logger) { if (_receiverManager != null) { return _receiverManager; } if (receivers == null) { throw new ArgumentNullException(nameof(receivers)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } IWebHookReceiverManager instance = new WebHookReceiverManager(receivers, logger); Interlocked.CompareExchange(ref _receiverManager, instance, null); return _receiverManager; }
/// <summary> /// Gets a default <see cref="IWebHookReceiverManager"/> implementation which is used if none are registered with the /// Dependency Injection engine. /// </summary> /// <returns>A default <see cref="IWebHookReceiverManager"/> instance.</returns> public static IWebHookReceiverManager GetReceiverManager(IEnumerable <IWebHookReceiver> receivers, ILogger logger) { if (_receiverManager != null) { return(_receiverManager); } if (receivers == null) { throw new ArgumentNullException(nameof(receivers)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } IWebHookReceiverManager instance = new WebHookReceiverManager(receivers, logger); Interlocked.CompareExchange(ref _receiverManager, instance, null); return(_receiverManager); }