Exemplo n.º 1
0
 public List<object> FindByName(string name, StringFields field)
 {
     //search method by string
     if (name == null)
         throw new System.Data.DataException("Bad Input!");
     List<object> result = itsDAL.ProductNameQuery(name, field).Cast<object>().ToList();
     return result;
 }
Exemplo n.º 2
0
        public List <object> FindByName(string name, StringFields field)
        {
            if (name == null)
            {
                throw new System.Data.DataException("Bad Input!");
            }
            List <object> result = itsDAL.EmployeeNameQuery(name, field).Cast <object>().ToList();

            return(result);
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            string fileName = Console.ReadLine();
            var    f        = int.Parse(Console.ReadLine());
            var    lines    = File.ReadAllLines(fileName);

            foreach (var e in StringFields.GetRightFields(lines, f))
            {
                Console.WriteLine(e);
            }
            Console.ReadKey();
        }
Exemplo n.º 4
0
        public void Test5()
        {
            var testText = new string[2];

            testText[0] = "acd\\'fgh\\\\\"k\'p\'l\"gdshn dsfb";
            testText[1] = "dsf\\\\\'sdh h\'tykfg dfhh";
            int f = 0;

            var fields = StringFields.GetRightFields(testText, f);

            Assert.AreEqual("acd\'fgh\\", fields[0]);
            Assert.AreEqual("dsf\\", fields[1]);
        }
Exemplo n.º 5
0
        public void Test4()
        {
            var testText = new string[2];

            testText[0] = "acd\'fgh\"k\'p\'l\"gdshn dsfb";
            testText[1] = "p\'l\"gdshn dsfb";
            int f = 1;

            var fields = StringFields.GetRightFields(testText, f);

            Assert.AreEqual("fgh\"k", fields[0]);
            Assert.AreEqual("l\"gdshn dsfb", fields[1]);
        }
Exemplo n.º 6
0
        //Filter by name for user
        public List <Backend.User> UserNameQuery(string name, StringFields field)
        {
            List <Backend.User> allUser = ReadFromFile(Elements.User).Cast <Backend.User>().ToList();
            List <Backend.User> filteredUser;

            if (allUser.ElementAtOrDefault(0) == null)
            {
                throw new InvalidDataException("There is nothing to find from.");
            }
            if (field != StringFields.username)
            {
                throw new System.Data.DataException("Bad Input!");
            }
            filteredUser = allUser.Where(n => n.UserName.Equals(name)).Cast <Backend.User>().ToList();
            return(filteredUser);
        }
Exemplo n.º 7
0
        //Filter by name for department
        public List <Backend.Department> DepartmentNameQuery(string name, StringFields field)
        {
            List <Backend.Department> allDepartment = ReadFromFile(Elements.Department).Cast <Backend.Department>().ToList();
            List <Backend.Department> filteredDepartment;

            if (allDepartment.ElementAtOrDefault(0) == null)
            {
                throw new InvalidDataException("There is nothing to find from.");
            }
            if (field != StringFields.name)
            {
                throw new System.Data.DataException("Bad Input!");
            }
            filteredDepartment = allDepartment.Where(n => n.Name.Equals(name)).Cast <Backend.Department>().ToList();
            return(filteredDepartment);
        }
Exemplo n.º 8
0
        public void Test3()
        {
            var testText = new string[4];

            testText[0] = "acd fgh \"k\'p\'l \" \"tyo\" gdshn dsfb";
            testText[1] = "if\'lk\'\'df\'";
            testText[2] = "lpdnfjkb a\'odfbfkbn";
            testText[3] = " ";
            int f = 2;

            var fields = StringFields.GetRightFields(testText, f);

            Assert.AreEqual("k\'p\'l ", fields[0]);
            Assert.AreEqual("df", fields[1]);
            Assert.AreEqual("odfbfkbn", fields[2]);
            Assert.AreEqual("null", fields[3]);
        }
Exemplo n.º 9
0
        public void Test2()
        {
            var testText = new string[4];

            testText[0] = "acd fgh \"k\'p\'l\" \"tyo\" gdshn dsfb";
            testText[1] = "\'\'";
            testText[2] = "lpdnfjkb \"odfbfkbn iflkmsdf";
            testText[3] = "";
            int f = 1;

            var fields = StringFields.GetRightFields(testText, f);

            Assert.AreEqual("fgh", fields[0]);
            Assert.AreEqual("null", fields[1]);
            Assert.AreEqual("odfbfkbn iflkmsdf", fields[2]);
            Assert.AreEqual("null", fields[3]);
        }
Exemplo n.º 10
0
        //Filter by name for Customer
        public List <Backend.Customer> CustomerNameQuery(string name, StringFields field)
        {
            List <Backend.Customer> allCustomer = ReadFromFile(Elements.Customer).Cast <Backend.Customer>().ToList();
            List <Backend.Customer> filteredCustomer;

            if (allCustomer.ElementAtOrDefault(0) == null)
            {
                throw new InvalidDataException("There is nothing to find from.");
            }
            if (field == StringFields.firstName)
            {
                filteredCustomer = allCustomer.Where(n => n.FirstName.Equals(name)).Cast <Backend.Customer>().ToList();
            }
            else if (field == StringFields.lastName)
            {
                filteredCustomer = allCustomer.Where(n => n.LastName.Equals(name)).Cast <Backend.Customer>().ToList();
            }
            else
            {
                throw new System.Data.DataException("Bad Input!");
            }
            return(filteredCustomer);
        }
Exemplo n.º 11
0
 public List <object> FindByName(string name, StringFields field)
 {
     throw new System.Data.DataException("transactions doesn't have names!");
 }
Exemplo n.º 12
0
        public void scalar_property_tests(
            int testnum,
            string field,
            string type,
            byte loop,
            float distance,
            char initial,
            char?initialN,
            bool done,
            string name,
            string decimalText,
            Weekday day,
            short gap,
            long bigNum,
            int laps,
            int?lapsN,
            string bornText,
            bool shouldThrow
            )
        {
            bool pass = false;

            Console.WriteLine(field);
            Console.WriteLine("------");

            var left = new StringFields()
            {
                Loop            = loop,
                Distance        = distance,
                Initial         = initial,
                InitialNullable = initialN,
                Done            = done,
                Name            = name,
                Amount          = decimal.Parse(decimalText),
                Day             = day,
                Gap             = gap,
                BigNum          = bigNum,
                Laps            = laps,
                LapsNullable    = lapsN,
                Born            = DateTime.Parse(bornText)
            };

            var right = new StringFields()
            {
                Loop            = 12,
                Distance        = 40.231F,
                Initial         = 'C',
                InitialNullable = 'C',
                Done            = true,
                Name            = "Fred",
                Amount          = 3.14M,
                Day             = Weekday.Friday,
                Gap             = 20230,
                BigNum          = 98765432154321,
                Laps            = 2,
                LapsNullable    = 2,
                Born            = new DateTime(2016, 10, 31, 18, 41, 24)
            };

            try
            {
                left.VerifySame(right);
                pass = !shouldThrow;
            }
            catch (VerifyException ae)
            {
                if (shouldThrow)
                {
                    StringAssert.Contains(field, ae.Message);
                    pass = true;
                }
                Console.WriteLine(ae.Message);
            }
            if (!pass)
            {
                if (shouldThrow)
                {
                    Assert.Fail("Expected CompareException, but was not thrown.");
                }
                else
                {
                    Assert.Fail("Expected comparison to pass, but exception was thrown.");
                }
            }
        }