|
1 | | -using Filters = GraphQL.EntityFramework.Filters<T>; |
2 | | - |
3 | | -public class GlobalFiltersTests |
| 1 | +public class GlobalFiltersTests |
4 | 2 | { |
5 | 3 | [Fact] |
6 | 4 | public async Task Simple() |
7 | 5 | { |
8 | | - var filters = new Filters(); |
9 | | - filters.Add<Target>((_, _, target) => target.Property != "Ignore"); |
10 | | - Assert.True(await filters.ShouldInclude(new(), null, new Target())); |
11 | | - Assert.False(await filters.ShouldInclude<object>(new(), null, null)); |
12 | | - Assert.True(await filters.ShouldInclude(new(), null, new Target {Property = "Include"})); |
13 | | - Assert.False(await filters.ShouldInclude(new(), null, new Target {Property = "Ignore"})); |
14 | | - |
15 | | - filters.Add<BaseTarget>((_, _, target) => target.Property != "Ignore"); |
16 | | - Assert.True(await filters.ShouldInclude(new(), null, new ChildTarget())); |
17 | | - Assert.True(await filters.ShouldInclude(new(), null, new ChildTarget {Property = "Include"})); |
18 | | - Assert.False(await filters.ShouldInclude(new(), null, new ChildTarget {Property = "Ignore"})); |
19 | | - |
20 | | - filters.Add<ITarget>((_, _, target) => target.Property != "Ignore"); |
21 | | - Assert.True(await filters.ShouldInclude(new(), null, new ImplementationTarget())); |
22 | | - Assert.True(await filters.ShouldInclude(new(), null, new ImplementationTarget { Property = "Include"})); |
23 | | - Assert.False(await filters.ShouldInclude(new(), null, new ImplementationTarget { Property = "Ignore" })); |
24 | | - |
25 | | - Assert.True(await filters.ShouldInclude(new(), null, new NonTarget { Property = "Foo" })); |
| 6 | + var filters = new Filters<MyContext>(); |
| 7 | + filters.Add<Target>((_, _, _, target) => target.Property != "Ignore"); |
| 8 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new Target())); |
| 9 | + Assert.False(await filters.ShouldInclude<object>(new(), new(), null, null)); |
| 10 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new Target {Property = "Include"})); |
| 11 | + Assert.False(await filters.ShouldInclude(new(), new(), null, new Target {Property = "Ignore"})); |
| 12 | + |
| 13 | + filters.Add<BaseTarget>((_, _, _, target) => target.Property != "Ignore"); |
| 14 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new ChildTarget())); |
| 15 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new ChildTarget {Property = "Include"})); |
| 16 | + Assert.False(await filters.ShouldInclude(new(), new(), null, new ChildTarget {Property = "Ignore"})); |
| 17 | + |
| 18 | + filters.Add<ITarget>((_, _, _, target) => target.Property != "Ignore"); |
| 19 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new ImplementationTarget())); |
| 20 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new ImplementationTarget { Property = "Include"})); |
| 21 | + Assert.False(await filters.ShouldInclude(new(), new(), null, new ImplementationTarget { Property = "Ignore" })); |
| 22 | + |
| 23 | + Assert.True(await filters.ShouldInclude(new(), new(), null, new NonTarget { Property = "Foo" })); |
26 | 24 | } |
27 | 25 |
|
| 26 | + public class MyContext : DbContext; |
| 27 | + |
28 | 28 | public class NonTarget |
29 | 29 | { |
30 | 30 | public string? Property { get; set; } |
|
0 commit comments