コード例 #1
0
ファイル: ArrayFiltersTests.cs プロジェクト: twgraham/fluid
        public void Where()
        {
            var input = new ArrayValue(new[] {
                new ObjectValue(new { Title = "a", Pinned = true }),
                new ObjectValue(new { Title = "b", Pinned = false }),
                new ObjectValue(new { Title = "c", Pinned = true })
            });

            var context = new TemplateContext();

            context.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());

            var arguments1 = new FilterArguments().Add(new StringValue("Pinned"));

            var result1 = ArrayFilters.Where(input, arguments1, context);

            Assert.Equal(2, result1.Enumerate().Count());

            var arguments2 = new FilterArguments()
                             .Add(new StringValue("Pinned"))
                             .Add(BooleanValue.Create(false))
            ;

            var result2 = ArrayFilters.Where(input, arguments2, context);

            Assert.Single(result2.Enumerate());

            var arguments3 = new FilterArguments()
                             .Add(new StringValue("Title"))
                             .Add(new StringValue("c"));

            var result3 = ArrayFilters.Where(input, arguments3, context);

            Assert.Single(result3.Enumerate());
        }
コード例 #2
0
ファイル: ArrayFiltersTests.cs プロジェクト: twgraham/fluid
        public void WhereShouldNotThrow()
        {
            var input = new ArrayValue(new[] {
                new ObjectValue(new { Title = "a", Pinned = true }),
                new ObjectValue(new { Title = "b", Pinned = false }),
                new ObjectValue(new { Title = "c", Pinned = true })
            });

            var context = new TemplateContext();

            context.MemberAccessStrategy.Register(new { Title = "a", Pinned = true }.GetType());

            var arguments1 = new FilterArguments().Add(new StringValue("a.b.c"));

            var result1 = ArrayFilters.Where(input, arguments1, context);

            Assert.Empty(result1.Enumerate());
        }