1- // Copyright (c) 2018 Inventory Innovations, Inc. - build by Jon P Smith ( GitHub JonPSmith)
2- // Licensed under MIT licence . See License.txt in the project root for license information.
1+ // Copyright (c) 2020 Jon P Smith, GitHub: JonPSmith, web: http://www.thereformedprogrammer.net/
2+ // Licensed under MIT license . See License.txt in the project root for license information.
33
44using System ;
55using System . Collections . Generic ;
@@ -32,6 +32,8 @@ public void TestRegisterAssemblyPublicNonGenericClasses()
3232 typeof ( TestAutoRegisterDiCallingAssembly ) ,
3333 typeof ( TestAutoRegisterDiDifferentAssembly ) ,
3434 typeof ( TestTypeExtensions ) ,
35+ typeof ( ClassWithJustIDisposable ) ,
36+ typeof ( ClassWithJustISerializable ) ,
3537 typeof ( LocalScopeService ) , typeof ( LocalService ) ,
3638 typeof ( LocalSingletonService ) , typeof ( LocalTransientService ) ,
3739 } ) ;
@@ -48,9 +50,11 @@ public void TestAsPublicImplementedInterfacesMyService()
4850 . AsPublicImplementedInterfaces ( ) ;
4951
5052 //VERIFY
51- service . Count . ShouldEqual ( 4 ) ;
53+ service . Count . ShouldEqual ( 5 ) ;
5254 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalService ) , ServiceLifetime . Transient ) ,
5355 new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
56+ service . Contains ( new ServiceDescriptor ( typeof ( IAnotherInterface ) , typeof ( LocalService ) , ServiceLifetime . Transient ) ,
57+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
5458 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalSingletonService ) , ServiceLifetime . Singleton ) ,
5559 new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
5660 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalTransientService ) , ServiceLifetime . Transient ) ,
@@ -70,9 +74,11 @@ public void TestAsPublicImplementedInterfacesMyServiceSetLifetime()
7074 . AsPublicImplementedInterfaces ( ServiceLifetime . Singleton ) ;
7175
7276 //VERIFY
73- service . Count . ShouldEqual ( 4 ) ;
77+ service . Count . ShouldEqual ( 5 ) ;
7478 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalService ) , ServiceLifetime . Singleton ) ,
7579 new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
80+ service . Contains ( new ServiceDescriptor ( typeof ( IAnotherInterface ) , typeof ( LocalService ) , ServiceLifetime . Singleton ) ,
81+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
7682 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalSingletonService ) , ServiceLifetime . Singleton ) ,
7783 new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
7884 service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalTransientService ) , ServiceLifetime . Transient ) ,
@@ -82,18 +88,65 @@ public void TestAsPublicImplementedInterfacesMyServiceSetLifetime()
8288 }
8389
8490 [ Fact ]
85- public void TestWhere ( )
91+ public void TestSingleWhere ( )
92+ {
93+ //SETUP
94+ var service = new ServiceCollection ( ) ;
95+
96+ //ATTEMPT
97+ service . RegisterAssemblyPublicNonGenericClasses ( )
98+ . Where ( x => x . Name == nameof ( LocalService ) )
99+ . AsPublicImplementedInterfaces ( ) ;
100+
101+ //VERIFY
102+ service . Count . ShouldEqual ( 2 ) ;
103+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalService ) , ServiceLifetime . Transient ) ,
104+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
105+ service . Contains ( new ServiceDescriptor ( typeof ( IAnotherInterface ) , typeof ( LocalService ) , ServiceLifetime . Transient ) ,
106+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
107+ }
108+
109+ [ Fact ]
110+ public void TestMultipleWhere ( )
111+ {
112+ //SETUP
113+ var service = new ServiceCollection ( ) ;
114+
115+ //ATTEMPT
116+ service . RegisterAssemblyPublicNonGenericClasses ( )
117+ . Where ( x => x . Name != nameof ( LocalService ) )
118+ . Where ( x => x . Name != nameof ( LocalScopeService ) )
119+ . AsPublicImplementedInterfaces ( ) ;
120+
121+ //VERIFY
122+ service . Count . ShouldEqual ( 2 ) ;
123+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalSingletonService ) , ServiceLifetime . Singleton ) ,
124+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
125+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalTransientService ) , ServiceLifetime . Transient ) ,
126+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
127+ }
128+
129+ [ Fact ]
130+ public void TestSingleIgnoreThisInterface ( )
86131 {
87132 //SETUP
88133 var service = new ServiceCollection ( ) ;
89134
90135 //ATTEMPT
91136 service . RegisterAssemblyPublicNonGenericClasses ( )
92- . Where ( x => x . Name == nameof ( MyService ) )
137+ . IgnoreThisInterface < IAnotherInterface > ( )
93138 . AsPublicImplementedInterfaces ( ) ;
94139
95140 //VERIFY
96- service . Count . ShouldEqual ( 0 ) ;
141+ service . Count . ShouldEqual ( 4 ) ;
142+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalService ) , ServiceLifetime . Transient ) ,
143+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
144+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalSingletonService ) , ServiceLifetime . Singleton ) ,
145+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
146+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalTransientService ) , ServiceLifetime . Transient ) ,
147+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
148+ service . Contains ( new ServiceDescriptor ( typeof ( ILocalService ) , typeof ( LocalScopeService ) , ServiceLifetime . Scoped ) ,
149+ new CheckDescriptor ( ) ) . ShouldBeTrue ( ) ;
97150 }
98151
99152 //-------------------------------------------------------------------------
0 commit comments