Ejemplo n.º 1
0
 private IEnumerable <string> GetUsedKeyPaths(KeyPathsDictionary keyPathsByHookUrlAndType)
 {
     return(keyPathsByHookUrlAndType.Values.Aggregate(new HashSet <string>(), (keyPathsAcc, currentKeyPaths) => {
         keyPathsAcc.UnionWith(currentKeyPaths);
         return keyPathsAcc;
     }));
 }
Ejemplo n.º 2
0
        public void LinkKeyPathsByHook()
        {
            var allHooks = new[] {
                new Hook("1", "a/b/c", "notification_webhook", "http://some-domain/awesome_hook", new string[] {}, "json"),
                new Hook("2", "a/b/c", "notification_webhook", "http://some-domain/another_awesome_hook", new string[] {}, "json"),
                new Hook("3", "a/b/*", "notification_webhook", "http://another-domain/ok_hook", new string[] {}, "json"),
                new Hook("4", "c/q/r", "notification_webhook", "http://fourth-domain/meh_hook", new string[] {}, "json"),
                new Hook("5", "a/b/d", "notification_webhook", "http://some-domain/awesome_hook", new string[] {}, "json")
            };
            var allKeyPaths = new[] { "a/b/c", "a/b/d", "a/t/f" };

            var expectedResult = new KeyPathsDictionary
            {
                { allHooks[0], new HashSet <string> {
                      "a/b/c"
                  } },
                { allHooks[1], new HashSet <string> {
                      "a/b/c"
                  } },
                { allHooks[2], new HashSet <string> {
                      "a/b/c", "a/b/d"
                  } },
                { allHooks[4], new HashSet <string> {
                      "a/b/d"
                  } }
            };

            var result = CallPrivateStaticMethod <KeyPathsDictionary>(
                hooksHelper, "LinkKeyPathsByHook", new object[] { allKeyPaths, allHooks }
                );

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 3
0
 private Dictionary <(string type, string url), string> GetHooksWithData(
     KeyPathsDictionary keyPathsByHookUrlAndType,
     Dictionary <string, KeyPathDiff> keyPathsDiffs,
     Author author
     )
 {
     return(keyPathsByHookUrlAndType.ToDictionary(
                kvp => kvp.Key,
                kvp => {
         var hookKeyPathDiff = kvp.Value.Select(keyPath => keyPathsDiffs[keyPath]);
         var hookData = new HookData(author, hookKeyPathDiff);
         return JsonConvert.SerializeObject(hookData);
     }
                ));
 }
Ejemplo n.º 4
0
        public void AggregateKeyPathsByHookUrlAndType()
        {
            var allHooks = new Hook[] {
                new Hook("1", "a/b/c", "notification_webhook", "http://some-domain/awesome_hook"),
                new Hook("2", "a/b/c", "notification_webhook", "http://some-domain/another_awesome_hook"),
                new Hook("3", "a/b/*", "notification_webhook", "http://another-domain/ok_hook"),
                new Hook("4", "c/q/r", "notification_webhook", "http://fourth-domain/meh_hook"),
                new Hook("5", "a/b/d", "notification_webhook", "http://some-domain/awesome_hook")
            };
            var allKeyPaths = new string[] { "a/b/c", "a/b/d", "a/t/f" };

            var expectedResult = new KeyPathsDictionary();

            expectedResult.Add(
                (type: "notification_webhook", url: "http://some-domain/awesome_hook"),
                new HashSet <string> {
                "a/b/c", "a/b/d"
            }
                );
            expectedResult.Add(
                (type: "notification_webhook", url: "http://some-domain/another_awesome_hook"),
                new HashSet <string> {
                "a/b/c"
            }
                );
            expectedResult.Add(
                (type: "notification_webhook", url: "http://another-domain/ok_hook"),
                new HashSet <string> {
                "a/b/c", "a/b/d"
            }
                );

            var result = CallPrivateMethod <KeyPathsDictionary>(
                hooksHelper, "AggregateKeyPathsByHookUrlAndType", new object[] { allKeyPaths, allHooks }
                );

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 5
0
 private static Dictionary <Hook, HookData> GetHooksWithData(
     KeyPathsDictionary keyPathsByHook,
     IReadOnlyDictionary <string, KeyPathDiff> keyPathsDiffs,
     Author author
     ) =>
 keyPathsByHook.Select(kvp => (
Ejemplo n.º 6
0
 private KeyPathsDictionary FilterNonPostCommitHooks(KeyPathsDictionary hooksDictionary)
 {
     return(hooksDictionary
            .Where(kvp => _postCommitHookTypes.Contains(kvp.Key.Type))
            .ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
 }
Ejemplo n.º 7
0
 private static IEnumerable <string> GetUsedKeyPaths(KeyPathsDictionary keyPathsByHook) =>
 keyPathsByHook.Values.Aggregate(new HashSet <string>(), (keyPathsAcc, currentKeyPaths) =>
 {
     keyPathsAcc.UnionWith(currentKeyPaths);
     return(keyPathsAcc);
 });
Ejemplo n.º 8
0
 private KeyPathsDictionary FilterNonNotificationHooks(KeyPathsDictionary hooksDictionary)
 {
     return(hooksDictionary
            .Where(kvp => NotificationHookTypes.Contains(kvp.Key.type))
            .ToDictionary(kvp => kvp.Key, kvp => kvp.Value));
 }