Example #1
0
        public Filter <Logic.Transaction> ReturnLatestTransactions(NumberEnums number, int seconds = -1, BankAccount account = null)
        {
            Filter <Logic.Transaction> filter = new Filter <Logic.Transaction>(ReturnAllTransactions()).AddFilter(t => {
                if (number == NumberEnums.Positive)
                {
                    return(t.Amount > 0);
                }
                else if (number == NumberEnums.Negative)
                {
                    return(t.Amount < 0);
                }
                else
                {
                    return(t.Amount > 0);
                }
            });

            if (seconds >= 0)
            {
                return(filter.AddFilter(t => t.LastExecuted >= DateTime.Now.AddSeconds(-seconds)));
            }

            if (account != null)
            {
                filter.AddFilter(t => t.Account == account);
            }

            return(filter);
        }
Example #2
0
        public void AddFilter_Adds_ValidAssemblyClassPair(
            [ValueSource("_filterExpressions")] FilterData assemblyClassPair)
        {
            // arrange
            var filter = new Filter(false);

            // act
            filter.AddFilter(assemblyClassPair.FilterExpression);

            // assert
            Assert.AreEqual(1, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilters.Count : filter.ExclusionFilters.Count);

            Assert.AreEqual(assemblyClassPair.ProcessResult,
                            assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilters[0].ProcessName
                    : filter.ExclusionFilters[0].ProcessName);

            Assert.AreEqual(assemblyClassPair.AssemblyResult,
                            assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilters[0].AssemblyName
                    : filter.ExclusionFilters[0].AssemblyName);

            Assert.AreEqual(assemblyClassPair.ClassResult,
                            assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilters[0].ClassName
                : filter.ExclusionFilters[0].ClassName);
        }
Example #3
0
        public void RunGroupTest <T>(List <T> seedValues, GroupOperators op, Operators opFirst, string valueFirst,
                                     Operators opSecond, string valueSecond, List <T> expectedResults)
        {
            List <TestContainer <T> > list = new List <TestContainer <T> >();

            foreach (var val in seedValues)
            {
                list.Add(new TestContainer <T> {
                    Value = val
                });
            }

            var filterProvider = new Filter <TestContainer <T> >();
            var group          = new PropertyFilterGroup();

            group.Operator = op;
            group.Children.Add(new PropertyFilter {
                Operator = opFirst, PropertyName = "Value", Value = valueFirst
            });
            group.Children.Add(new PropertyFilter {
                Operator = opSecond, PropertyName = "Value", Value = valueSecond
            });
            filterProvider.AddFilter(group);
            var result = filterProvider.Apply(list.AsQueryable());
            var values = result.Select(x => x.Value).ToList();

            Assert.True(Enumerable.SequenceEqual(values.OrderBy(x => x), expectedResults.OrderBy(x => x)));
        }
Example #4
0
        public void CreateAndAddFilter(string name, bool strict, Func <DataList, bool> filter)
        {
            Filter f = new Filter(name, strict);

            f.AddFilter(filter);

            filters.Add(f);
        }
        protected override VCFilter _AddFilter(string name)
        {
            if (!Filter.CanAddFilter(name))
            {
                throw new InvalidOperationException();
            }

            return((VCFilter)Filter.AddFilter(name));
        }
Example #6
0
        public void ApplyFilter_OrElseFilter_ReturnListCountOne()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> isGreaterThanSeven = val => val > 7;
            Predicate <int> isSmallerThanTen   = val => val < 10;

            filter.AddFilter(isGreaterThanSeven);
            filter.AddFilter(isSmallerThanTen);

            List <int> numbers = new List <int>()
            {
                0, 1, 3, 4, 9, 5, 17
            };
            List <int> resultList = filter.ApplyFilters(numbers).ToList();

            Assert.IsTrue(resultList.Count == 1);
        }
Example #7
0
        public void ApplyFilter_MultipleFilter_ReturnListCountTwo()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> predicate        = val => val > 10;
            Predicate <int> anotherPredicate = val => val == 17;

            filter.AddFilter(predicate);
            filter.AddFilter(anotherPredicate);

            List <int> numbers = new List <int>()
            {
                0, 1, 3, 4, 9, 5, 17
            };
            List <int> resultList = filter.ApplyFilters(numbers).ToList();

            Assert.IsTrue(resultList.Count == 1);
        }
Example #8
0
        public void AddFilter_AnonymousFilter_FilterCountEqualsOne()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> predicate = val => val > 0;

            filter.AddFilter(predicate);

            Assert.AreEqual(filter.Count, 1);
        }
Example #9
0
        public void AddFilter_ThrowsException_WhenInvalid_AssemblyClassPair(
            [ValueSource("_invalidFilterExpressions")] string assemblyClassPair)
        {
            // arrange
            var filter = new Filter();

            // act/assert
            Assert.Catch <InvalidOperationException>(() => filter.AddFilter(assemblyClassPair),
                                                     "'{0}' should be invalid", assemblyClassPair);
        }
Example #10
0
        public void AddFilter_ThrowsException_WhenInvalid_AssemblyClassPair(
            [ValueSource("_invalidFilterExpressions")] string assemblyClassPair)
        {
            // arrange
            var filter = new Filter(false);

            // act/assert
            Assert.Catch <ExitApplicationWithoutReportingException>(() => filter.AddFilter(assemblyClassPair),
                                                                    "'{0}' should be invalid", assemblyClassPair);
        }
Example #11
0
        public void RemoveByGroup_GroupDoesNotExists_ReturnsFalse()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> predicate = val => val > 0;

            filter.AddFilter(predicate, group: "test");
            bool result = filter.RemoveByGroup("something different");

            Assert.IsFalse(result);
        }
Example #12
0
        public void RemoveByGroup_GroupExists_ReturnsTrue()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> predicate = val => val > 0;

            filter.AddFilter(predicate, group: "test");
            bool result = filter.RemoveByGroup("test");

            Assert.IsTrue(result);
        }
Example #13
0
        public Filter <Logic.Transaction> ReturnLatestTransactions(int seconds, BankAccount account = null)
        {
            Filter <Logic.Transaction> filter = new Filter <Logic.Transaction>(ReturnAllTransactions()).AddFilter(t => t.LastExecuted >= DateTime.Now.AddSeconds(-seconds));

            if (account != null)
            {
                filter.AddFilter(t => t.Account == account);
            }

            return(filter);
        }
Example #14
0
        public void CanHandle_AssemblyClassFilters_ExpressedAs_RegularExpressions(string namespaceClass, bool canInstrument)
        {
            // arrange
            var filter = new Filter(true);

            filter.AddFilter(@"+[(A1\.B[23])]([CD]1.*)");

            // act

            // assert
            Assert.AreEqual(canInstrument, filter.InstrumentClass("A1.B2", namespaceClass));
        }
Example #15
0
        public void CanHandle_AssemblyFilters_ExpressedAs_RegularExpressions(string assembly, bool canUse)
        {
            // arrange
            var filter = new Filter(true);

            filter.AddFilter(@"+[(A1\.B[23])]([CD]1.*)");

            // act

            // assert
            Assert.AreEqual(canUse, filter.UseAssembly("processName", assembly));
        }
Example #16
0
        public void ApplyFilter_OneFilter_ReturnListCountTwo()
        {
            Filter <int> filter = new Filter <int>();

            Predicate <int> predicate = val => val > 2;

            filter.AddFilter(predicate);

            List <int> numbers = new List <int>()
            {
                0, 1, 3, 4
            };
            List <int> resultList = filter.ApplyFilters(numbers).ToList();

            Assert.IsTrue(resultList.Count == 2);
        }
        public SelectFilterFromMonitorGroup(Options o, List<string> monitor)
        {
            InitializeComponent();
            m_options = o;
            this.FilterString = o.filterList;
            this.ResizeRedraw = true;
            this.splitContainer1.Panel1.Resize += new EventHandler(Panel1_Resize);
            cusfil = new CustomFilterList();
            FilterObject defFiltOb;
            FilterO = new List<FilterObject>();
            UserAddFilter = new List<FilterObject>();
            MgprF = new FolderTrack.Types.MGProperties();

            foreach (string listIt in FilterString)
            {
                defFiltOb = new FilterObject();
                defFiltOb.mgpro = null;
                defFiltOb.filter = listIt;
                defFiltOb.use = true;
                defFiltOb.mode = FilterObject.FilterObjectMode.KEEP;
                defFiltOb.AddToCa(this);
                FilterO.Add(defFiltOb);
                UserAddFilter.Add(defFiltOb);

            }
            foreach (GuiInfoMGProperties mgpro in o.proper)
            {
                defFiltOb = new FilterObject();
                defFiltOb.mgpro = mgpro;

                defFiltOb.filter = mgpro.description;
                defFiltOb.discription = mgpro.title;
                defFiltOb.use = mgpro.active;
                defFiltOb.mode = FilterObject.FilterObjectMode.PROFILT;
                defFiltOb.AddToCa(this);
                FilterO.Add(defFiltOb);
            }

            cusfil.SetCus(FilterO);
            cusfil.Dock = DockStyle.Fill;

            this.splitContainer1.Panel1.Controls.Add(cusfil);
            TreeNodeFromString = new Dictionary<string, TreeNode>();
            filt = new Filter();
            filt.AddFilter(FilterString);
            PopulateTree(monitor);
        }
Example #18
0
        public void AddFilter_Adds_ValidAssemblyClassPair(
            [ValueSource("_assemblyClassPairs")] AssemblyClassData assemblyClassPair)
        {
            // arrange
            var filter = new Filter();

            // act
            filter.AddFilter(assemblyClassPair.AssemblyClass);

            // assert
            Assert.AreEqual(1, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilter.Count : filter.ExclusionFilter.Count);

            Assert.AreEqual(assemblyClassPair.AssemblyResult, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilter[0].Key : filter.ExclusionFilter[0].Key);

            Assert.AreEqual(assemblyClassPair.ClassResult, assemblyClassPair.FilterTypeResult == FilterType.Inclusion ?
                            filter.InclusionFilter[0].Value : filter.ExclusionFilter[0].Value);
        }
Example #19
0
        public void RunTest <T>(List <T> seedValues, Operators op, string value, List <T> expectedResults)
        {
            List <TestContainer <T> > list = new List <TestContainer <T> >();

            foreach (var val in seedValues)
            {
                list.Add(new TestContainer <T> {
                    Value = val
                });
            }

            var filterProvider = new Filter <ITestContainer <T> >();

            filterProvider.AddFilter(new PropertyFilter {
                Operator = op, PropertyName = "Value", Value = value
            });
            var result = filterProvider.Apply(list.AsQueryable());
            var values = result.Select(x => x.Value).ToList();

            Assert.True(Enumerable.SequenceEqual(values.OrderBy(x => x), expectedResults.OrderBy(x => x)));
        }
Example #20
0
        private static IFilter BuildFilter(CommandLineParser parser)
        {
            var filter = new Filter();

            // apply filters
            if (!parser.NoDefaultFilters)
            {
                filter.AddFilter("-[mscorlib]*");
                filter.AddFilter("-[mscorlib.*]*");
                filter.AddFilter("-[System]*");
                filter.AddFilter("-[System.*]*");
                filter.AddFilter("-[Microsoft.VisualBasic]*");
            }


            if (parser.Filters.Count == 0 && string.IsNullOrEmpty(parser.FilterFile))
            {
                filter.AddFilter("+[*]*");
            }
            else
            {
                if (!string.IsNullOrEmpty(parser.FilterFile))
                {
                    if (!File.Exists(parser.FilterFile))
                    {
                        System.Console.WriteLine("FilterFile '{0}' cannot be found - have you specified your arguments correctly?", parser.FilterFile);
                    }
                    else
                    {
                        var filters = File.ReadAllLines(parser.FilterFile);
                        filters.ToList().ForEach(filter.AddFilter);
                    }
                }
                if (parser.Filters.Count > 0)
                {
                    parser.Filters.ForEach(filter.AddFilter);
                }
            }

            filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray());
            filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray());
            filter.AddTestFileFilters(parser.TestFilters.ToArray());

            return(filter);
        }
Example #21
0
 protected RegressionBase(IEnumerable <T> items, Func <T, TResult?> resultFunc) :
     this(items, i => resultFunc(i).Value)
 {
     Filter.AddFilter(resultFunc);
 }
Example #22
0
        static void Main(string[] args)
        {
            Power          power  = new Power();
            WaterContainer water  = new WaterContainer();
            Filter         filter = new Filter();
            Powder         powder = new Powder();
            TeaFlavor      flavor = new TeaFlavor();

            while (true)
            {
                Console.WriteLine("Options:\n 1: Power option\n 2: Fill water\n 3: Insert filter\n 4: Remove filter\n 5: Choose drink");
                int choice = int.Parse(Console.ReadLine());
                Console.Clear();
                switch (choice)
                {
                case 1:

                    Console.WriteLine(" 1: Turn on\n 2: Turn off");
                    choice = int.Parse(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine(power.PowerOn(powder.containPowder, water.water));
                        break;

                    case 2:
                        Console.WriteLine(power.PowerOff());
                        break;
                    }
                    break;

                case 2:

                    Console.WriteLine(" 1: Add water in ML: ");
                    choice = int.Parse(Console.ReadLine());
                    Console.WriteLine(water.AddWater(choice));

                    break;

                case 3:
                    Console.WriteLine(filter.AddFilter());
                    break;

                case 4:
                    Console.WriteLine(filter.RemoveFilter(powder.containPowder));
                    break;

                case 5:
                    Console.WriteLine(" 1: Coffe\n 2: The");
                    choice = int.Parse(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                        Console.WriteLine("How many scoops of powder?");
                        choice = int.Parse(Console.ReadLine());
                        Console.WriteLine(powder.AddPowder(choice, filter.filter));
                        break;

                    case 2:
                        Console.WriteLine("What flavor {0}", flavor.Flavor());
                        break;
                    }
                    break;

                case 6:

                    break;
                }
            }
        }