Esempio n. 1
0
        public void TestMethod_Get_Region_By_Predicate()
        {
            var repositoryMock = new Mock <IEmployeeRepository>();

            repositoryMock.Setup(x => x.GetAll()).Returns(_employees);
            var allRegion = new RepositoryTest(repositoryMock.Object);

            string[] keywords = new string[2] {
                "o", "a"
            };

            Expression <Func <Employee, bool> > predicate = PredicateBuilder.False <Employee>();
            ParameterExpression it = Expression.Parameter(typeof(string), "fn");

            string str  = String.Format("it.{0}.Contains(@0)", "FirstName");
            string str1 = String.Format("it.{0}.Contains(@0)", "LastName");

            var e  = DynamicExpression.ParseLambda <Employee, bool>(str, "a");
            var e1 = DynamicExpression.ParseLambda <Employee, bool>(str1, "a");
            Expression <Func <Employee, bool> > predicate1 = e.And(e1);
            //foreach (string keyword in keywords)
            //{
            //    string temp = keyword;
            //    predicate = predicate.Or(p => p.LastName.Contains(temp));
            //}
            //IEnumerable<T> FindBy(System.Linq.Expressions.Expression<Func<T, bool>> predicate)
            IEnumerable <Employee> listRegion = allRegion.FindBy(predicate1);
            int count = listRegion.Count();

            //Assert
            Assert.IsNotNull(listRegion); // Test if null
            Assert.IsInstanceOfType(typeof(IEnumerable <Employee>), listRegion);
            Assert.AreEqual(1, count);
        }
Esempio n. 2
0
        public void TestByID()
        {
            var repositoryMock = new Mock <IEmployeeRepository>();

            //Setup mock that will return Region list when called:
            repositoryMock.Setup(x => x.GetAll()).Returns(_employees);
            var allEmployee = new RepositoryTest(repositoryMock.Object);
            //public Region GetById(int id)
            var employee = allEmployee.GetById(1);

            //Assert
            Assert.IsNotNull(employee); // Test if null
#pragma warning disable 612
            Assert.IsInstanceOfType(typeof(Employee), employee);
#pragma warning restore 612
        }