44using Microsoft . Extensions . DependencyInjection ;
55using SixLabors . ImageSharp . Web . Caching ;
66using SixLabors . ImageSharp . Web . Commands ;
7+ using SixLabors . ImageSharp . Web . Commands . Converters ;
78using SixLabors . ImageSharp . Web . DependencyInjection ;
89using SixLabors . ImageSharp . Web . Processors ;
910using SixLabors . ImageSharp . Web . Providers ;
@@ -27,6 +28,53 @@ public void DefaultServicesAreRegistered()
2728 Assert . Contains ( services , x => x . ServiceType == typeof ( IImageWebProcessor ) && x . ImplementationType == typeof ( ResizeWebProcessor ) ) ;
2829 Assert . Contains ( services , x => x . ServiceType == typeof ( IImageWebProcessor ) && x . ImplementationType == typeof ( FormatWebProcessor ) ) ;
2930 Assert . Contains ( services , x => x . ServiceType == typeof ( IImageWebProcessor ) && x . ImplementationType == typeof ( BackgroundColorWebProcessor ) ) ;
31+ Assert . Contains ( services , x => x . ServiceType == typeof ( CommandParser ) ) ;
32+
33+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < sbyte > ) ) ;
34+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < byte > ) ) ;
35+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < short > ) ) ;
36+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < ushort > ) ) ;
37+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < int > ) ) ;
38+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < uint > ) ) ;
39+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < long > ) ) ;
40+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( IntegralNumberConverter < ulong > ) ) ;
41+
42+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( SimpleCommandConverter < decimal > ) ) ;
43+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( SimpleCommandConverter < float > ) ) ;
44+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( SimpleCommandConverter < double > ) ) ;
45+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( SimpleCommandConverter < string > ) ) ;
46+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( SimpleCommandConverter < bool > ) ) ;
47+
48+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < sbyte > ) ) ;
49+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < byte > ) ) ;
50+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < short > ) ) ;
51+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < ushort > ) ) ;
52+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < int > ) ) ;
53+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < uint > ) ) ;
54+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < long > ) ) ;
55+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < ulong > ) ) ;
56+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < decimal > ) ) ;
57+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < float > ) ) ;
58+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < double > ) ) ;
59+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < string > ) ) ;
60+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ArrayConverter < bool > ) ) ;
61+
62+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < sbyte > ) ) ;
63+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < byte > ) ) ;
64+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < short > ) ) ;
65+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < ushort > ) ) ;
66+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < int > ) ) ;
67+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < uint > ) ) ;
68+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < long > ) ) ;
69+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < ulong > ) ) ;
70+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < decimal > ) ) ;
71+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < float > ) ) ;
72+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < double > ) ) ;
73+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < string > ) ) ;
74+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ListConverter < bool > ) ) ;
75+
76+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( ColorConverter ) ) ;
77+ Assert . Contains ( services , x => x . ServiceType == typeof ( ICommandConverter ) && x . ImplementationType == typeof ( EnumConverter ) ) ;
3078 }
3179
3280 [ Fact ]
@@ -156,5 +204,69 @@ public void CanAddRemoveAllFactoryImageProcessors()
156204
157205 Assert . DoesNotContain ( services , x => x . ImplementationFactory ? . Method . ReturnType == typeof ( MockWebProcessor ) ) ;
158206 }
207+
208+ [ Fact ]
209+ public void CanAddRemoveCommandConverters ( )
210+ {
211+ var services = new ServiceCollection ( ) ;
212+
213+ IImageSharpBuilder builder = services . AddImageSharp ( )
214+ . AddConverter < MockCommandConverter > ( ) ;
215+
216+ Assert . Contains ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
217+
218+ builder . RemoveConverter < MockCommandConverter > ( ) ;
219+
220+ Assert . DoesNotContain ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
221+ }
222+
223+ [ Fact ]
224+ public void CanAddRemoveFactoryCommandConverters ( )
225+ {
226+ var services = new ServiceCollection ( ) ;
227+
228+ IImageSharpBuilder builder = services . AddImageSharp ( )
229+ . AddConverter ( _ => new MockCommandConverter ( ) ) ;
230+
231+ Assert . DoesNotContain ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
232+
233+ Assert . Contains ( services , x => x . ImplementationFactory ? . Method . ReturnType == typeof ( MockCommandConverter ) ) ;
234+
235+ builder . RemoveConverter < MockCommandConverter > ( ) ;
236+
237+ Assert . DoesNotContain ( services , x => x . ImplementationFactory ? . Method . ReturnType == typeof ( MockCommandConverter ) ) ;
238+ }
239+
240+ [ Fact ]
241+ public void CanAddRemoveAllCommandConverters ( )
242+ {
243+ var services = new ServiceCollection ( ) ;
244+
245+ IImageSharpBuilder builder = services . AddImageSharp ( )
246+ . AddConverter < MockCommandConverter > ( ) ;
247+
248+ Assert . Contains ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
249+
250+ builder . ClearConverters ( ) ;
251+
252+ Assert . DoesNotContain ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
253+ }
254+
255+ [ Fact ]
256+ public void CanAddRemoveAllFactoryCommandConverters ( )
257+ {
258+ var services = new ServiceCollection ( ) ;
259+
260+ IImageSharpBuilder builder = services . AddImageSharp ( )
261+ . AddConverter ( _ => new MockCommandConverter ( ) ) ;
262+
263+ Assert . DoesNotContain ( services , x => x . ImplementationType == typeof ( MockCommandConverter ) ) ;
264+
265+ Assert . Contains ( services , x => x . ImplementationFactory ? . Method . ReturnType == typeof ( MockCommandConverter ) ) ;
266+
267+ builder . ClearConverters ( ) ;
268+
269+ Assert . DoesNotContain ( services , x => x . ImplementationFactory ? . Method . ReturnType == typeof ( MockCommandConverter ) ) ;
270+ }
159271 }
160272}
0 commit comments