コード例 #1
0
    static Filters BuildFilters()
    {
        var filters = new Filters();

        filters.Add <FilterParentEntity>((context, item) => item.Property != "Ignore");
        filters.Add <FilterChildEntity>((context, item) => item.Property != "Ignore");
        return(filters);
    }
コード例 #2
0
    public async Task Simple()
    {
        var filters = new Filters();

        filters.Add <Target>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(new object(), new Target()));
        Assert.False(await filters.ShouldInclude <object>(new object(), null));
        Assert.True(await filters.ShouldInclude(new object(), new Target {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(new object(), new Target {
            Property = "Ignore"
        }));

        filters.Add <BaseTarget>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(new object(), new ChildTarget()));
        Assert.True(await filters.ShouldInclude(new object(), new ChildTarget {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(new object(), new ChildTarget {
            Property = "Ignore"
        }));

        filters.Add <ITarget>((o, target) => target.Property != "Ignore");
        Assert.True(await filters.ShouldInclude(new object(), new ImplementationTarget()));
        Assert.True(await filters.ShouldInclude(new object(), new ImplementationTarget {
            Property = "Include"
        }));
        Assert.False(await filters.ShouldInclude(new object(), new ImplementationTarget {
            Property = "Ignore"
        }));

        Assert.True(await filters.ShouldInclude(new object(), new NonTarget {
            Property = "Foo"
        }));
    }