コード例 #1
0
        public void IsMatchCombinations(bool expectedMatch, bool[] states)
        {
            Filter<object>[] filters = GenericCollectionUtils.ConvertAllToArray<bool, Filter<object>>(states, delegate(bool state)
            {
                return state ? (Filter<object>)new AnyFilter<object>() : new NoneFilter<object>();
            });

            OrFilter<object> combinator = new OrFilter<object>(filters);
            Assert.AreEqual(expectedMatch, combinator.IsMatch(null));
        }
コード例 #2
0
        public void IsMatchCombinations(bool expectedMatch, bool[] states)
        {
            Filter <object>[] filters = GenericCollectionUtils.ConvertAllToArray <bool, Filter <object> >(states, delegate(bool state)
            {
                return(state ? (Filter <object>) new AnyFilter <object>() : new NoneFilter <object>());
            });

            OrFilter <object> combinator = new OrFilter <object>(filters);

            Assert.AreEqual(expectedMatch, combinator.IsMatch(null));
        }
コード例 #3
0
        public void IsMatchTest()
        {
            {
                FilterBase f1 = new FacilityEqualsFilter
                {
                    facility = SyslogFacility.Ftp
                },
                           f2 = new MessageRegexMatchFilter
                {
                    pattern = "^FFDA"
                };

                OrFilter target = new OrFilter();
                target.filter = new FilterBase[] { f1, f2 };


                SyslogMessage message = new SyslogMessage
                {
                    Facility = SyslogFacility.Internally,
                    Severity = SyslogSeverity.Error,
                    Text     = "FFDA WOW!"
                };


                bool expected = true;
                bool actual;
                actual = target.IsMatch(message);
                Assert.AreEqual(expected, actual);
            }

            {
                FilterBase f1 = new FacilityEqualsFilter
                {
                    facility = SyslogFacility.Ftp
                },
                           f2 = new MessageRegexMatchFilter
                {
                    pattern = "^FFDA"
                };

                OrFilter target = new OrFilter();
                target.filter = new FilterBase[] { f1, f2 };


                SyslogMessage message = new SyslogMessage
                {
                    Facility = SyslogFacility.Ftp,
                    Severity = SyslogSeverity.Error,
                    Text     = "Nobody!"
                };


                bool expected = true;
                bool actual;
                actual = target.IsMatch(message);
                Assert.AreEqual(expected, actual);
            }

            {
                string msg =
                    @"<34>1 2003-10-11T22:14:15.003Z mymachine.example.com su - ID47 - ’su root’ failed for lonvick on /dev/pts/8";
                FilterBase f1 = new FacilityEqualsFilter
                {
                    facility = SyslogFacility.Security
                },
                           f2 = new MessageRegexMatchFilter
                {
                    //Ok, that should be the real UNIX user pattern but let's assume only letters and numbers here :)
                    pattern = "’su root’ failed for [a-zA-Z0-9]"
                },
                           f3 = new SeverityFilter
                {
                    comparison = ComparisonOperator.neq,
                    severity   = SyslogSeverity.Emergency
                };

                OrFilter target = new OrFilter();
                target.filter = new FilterBase[] { f1, f2, f3 };


                SyslogMessage message = SyslogMessage.Parse(msg);


                bool expected = true;
                bool actual;
                actual = target.IsMatch(message);
                Assert.AreEqual(expected, actual);
            }
        }