Пример #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 ShouldListEventsFromThisWeek()
        {
            Events newEvents = new Events
            {
                { new Event ( "2015/01/01", "one", "test") },
                {new Event(DateTime.Today.ToShortDateString(), "two") },
            };

            List<Event> expectedList = new List<Event>
            {{ new Event (DateTime.Today.ToShortDateString(),"two") },
            };

            string[] args = { "/search", "date", "this week" };
            SearchDateArgument searchArgs = new SearchDateArgument(args);
            string field = "";
            string op = "";
            string val1 = "";
            string val2 = "";
            searchArgs.IsValid();
            field = searchArgs.Field;
            op = searchArgs.Criteria;
            val1 = searchArgs.Date;
            val2 = searchArgs.AnotherDate;
            string[] values = { val1, val2 };

            Events filteredList = Dispenser.SearchEvents(newEvents,field, op,  values);
            Utils.AssertAreEqual(filteredList, expectedList);
        }
Пример #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;
 }