@@ -12,6 +12,7 @@ public class ToolStripKeyboardHandlingServiceTests
1212 private readonly Mock < IDesignerHost > _designerHostMock ;
1313 private readonly Mock < IComponentChangeService > _componentChangeServiceMock ;
1414 private readonly DummyServiceProvider _provider ;
15+ private readonly ToolStripKeyboardHandlingService _service ;
1516
1617 public ToolStripKeyboardHandlingServiceTests ( )
1718 {
@@ -20,12 +21,14 @@ public ToolStripKeyboardHandlingServiceTests()
2021 _componentChangeServiceMock = new ( ) ;
2122
2223 _provider = new ( type =>
23- type == typeof ( ISelectionService ) ? _selectionServiceMock . Object :
24- type == typeof ( IDesignerHost ) ? _designerHostMock . Object :
25- type == typeof ( IComponentChangeService ) ? _componentChangeServiceMock . Object :
26- null ) ;
24+ type == typeof ( ISelectionService ) ? _selectionServiceMock . Object
25+ : type == typeof ( IDesignerHost ) ? _designerHostMock . Object
26+ : type == typeof ( IComponentChangeService ) ? _componentChangeServiceMock . Object
27+ : null ) ;
2728
2829 _designerHostMock . Setup ( h => h . GetService ( typeof ( IComponentChangeService ) ) ) . Returns ( _componentChangeServiceMock . Object ) ;
30+
31+ _service = new ( _provider ) ;
2932 }
3033
3134 private class DummyServiceProvider : IServiceProvider
@@ -43,72 +46,64 @@ public DummyServiceProvider(Func<Type, object?> serviceResolver)
4346 [ Fact ]
4447 public void Ctor_InitializesAndSubscribesToEvents ( )
4548 {
46- ToolStripKeyboardHandlingService service = new ( _provider ) ;
47-
4849 _selectionServiceMock . VerifyAdd ( s => s . SelectionChanging += It . IsAny < EventHandler > ( ) , Times . Once ( ) ) ;
4950 _selectionServiceMock . VerifyAdd ( s => s . SelectionChanged += It . IsAny < EventHandler > ( ) , Times . Once ( ) ) ;
5051 _componentChangeServiceMock . VerifyAdd ( s => s . ComponentRemoved += It . IsAny < ComponentEventHandler > ( ) , Times . Once ( ) ) ;
5152 }
5253
5354 [ Fact ]
54- public void AddCommands_DoesNotThrow_WhenNoMenuService ( )
55- {
56- ToolStripKeyboardHandlingService service = new ( _provider ) ;
57- service . AddCommands ( ) ;
58- }
55+ public void AddCommands_DoesNotThrow_WhenNoMenuService ( ) =>
56+ ( ( Action ) _service . AddCommands ) . Should ( ) . NotThrow ( ) ;
5957
6058 [ Fact ]
61- public void RestoreCommands_DoesNotThrow_WhenNoMenuService ( )
62- {
63- ToolStripKeyboardHandlingService service = new ( _provider ) ;
64- service . RestoreCommands ( ) ;
65- }
59+ public void RestoreCommands_DoesNotThrow_WhenNoMenuService ( ) =>
60+ ( ( Action ) _service . RestoreCommands ) . Should ( ) . NotThrow ( ) ;
6661
6762 [ Fact ]
68- public void RemoveCommands_DoesNotThrow_WhenNoMenuService ( )
69- {
70- ToolStripKeyboardHandlingService service = new ( _provider ) ;
71- service . RemoveCommands ( ) ;
72- }
63+ public void RemoveCommands_DoesNotThrow_WhenNoMenuService ( ) =>
64+ ( ( Action ) _service . RemoveCommands ) . Should ( ) . NotThrow ( ) ;
7365
7466 [ Fact ]
7567 public void OnContextMenu_ReturnsTrue_WhenTemplateNodeActive ( )
7668 {
77- ToolStripKeyboardHandlingService service = new ( _provider )
78- {
79- TemplateNodeActive = true
80- } ;
81- service . OnContextMenu ( 10 , 10 ) . Should ( ) . BeTrue ( ) ;
69+ _service . TemplateNodeActive = true ;
70+
71+ bool result = _service . OnContextMenu ( 10 , 10 ) ;
72+
73+ result . Should ( ) . BeTrue ( ) ;
8274 }
8375
8476 [ Fact ]
8577 public void OnContextMenu_ReturnsFalse_WhenNotTemplateNodeActive ( )
8678 {
87- ToolStripKeyboardHandlingService service = new ( _provider )
88- {
89- TemplateNodeActive = false
90- } ;
91- service . OnContextMenu ( 10 , 10 ) . Should ( ) . BeFalse ( ) ;
79+ _service . TemplateNodeActive = false ;
80+
81+ bool result = _service . OnContextMenu ( 10 , 10 ) ;
82+
83+ result . Should ( ) . BeFalse ( ) ;
9284 }
9385
9486 [ Fact ]
9587 public void ProcessKeySelect_DoesNotThrow_WhenNoSelectionService ( )
9688 {
97- ToolStripKeyboardHandlingService service = new ( _provider ) ;
98- service . ProcessKeySelect ( false ) ;
89+ Action action = ( ) => _service . ProcessKeySelect ( false ) ;
90+
91+ action . Should ( ) . NotThrow ( ) ;
9992 }
10093
10194 [ Fact ]
10295 public void ProcessUpDown_DoesNotThrow_WhenNoSelectionService ( )
10396 {
104- ToolStripKeyboardHandlingService service = new ( _provider ) ;
105- service . ProcessUpDown ( false ) ;
97+ Action action = ( ) => _service . ProcessUpDown ( false ) ;
98+
99+ action . Should ( ) . NotThrow ( ) ;
106100 }
107101
108102 [ Fact ]
109103 public void RotateTab_DoesNotThrow_WhenNoSelectionService ( )
110104 {
111- ToolStripKeyboardHandlingService service = new ( _provider ) ;
112- service . RotateTab ( false ) ;
105+ Action action = ( ) => _service . RotateTab ( false ) ;
106+
107+ action . Should ( ) . NotThrow ( ) ;
113108 }
114109}
0 commit comments