コード例 #1
0
        public void TestRuleMatchesEvent()
        {
            IEnumerable <Rule> ret      = GetRules(AlsoGetInactive: false);
            string             exePath  = @"C:\Windows\System32\svchost.exe";
            const int          PROF_ALL = (int)NET_FW_PROFILE_TYPE2_.NET_FW_PROFILE2_ALL;

            Console.WriteLine($"{exePath}");
            int cntMatch = 0;

            foreach (Rule rule in ret)
            {
                bool matches = FirewallHelper.RuleMatchesEvent(rule, currentProfile: PROF_ALL, appPkgId: null, svcName: "*", path: exePath, target: "*", remoteport: "*");
                if (matches)
                {
                    string ruleFriendlyPath = String.IsNullOrWhiteSpace(rule.ApplicationName) ? rule.ApplicationName : FileHelper.GetFriendlyPath(rule.ApplicationName);
                    Assert.True(String.IsNullOrWhiteSpace(ruleFriendlyPath) || exePath.Equals(ruleFriendlyPath, StringComparison.OrdinalIgnoreCase));
                    Console.WriteLine($"match found={matches}, rule={rule.Name}");
                    cntMatch++;
                }
            }
            Assert.True(cntMatch > 0);
        }