@@ -12,57 +12,41 @@ public class ClipboardServiceTest : BootstrapBlazorTestBase
1212 [ Fact ]
1313 public async Task Clipboard_Ok ( )
1414 {
15- var cut = Context . RenderComponent < MockClipboard > ( ) ;
16- await cut . Instance . Copy ( null , ( ) => Task . CompletedTask ) ;
17- await cut . Instance . Copy ( "Test" , ( ) => Task . CompletedTask ) ;
15+ var service = Context . Services . GetRequiredService < ClipboardService > ( ) ;
16+ await service . Copy ( null , ( ) => Task . CompletedTask ) ;
17+ await service . Copy ( "Test" , ( ) => Task . CompletedTask ) ;
1818 }
1919
2020 [ Fact ]
2121 public async Task GetText ( )
2222 {
2323 Context . JSInterop . Setup < string ? > ( "getTextFromClipboard" ) . SetResult ( "test123" ) ;
24- var cut = Context . RenderComponent < MockClipboard > ( ) ;
24+ var service = Context . Services . GetRequiredService < ClipboardService > ( ) ;
2525
26- var text = await cut . Instance . GetText ( ) ;
26+ var text = await service . GetText ( ) ;
2727 Assert . Equal ( "test123" , text ) ;
28- await cut . Instance . GetText ( ) ;
28+ await service . GetText ( ) ;
2929 }
3030
3131 [ Fact ]
3232 public async Task Get ( )
3333 {
3434 Context . JSInterop . Setup < List < ClipboardItem > ? > ( "getAllClipboardContents" ) . SetResult ( [ new ( ) { Data = [ 0x31 , 0x32 , 0x33 ] , MimeType = "text/text" } ] ) ;
35- var cut = Context . RenderComponent < MockClipboard > ( ) ;
36- var items = await cut . Instance . Get ( ) ;
37- Assert . NotNull ( items ) ;
35+ var service = Context . Services . GetRequiredService < ClipboardService > ( ) ;
36+ var items = await service . Get ( ) ;
3837 var item = items [ 0 ] ;
3938
4039 Assert . Equal ( "123" , item . Text ) ;
4140 Assert . Equal ( "text/text" , item . MimeType ) ;
4241
4342 Context . JSInterop . Setup < List < ClipboardItem > ? > ( "getAllClipboardContents" ) . SetResult ( [ new ( ) { Data = [ 0x31 , 0x32 , 0x33 ] } ] ) ;
44- items = await cut . Instance . Get ( ) ;
45- Assert . NotNull ( items ) ;
43+ items = await service . Get ( ) ;
4644 item = items [ 0 ] ;
4745 Assert . Empty ( item . Text ) ;
4846
4947 Context . JSInterop . Setup < List < ClipboardItem > ? > ( "getAllClipboardContents" ) . SetResult ( [ new ( ) ] ) ;
50- items = await cut . Instance . Get ( ) ;
51- Assert . NotNull ( items ) ;
48+ items = await service . Get ( ) ;
5249 item = items [ 0 ] ;
5350 Assert . Empty ( item . Text ) ;
5451 }
55-
56- private class MockClipboard : ComponentBase
57- {
58- [ Inject ]
59- [ NotNull ]
60- public ClipboardService ? ClipboardService { get ; set ; }
61-
62- public Task Copy ( string ? text , Func < Task > callback ) => ClipboardService . Copy ( text , callback , CancellationToken . None ) ;
63-
64- public Task < string ? > GetText ( ) => ClipboardService . GetText ( CancellationToken . None ) ;
65-
66- public Task < List < ClipboardItem > ? > Get ( ) => ClipboardService . Get ( CancellationToken . None ) ;
67- }
6852}
0 commit comments