public virtual void Initialize(string name, string config) { if (ReceiverMock == null) { ReceiverMock = new Mock <T> { CallBase = true }; } Receiver = ReceiverMock.Object; Logger = new Mock <ILogger>().Object; name = name ?? Receiver.Name; Settings = new SettingsDictionary { [SecretPrefix + name] = config, }; ReceiverConfig = new WebHookReceiverConfig(Settings, Logger); HttpConfig = HttpConfigurationMock.Create(new Dictionary <Type, object> { { typeof(IWebHookReceiverConfig), ReceiverConfig }, { typeof(SettingsDictionary), Settings }, }); RequestContext = new HttpRequestContext { Configuration = HttpConfig }; }
public void GetConfigKey(string receiver, string id, string expected) { // Act string actual = WebHookReceiverConfig.GetConfigKey(receiver, id); // Assert Assert.Equal(expected, actual); }
public void AddKey_AddsItem(string receiver, string id, string key) { // Arrange IDictionary <string, string> config = new Dictionary <string, string>(); // Act WebHookReceiverConfig.AddKey(config, _logger, receiver, id, "Value"); // Assert Assert.Equal("Value", config[key]); }
public void ReadSettings_Parses_ValidValues(IDictionary <string, string> input, IDictionary <string, string> expected) { // Arrange SettingsDictionary settings = GetSettings(input); // Act IDictionary <string, string> actual = WebHookReceiverConfig.ReadSettings(settings, logger: null); // Assert Assert.Equal(expected, actual); }
public async Task GetReceiverConfigAsync_Returns_ExpectedValue(IDictionary <string, string> input, string receiver, string id, string expected) { // Arrange SettingsDictionary settings = GetSettings(input); WebHookReceiverConfig config = new WebHookReceiverConfig(settings, _logger); // Act string actual = await config.GetReceiverConfigAsync(receiver, id); // Assert Assert.Equal(expected, actual); }
public async Task GetReceiverConfigAsync_Returns_ExpectedValue(IDictionary<string, string> input, string receiver, string id, string expected) { // Arrange SettingsDictionary settings = GetSettings(input); WebHookReceiverConfig config = new WebHookReceiverConfig(settings, _logger); // Act string actual = await config.GetReceiverConfigAsync(receiver, id); // Assert Assert.Equal(expected, actual); }
public void AddKey_ThrowsOnDuplicateKey() { // Arrange IDictionary <string, string> config = new Dictionary <string, string>(); WebHookReceiverConfig.AddKey(config, _logger, "Receiver", "Id", "Value"); // Act InvalidOperationException ioex = Assert.Throws <InvalidOperationException>(() => WebHookReceiverConfig.AddKey(config, _logger, "Receiver", "Id", "Value")); // Assert Assert.Equal("Could not add configuration for receiver 'Receiver' and id 'Id': An item with the same key has already been added.", ioex.Message); }
/// <summary> /// Gets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the /// Dependency Injection engine. /// </summary> /// <returns>A default <see cref="IWebHookReceiverConfig"/> instance.</returns> public static IWebHookReceiverConfig GetReceiverConfig(SettingsDictionary settings, ILogger logger) { if (_receiverConfig != null) { return _receiverConfig; } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } IWebHookReceiverConfig instance = new WebHookReceiverConfig(settings, logger); Interlocked.CompareExchange(ref _receiverConfig, instance, null); return _receiverConfig; }
/// <summary> /// Gets a default <see cref="IWebHookReceiverConfig"/> implementation which is used if none are registered with the /// Dependency Injection engine. /// </summary> /// <returns>A default <see cref="IWebHookReceiverConfig"/> instance.</returns> public static IWebHookReceiverConfig GetReceiverConfig(SettingsDictionary settings, ILogger logger) { if (_receiverConfig != null) { return(_receiverConfig); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } IWebHookReceiverConfig instance = new WebHookReceiverConfig(settings, logger); Interlocked.CompareExchange(ref _receiverConfig, instance, null); return(_receiverConfig); }
public void ReadSettings_Throws_OnInvalidValues() { // Arrange SettingsDictionary settings = GetSettings(new Dictionary <string, string> { { "MS_WebHookReceiverSecret_A", "a=b=c" } }); // Act InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => WebHookReceiverConfig.ReadSettings(settings, logger: null)); // Assert Assert.Equal("The 'MS_WebHookReceiverSecret_A' application setting must have a comma-separated value of one or more secrets of the form <secret> or <id>=<secret>.", ex.Message); }