Example #1
0
        public void EntityFilter_EmptyFilter_ReturnsOriginalList()
        {
            // Create source entity list
            var accounts = GetAccountList();

            // Define queries to be appled on source
            var queryExpression = new QueryExpression();

            // Apply filters on entity list
            IEntityFilter <Account> entityFilter = new EntityFilter <Account>();
            var filteredResults = entityFilter.FilterBy(accounts, queryExpression);

            Assert.AreEqual(accounts.Count, filteredResults.Count);
        }
Example #2
0
        public void EntityFilter_FilterByName_ReturnsFilteredList()
        {
            // Create source entity list
            var accounts = GetAccountList();

            // Define queries to be appled on source
            var queryExpression = new QueryExpression();

            queryExpression.Criteria.AddCondition("name", ConditionOperator.EndsWith, "LLC");

            // Apply filters on entity list
            IEntityFilter <Account> entityFilter = new EntityFilter <Account>();
            var filteredResults = entityFilter.FilterBy(accounts, queryExpression);

            Assert.IsTrue(
                filteredResults.All(a =>
                                    a.name.EndsWith("LLC")
                                    )
                );
        }
Example #3
0
        public void EntityFilter_FilterByOptionSet_ReturnsFilteredList()
        {
            // Create source entity list
            var accounts = GetAccountList();

            // Define queries to be appled on source
            var queryExpression = new QueryExpression();

            queryExpression.Criteria.AddCondition("preferredcontactmethodcode", ConditionOperator.In, Account_PreferredContactMethodCode.Email, Account_PreferredContactMethodCode.Phone);

            // Apply filters on entity list
            IEntityFilter <Account> entityFilter = new EntityFilter <Account>();
            var filteredResults = entityFilter.FilterBy(accounts, queryExpression);

            Assert.IsTrue(
                filteredResults.All(a =>
                                    a.preferredcontactmethodcode == Account_PreferredContactMethodCode.Email ||
                                    a.preferredcontactmethodcode == Account_PreferredContactMethodCode.Phone
                                    )
                );
        }
Example #4
0
        public void EntityFilter_FilterByComplex_ReturnsFilteredList()
        {
            /*
             * The test creates a list of accounts and filters them where:
             *  Name ends with LLC and
             *      Can be faxed and has fax number, or
             *      Can be phoned and has phone number, or
             *      Can be e-mailed and has e-mail.
             */

            // Create source entity list
            var accounts = GetAccountList();

            // Define queries to be appled on source
            var queryExpression = new QueryExpression();

            queryExpression.Criteria.AddCondition("name", ConditionOperator.EndsWith, "LLC");
            queryExpression.Criteria.FilterOperator = LogicalOperator.And;

            // Marketing filter to find accounts where any kind of contact type is allowed.
            var marketingAllowed = new FilterExpression(LogicalOperator.Or);

            // Can be faxed and has fax number
            var canBeFaxed = new FilterExpression(LogicalOperator.And);

            canBeFaxed.AddCondition("donotfax", ConditionOperator.Equal, false);
            canBeFaxed.AddCondition("fax", ConditionOperator.NotNull);

            // Can be called and has phone number
            var canBeCalled = new FilterExpression(LogicalOperator.And);

            canBeCalled.AddCondition("donotphone", ConditionOperator.Equal, false);
            canBeCalled.AddCondition("telephone1", ConditionOperator.NotNull);

            // Can be e-mailed and has e-mail
            var canBeEmailed = new FilterExpression(LogicalOperator.And);

            canBeEmailed.AddCondition("donotemail", ConditionOperator.Equal, false);
            canBeEmailed.AddCondition("emailaddress1", ConditionOperator.NotNull);

            marketingAllowed.AddFilter(canBeFaxed);
            marketingAllowed.AddFilter(canBeCalled);
            marketingAllowed.AddFilter(canBeEmailed);

            queryExpression.Criteria.AddFilter(marketingAllowed);

            // Apply filters on entity list
            IEntityFilter <Account> entityFilter = new EntityFilter <Account>();
            var filteredResults = entityFilter.FilterBy(accounts, queryExpression);

            Assert.IsTrue(
                filteredResults.All(a =>
                                    a.name.Contains("LLC") &&
                                    (
                                        (a.donotfax == false && !String.IsNullOrWhiteSpace(a.fax)) ||
                                        (a.donotemail == false && !String.IsNullOrWhiteSpace(a.telephone1)) ||
                                        (a.donotphone == false && !String.IsNullOrWhiteSpace(a.emailaddress1))
                                    )
                                    )
                );
        }