Ejemplo n.º 1
0
        public void ShouldGetListWhenListAllWithFilterInfoAndNoOrderInfo()
        {
            var users  = CreateUsersWithAddress();
            var actual = users.ListAll(FilterInfo.CreateItem("Name", Operator.Contains, "a"), null, null);

            actual.Should().BeEquivalentTo(users.Where(p => (p.Name != null && p.Name.Contains("a"))).ToList());
        }
        public void ShouldGetExpectedResultWhenFilterSingleItem(string fieldName, FilterType filterType, object value, string expectedIds)
        {
            var filter = FilterInfo.CreateItem(fieldName, filterType, value);
            var ids    = CreateTestUsers().WhereCondition(filter)
                         .Select(p => p.Id);

            Assert.AreEqual(expectedIds, string.Join(",", ids));
        }
Ejemplo n.º 3
0
        public void ShouldSupportFilterTypeExists()
        {
            var datas  = CreateUsersWithAddress();
            var filter = FilterInfo.CreateItem("Addresses", FilterType.Exists, FilterInfo.CreateItem("City", FilterType.Equals, "xian"));
            var ids    = datas.WhereCondition(filter).Select(p => p.Id);

            Assert.AreEqual("001,002,004", string.Join(",", ids));
        }
Ejemplo n.º 4
0
        public void ShouldGetListWhenListAllWithFilterInfoAndOrderInfo()
        {
            var users  = CreateUsersWithAddress();
            var actual = users.ListAll(FilterInfo.CreateItem("Name", FilterType.Contains, "a"),
                                       OrderInfo.Create("Name", OrderType.Desc));

            actual.Should().BeEquivalentTo(users.Where(p => (p.Name != null && p.Name.Contains("a")))
                                           .OrderByDescending(p => p.Name).ToList());
        }
Ejemplo n.º 5
0
        public void ShouldAppendItemsWhenAndAlsoAndGivenOpTypeIsAndItemsAndOtherOpTypeIsSingleItem()
        {
            var filter = FilterInfo.CreateItem("Age", FilterType.GreaterThan, 1)
                         .AndAlso("Name", FilterType.StartsWith, "Zhang");

            Assert.AreEqual(OpType.AndItems, filter.OpType);
            Assert.AreEqual(2, filter.Items.Count);
            filter.AndAlso(new FilterInfo("Id", FilterType.Equals, "001"));
            Assert.AreEqual(OpType.AndItems, filter.OpType);
            Assert.AreEqual(3, filter.Items.Count);
        }
Ejemplo n.º 6
0
        public void ShouldAppendItemsWhenAndAlsoAndGivenOpTypeIsAndItemsAndOtherOpTypeIsAndItems()
        {
            var filter = FilterInfo.CreateItem("Age", FilterType.GreaterThan, 1)
                         .AndAlso("Name", FilterType.StartsWith, "Zhang");

            Assert.AreEqual(OpType.AndItems, filter.OpType);
            Assert.AreEqual(2, filter.Items.Count);
            var otherAndItems = FilterInfo.CreateAnd(
                new FilterInfo("Id", FilterType.StartsWith, "0"),
                new FilterInfo("Tel", FilterType.Contains, "135"));

            filter.AndAlso(otherAndItems);
            Assert.AreEqual(OpType.AndItems, filter.OpType);
            Assert.AreEqual(4, filter.Items.Count);
        }
Ejemplo n.º 7
0
        public void ShouldCreateNewOrItemsFilterWhenOrElseAndGivenOpTypeIsAndItemsAndOtherTypeIsSignleItem()
        {
            var filter = FilterInfo.CreateItem("Age", FilterType.GreaterThan, 1)
                         .AndAlso("Name", FilterType.StartsWith, "Zhang");

            Assert.AreEqual(OpType.AndItems, filter.OpType);
            Assert.AreEqual(2, filter.Items.Count);
            var newfilter = filter.OrElse(new FilterInfo("Id", FilterType.Equals, "001"));

            Assert.AreEqual(OpType.OrItems, newfilter.OpType);
            Assert.AreEqual(2, newfilter.Items.Count);


            Assert.AreEqual(filter, newfilter.Items.First());
            Assert.AreEqual(OpType.SingleItem, newfilter.Items.Last().OpType);
        }
        public void ShouldThrowFilterInfoExpressionExceptionWhenFilterSingleItemAndWithInvalidArguments(string fieldName, FilterType filterType, object value)
        {
            var filter = FilterInfo.CreateItem(fieldName, filterType, value);

            CreateTestUsers().WhereCondition(filter).ToList();
        }