11namespace TestingContextCore . Implementation . Registrations
22{
33 using System ;
4+ using System . Collections . Generic ;
5+ using System . Linq ;
46 using System . Linq . Expressions ;
57 using TestingContextCore . Implementation . Dependencies ;
68 using TestingContextCore . Implementation . Filters ;
9+ using TestingContextCore . Implementation . Providers ;
10+ using TestingContextCore . Implementation . ResolutionContext ;
711 using TestingContextCore . Interfaces ;
12+ using static Definition ;
813
9- internal class Registration2 < T1 , T2 > : IFor < T1 , T2 >
14+ internal class Registration2 < T1 , T2 > : IFor < T1 , T2 >
1015 {
1116 private readonly IDependency < T1 > dependency1 ;
1217 private readonly IDependency < T2 > dependency2 ;
@@ -23,5 +28,51 @@ public void IsTrue(Expression<Func<T1, T2, bool>> filter, string key = null)
2328 {
2429 store . RegisterFilter ( new Filter2 < T1 , T2 > ( dependency1 , dependency2 , filter , key ) , key ) ;
2530 }
31+
32+ public void Exists < T3 > ( string key , Func < T1 , T2 , IEnumerable < T3 > > srcFunc )
33+ {
34+ CreateFilter < T3 > ( key , x => x . Any ( y => y . MeetsConditions ) ) ;
35+ CreateProvider ( key , srcFunc ) ;
36+ }
37+
38+ public void DoesNotExist < T3 > ( string key , Func < T1 , T2 , IEnumerable < T3 > > srcFunc )
39+ {
40+ CreateFilter < T3 > ( key , x => ! x . Any ( y => y . MeetsConditions ) ) ;
41+ CreateProvider ( key , srcFunc ) ;
42+ }
43+
44+ public void Each < T3 > ( string key , Func < T1 , T2 , IEnumerable < T3 > > srcFunc )
45+ {
46+ CreateFilter < T3 > ( key , x => x . All ( y => y . MeetsConditions ) ) ;
47+ CreateProvider ( key , srcFunc ) ;
48+ }
49+
50+ public void Satisfies < T3 > ( string key , Func < T1 , T2 , T3 > srcFunc )
51+ {
52+ Exists ( key , ( x , y ) =>
53+ {
54+ var item = srcFunc ( x , y ) ;
55+ return item == null ? Enumerable . Empty < T3 > ( ) : new [ ] { item } ;
56+ } ) ;
57+ }
58+
59+ public void DoesNotSatisfy < T3 > ( string key , Func < T1 , T2 , T3 > srcFunc )
60+ {
61+ DoesNotExist ( key , ( x , y ) =>
62+ {
63+ var item = srcFunc ( x , y ) ;
64+ return item == null ? Enumerable . Empty < T3 > ( ) : new [ ] { item } ;
65+ } ) ;
66+ }
67+
68+ private void CreateFilter < T3 > ( string key , Expression < Func < IEnumerable < IResolutionContext > , bool > > func )
69+ {
70+ store . RegisterCollectionValidityFilter ( new CollectionValidityFilter ( func , Define < T3 > ( key ) ) ) ;
71+ }
72+
73+ private void CreateProvider < T3 > ( string key , Func < T1 , T2 , IEnumerable < T3 > > srcFunc )
74+ {
75+ store . RegisterProvider ( Define < T2 > ( key ) , new Provider2 < T1 , T2 , T3 > ( dependency1 , dependency2 , srcFunc ) ) ;
76+ }
2677 }
2778}
0 commit comments