Пример #1
0
        public void when_requesting_equal_text_returns_correct_sql_string()
        {
            var filter = new StringTextFilter("notes", "", StringTextFilterMode.Equal);
            var result = filter.GetMySqlString();

            Assert.That(result, Is.EqualTo("notes = ''"));
        }
Пример #2
0
        public void when_requesting_contains_text_returns_correct_sql_string()
        {
            var filter = new StringTextFilter("notes", "a", StringTextFilterMode.Contains);
            var result = filter.GetMySqlString();

            Assert.That(result, Is.EqualTo("notes LIKE '%a%'"));
        }
Пример #3
0
        public void when_requesting_exact_string_returns_correct_sql_string()
        {
            var filter = new StringTextFilter("email", "*****@*****.**", StringTextFilterMode.Equal);
            var result = filter.GetMySqlString();

            Assert.That(result, Is.EqualTo("email = '*****@*****.**'"));
        }
Пример #4
0
        public void when_requesting_ending_with_string_returns_correct_sql_string()
        {
            var filter = new StringTextFilter("email", ".com", StringTextFilterMode.Ends);
            var result = filter.GetMySqlString();

            Assert.That(result, Is.EqualTo("email LIKE '%.com'"));
        }
Пример #5
0
        //Dovrò fare dei metodi per gestire in qualche modo tutte le combo dei filtri
        public static ISqlFilter SqlAllOrCompositeFilter()
        {
            Console.WriteLine(" Inserisci il testo che vuoi cercare:");
            var filterValue = Console.ReadLine();

            var email             = new StringTextFilter("email", filterValue.Trim(), StringTextFilterMode.Contains);
            var phone             = new StringTextFilter("phone", filterValue.Trim(), StringTextFilterMode.Contains);
            var name              = new StringTextFilter("name", filterValue.Trim(), StringTextFilterMode.Contains);
            var notes             = new StringTextFilter("notes", filterValue.Trim(), StringTextFilterMode.Contains);
            var orCompositeFilter = new OrCompositeFilter(email, phone, name, notes);

            return(orCompositeFilter);
        }
Пример #6
0
        public static ISqlFilter SqlTextStringFilter(UserFilterProviderColumn columnFilter)
        {
            string column;

            switch (columnFilter)
            {
            case UserFilterProviderColumn.Email:
                Console.WriteLine(" Inserisci l'email o parte di essa:");
                column = "email";
                break;

            case UserFilterProviderColumn.Phone:
                Console.WriteLine(" Inserisci il telefono o parte di esso:");
                column = "phone";
                break;

            case UserFilterProviderColumn.Name:
                Console.WriteLine(" Inserisci il nome o parte di esso:");
                column = "name";
                break;

            case UserFilterProviderColumn.Notes:
                Console.WriteLine(" Inserisci le note o parte di esse:");
                column = "notes";
                break;

            default: throw new Exception();
            }


            var filterValue           = Console.ReadLine();
            StringTextFilterMode?mode = null; //non è più un enum ma un oggetto che ha un enum ma che può essere nullo

            while (mode == null)
            {
                Console.WriteLine("1. Contains");
                Console.WriteLine("2. Starts");
                Console.WriteLine("3. End");
                Console.WriteLine("4. Match esatto");
                var key = Console.ReadKey();
                switch (key.KeyChar)
                {
                case '1':
                    mode = StringTextFilterMode.Contains;
                    break;

                case '2':
                    mode = StringTextFilterMode.Starts;
                    break;

                case '3':
                    mode = StringTextFilterMode.Ends;
                    break;

                case '4':
                    mode = StringTextFilterMode.Equal;
                    break;
                }
            }

            var filter = new StringTextFilter(column, filterValue.Trim(), mode.Value);

            return(filter);
        }