Пример #1
0
        public void IsMatchTest()
        {
            PropertyFilter target  = new PropertyFilter();
            SyslogMessage  message = new SyslogMessage
            {
                Facility = SyslogFacility.Internally,
                Severity = SyslogSeverity.Error,
                Text     = "FFDA WOW!"
            };

            target.value        = "Internally";
            target.propertyName = Property.Facility;
            target.comparison   = ComparisonOperator.eq;
            bool expected = true;
            bool actual;

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

            target.value        = "Alert";
            target.propertyName = Property.Severity;
            target.comparison   = ComparisonOperator.neq;
            expected            = true;
            actual = target.IsMatch(message);
            Assert.AreEqual(expected, actual);
        }
        public void Test_IsMatch()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the PropertyFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID    = Guid.NewGuid();
                article.Title = "Test Title 1";

                TestArticle article2 = new TestArticle();
                article2.ID    = Guid.NewGuid();
                article2.Title = "Test Title 2";

                //DataAccess.Data.Saver.Save(article);
                //DataAccess.Data.Saver.Save(article2);

                PropertyFilter filter = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter.Operator      = FilterOperator.Equal;
                filter.PropertyName  = "Title";
                filter.PropertyValue = article.Title;
                filter.AddType(typeof(TestArticle));


                bool isMatch = filter.IsMatch(article);
                Assert.IsTrue(isMatch, "The IsMatch function returned false when it should have been true.");
            }
        }
Пример #3
0
        public void Test_IsMatch_And_True()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Article1";

            FilterGroup group = new FilterGroup();

            PropertyFilter filter1 = new PropertyFilter();

            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName  = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");


            PropertyFilter filter2 = new PropertyFilter();

            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName  = "ID";
            filter2.PropertyValue = article.ID;

            Assert.IsTrue(filter2.IsMatch(article), "filter2 failed to match article when it should.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsTrue(group.IsMatch(article), "group failed to match when it should");
        }
Пример #4
0
        public void Test_IsMatch_Or_True_OneMatches()
        {
            TestArticle article = new TestArticle();

            article.ID    = Guid.NewGuid();
            article.Title = "Article1";

            FilterGroup group = new FilterGroup();

            group.Operator = FilterGroupOperator.Or;

            PropertyFilter filter1 = new PropertyFilter();

            filter1.AddType(typeof(TestArticle));
            filter1.PropertyName  = "Title";
            filter1.PropertyValue = article.Title;

            Assert.IsTrue(filter1.IsMatch(article), "filter1 failed to match article when it should.");


            PropertyFilter filter2 = new PropertyFilter();

            filter2.AddType(typeof(TestArticle));
            filter2.PropertyName  = "Title";
            filter2.PropertyValue = "MISMATCH";             // This one should fail

            Assert.IsFalse(filter2.IsMatch(article), "filter2 matched when it should fail.");

            group.Add(filter1);
            group.Add(filter2);

            Assert.IsTrue(group.IsMatch(article), "group failed when it should match");
        }
        public void Test_IsMatch_Exclude()
        {
            using (LogGroup logGroup = LogGroup.Start("Testing the PropertyFilter.IsMatch function.", NLog.LogLevel.Debug))
            {
                TestArticle article = new TestArticle();
                article.ID = Guid.NewGuid();

                TestCategory category = new TestCategory();
                category.ID = Guid.NewGuid();


                PropertyFilter filter = (PropertyFilter)DataAccess.Data.CreateFilter(typeof(PropertyFilter));
                filter.Operator      = FilterOperator.Equal;
                filter.PropertyName  = "Title";
                filter.PropertyValue = "MISMATCH";                 // Should fail to match
                filter.AddType(typeof(TestArticle));



                bool isMatch = filter.IsMatch(article);
                Assert.IsFalse(isMatch, "The IsMatch function returned true when it should have been false.");
            }
        }