Beispiel #1
0
        static bool AreValidSearchArguments(string[] args, out string field, out string op, out string[] val)
        {
            field = op = "";
            val   = new string[10];
            if (args.Length > 1)
            {
                switch (args[1].ToLower())
                {
                case "date":
                {
                    SearchDateArgument searchArgs = new SearchDateArgument(args);
                    if (searchArgs.IsValid())
                    {
                        field  = searchArgs.Field;
                        op     = searchArgs.Criteria;
                        val[0] = searchArgs.Date;
                        val[1] = searchArgs.AnotherDate;
                        Array.Resize(ref val, 2);
                        return(true);
                    }
                    break;
                }

                case "description":
                {
                    SearchDescriptionArgument searchArgs = new SearchDescriptionArgument(args);
                    if (searchArgs.IsValid())
                    {
                        field  = searchArgs.Field;
                        op     = searchArgs.Criteria;
                        val[0] = searchArgs.Value;
                        Array.Resize(ref val, 1);
                        return(true);
                    }
                    break;
                }

                case "tag":
                {
                    SearchTagArgument searchArgs = new SearchTagArgument(args);
                    if (searchArgs.IsValid())
                    {
                        field = searchArgs.Field;
                        op    = searchArgs.Criteria;
                        val   = searchArgs.Values;
                        return(true);
                    }
                    break;
                }

                default:
                {
                    InvalidCommand();
                    return(false);
                }
                }
            }
            InvalidCommand();
            return(false);
        }
        public void ShouldListOnlyEventsWithTitleContainingText()
        {
            Events newEvents = new Events {
                { new Event ( "2015/01/01", "one", "test") },
                {new Event("2015/11/15","two", "two cats") },
            };

            List<Event> expectedList = new List<Event>
            {{ new Event("2015/11/15","two", "two cats") },
            };
            string[] inputArgs = { "/search", "title", "contains", "two" };

            SearchDescriptionArgument searchArgs = new SearchDescriptionArgument(inputArgs);
            string field = "";
            string op = "";
            string val1 = "";

            searchArgs.IsValid();
            field = searchArgs.Field;
            op = searchArgs.Criteria;
            val1 = searchArgs.Value;

            Events filteredList = Dispenser.SearchEvents(newEvents,field, op, new String[] { val1 });
            Utils.AssertAreEqual(filteredList, expectedList);
        }
Beispiel #3
0
 static bool AreValidSearchArguments(string[] args, out string field, out string op, out string[] val)
 {
     field = op = "";
     val = new string[10];
     if (args.Length > 1)
     {
         switch (args[1].ToLower())
         {
             case "date":
                 {
                     SearchDateArgument searchArgs = new SearchDateArgument(args);
                     if (searchArgs.IsValid())
                     {
                         field = searchArgs.Field;
                         op = searchArgs.Criteria;
                         val[0] = searchArgs.Date;
                         val[1] = searchArgs.AnotherDate;
                         Array.Resize(ref val, 2);
                         return true;
                     }
                     break;
                 }
             case "description":
                 {
                     SearchDescriptionArgument searchArgs = new SearchDescriptionArgument(args);
                     if (searchArgs.IsValid())
                     {
                         field = searchArgs.Field;
                         op = searchArgs.Criteria;
                         val[0] = searchArgs.Value;
                         Array.Resize(ref val, 1);
                         return true;
                     }
                     break;
                 }
             case "tag":
                 {
                     SearchTagArgument searchArgs = new SearchTagArgument(args);
                     if (searchArgs.IsValid())
                     {
                         field = searchArgs.Field;
                         op = searchArgs.Criteria;
                         val = searchArgs.Values;
                         return true;
                     }
                     break;
                 }
             default:
                 {
                     InvalidCommand();
                     return false;
                 }
         }
     }
     InvalidCommand();
     return false;
 }
        public void ShouldNotListEventsWithSometitle()
        {
            Events newEvents = new Events {
                        { new Event ( "2015/01/01", "one", "test") },
                        {new Event("2015/11/15", "two cats") },
                };

            string[] inputArgs = { "/search", "title", "contains", "pair" };
            SearchDescriptionArgument searchArgs = new SearchDescriptionArgument(inputArgs);
            string field = "";
            string op = "";
            string val1 = "";

            searchArgs.IsValid();
            field = searchArgs.Field;
            op = searchArgs.Criteria;
            val1 = searchArgs.Value;

            Events filteredList = Dispenser.SearchEvents(newEvents,field, op, new String[] { val1 });

            filteredList.ShouldBeEmpty();
        }