private static void SetupWebHookOptions(WebHookOptions options)
 {
     if (!options.HttpContextItemsTypes.Contains(typeof(NameValueCollection)))
     {
         options.HttpContextItemsTypes.Add(typeof(NameValueCollection));
     }
 }
        public void ReturnFirstMatchedRuleByRefAndRepositoryUrl()
        {
            var rules = new WebHookOptions
            {
                Rules = new List <WebHookRule>
                {
                    new WebHookRule
                    {
                        Name          = "no match",
                        Ref           = "/test/test",
                        RepositoryUrl = "repo1"
                    },
                    new WebHookRule
                    {
                        Name          = "match",
                        Ref           = "/test/test",
                        RepositoryUrl = "repo2"
                    }
                }
            };

            var sup = new RuleMatcher(new OptionsWrapper <WebHookOptions>(rules), new NullLogger <RuleMatcher>());

            var actual = sup.Match("/test/test", "repo2");

            actual.Name.Should().Be("match");
        }
        public void ReturnFirstMatchedRuleByMatch_IfRepositoryUrlIsNotSpecified()
        {
            var rules = new WebHookOptions
            {
                Rules = new List <WebHookRule>
                {
                    new WebHookRule
                    {
                        Name  = "no match",
                        Match = "/test/test1"
                    },
                    new WebHookRule
                    {
                        Name  = "match",
                        Match = "/test/test"
                    },
                    new WebHookRule
                    {
                        Name  = "match2",
                        Match = "/test/test"
                    }
                }
            };

            var sup = new RuleMatcher(new OptionsWrapper <WebHookOptions>(rules), new NullLogger <RuleMatcher>());

            var actual = sup.Match("/test/test", null);

            actual.Name.Should().Be("match");
        }
Example #4
0
 private static void SetupWebHookOptions(WebHookOptions options)
 {
     if (!options.HttpContextItemsTypes.Contains(typeof(StripeEvent)))
     {
         options.HttpContextItemsTypes.Add(typeof(StripeEvent));
     }
 }
Example #5
0
 private static void SetupWebHookOptions(WebHookOptions options)
 {
     if (!options.HttpContextItemsTypes.Contains(typeof(SalesforceNotifications)))
     {
         options.HttpContextItemsTypes.Add(typeof(SalesforceNotifications));
     }
 }
Example #6
0
        /// <summary>
        /// Extension to Register Custom WebHook Senders
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to register services with</param>
        /// <param name="setupAction">A <see cref="Action{WebHookOptions}"/> that can be used to configure Custom WebHook Sender</param>
        public static void AddCustomWebHookSender(this IServiceCollection services, Action <WebHookOptions> setupAction)
        {
            services.Configure <WebHookOptions>(setupAction);


            WebHookOptions options = new WebHookOptions();

            setupAction(options);
            services.AddSingleton(typeof(IWebHookStore), options.StoreType);
            services.AddScoped(typeof(IWebHookSender), options.SenderType);
            services.AddScoped <IWebHookManager, WebHookManager>();
        }
 public RuleMatcher(IOptions <WebHookOptions> options, ILogger <RuleMatcher> log)
 {
     _log     = log;
     _options = options.Value;
 }