@@ -141,4 +141,121 @@ public void OnComponentRemoved_DoesNotRemoveService_WhenToolStripPresent()
141
141
142
142
_mockDesignerHost . Verify ( dh => dh . RemoveService ( typeof ( ISupportInSituService ) ) , Times . Never ) ;
143
143
}
144
+
145
+ [ Fact ]
146
+ public void IgnoreMessages_WhenPrimarySelectionIsNotIComponentAndSelectedDesignerControlIsNull_ReturnsFalse ( )
147
+ {
148
+ _inSituService . TestAccessor ( ) . Dynamic . _toolDesigner = _mockToolStripDesigner . Object ;
149
+ bool result = _inSituService . IgnoreMessages ;
150
+ result . Should ( ) . BeFalse ( ) ;
151
+ }
152
+
153
+ [ Fact ]
154
+ public void IgnoreMessages_WhenComponentIsMenuStrip_ReturnsTrue ( )
155
+ {
156
+ Mock < MenuStrip > menuStripMock = new ( ) ;
157
+ Mock < ToolStrip > toolStripMock = new ( ) ;
158
+ _mockSelectionService . Setup ( ss => ss . PrimarySelection ) . Returns ( menuStripMock . Object ) ;
159
+ _mockDesignerHost . Setup ( dh => dh . GetDesigner ( menuStripMock . Object ) ) . Returns ( _mockToolStripDesigner . Object ) ;
160
+ bool result = _inSituService . IgnoreMessages ;
161
+ result . Should ( ) . BeTrue ( ) ;
162
+ }
163
+
164
+ [ Fact ]
165
+ public void IgnoreMessages_WhenComponentIsToolStripMenuItem_ReturnsTrue ( )
166
+ {
167
+ Mock < ToolStripMenuItem > toolStripMenuItemMock = new ( ) ;
168
+ Mock < DesignerToolStripControlHost > designerToolStripControlHostMock = new ( toolStripMenuItemMock . Object ) ;
169
+ _mockSelectionService . Setup ( ss => ss . PrimarySelection ) . Returns ( toolStripMenuItemMock . Object ) ;
170
+ _mockDesignerHost . Setup ( dh => dh . GetDesigner ( toolStripMenuItemMock . Object ) ) . Returns ( _mockToolStripItemDesigner . Object ) ;
171
+ bool result = _inSituService . IgnoreMessages ;
172
+ result . Should ( ) . BeTrue ( ) ;
173
+ }
174
+
175
+ // TODO: Uncomment when internalsVisibleTo is working again
176
+ [ Fact ]
177
+ public void IgnoreMessages_WhenComponentIsToolStripDropDown_ReturnsTrue ( )
178
+ {
179
+ Mock < ToolStripDropDown > toolStripDropDownMock = new ( ) ;
180
+ var toolStripDropDownDesignerMock = new Mock < SubToolStripDropDownDesigner > ( ) ;
181
+ _mockSelectionService . Setup ( ss => ss . PrimarySelection ) . Returns ( toolStripDropDownMock . Object ) ;
182
+ _mockDesignerHost . Setup ( dh => dh . GetDesigner ( toolStripDropDownMock . Object ) ) . Returns ( toolStripDropDownDesignerMock . Object ) ;
183
+ object toolItemDesignerValue = _inSituService . TestAccessor ( ) . Dynamic . _toolItemDesigner ;
184
+ toolItemDesignerValue = _mockToolStripItemDesigner . Object ;
185
+
186
+ toolStripDropDownDesignerMock . Setup ( tdd => tdd . DesignerMenuItem ) . Returns ( new ToolStripMenuItem ( ) ) ;
187
+ bool result = _inSituService . IgnoreMessages ;
188
+ result . Should ( ) . BeTrue ( ) ;
189
+ }
190
+
191
+ private class SubToolStripDropDownDesigner : ToolStripDropDownDesigner
192
+ {
193
+ public SubToolStripDropDownDesigner ( ToolStripDropDown dropDown ) : base ( )
194
+ {
195
+ }
196
+
197
+ public new ToolStripMenuItem DesignerMenuItem => new ( ) ;
198
+ }
199
+
200
+ [ Fact ]
201
+ public void IgnoreMessages_WhenPrimarySelectionIsComponentAndIsDesignerToolStripControlHost_ReturnsTrue ( )
202
+ {
203
+ Mock < ToolStripDropDown > toolStripDropDownMock = new ( ) ;
204
+ Mock < ToolStrip > toolStripMock = new ( ) ;
205
+ Mock < SubDesignerToolStripControlHost > designerToolStripControlHostMock = new ( toolStripDropDownMock . Object ) ;
206
+ _mockSelectionService . Setup ( ss => ss . PrimarySelection ) . Returns ( designerToolStripControlHostMock . Object ) ;
207
+ _inSituService . TestAccessor ( ) . Dynamic . _toolDesigner = _mockToolStripDesigner . Object ;
208
+ object toolStripKeyBoardService = _inSituService . TestAccessor ( ) . Dynamic . ToolStripKeyBoardService ;
209
+ bool result = _inSituService . IgnoreMessages ;
210
+ result . Should ( ) . BeTrue ( ) ;
211
+ }
212
+
213
+ internal class SubDesignerToolStripControlHost : DesignerToolStripControlHost
214
+ {
215
+ private readonly Control _parent ;
216
+
217
+ public SubDesignerToolStripControlHost ( Control c ) : base ( c )
218
+ {
219
+ _parent = c ;
220
+ }
221
+
222
+ public new Control GetCurrentParent ( )
223
+ {
224
+ return _parent ;
225
+ }
226
+ }
227
+
228
+ [ Fact ]
229
+ public void HandleKeyChar_WhenToolItemDesignerIsNotMenuDesigner_CallsShowEditNode ( )
230
+ {
231
+ _inSituService . TestAccessor ( ) . Dynamic . _toolDesigner = null ;
232
+
233
+ _inSituService . HandleKeyChar ( ) ;
234
+
235
+ _mockToolStripItemDesigner . Verify ( d => d . ShowEditNode ( false ) , Times . Once ) ;
236
+ }
237
+
238
+ // TODO: Ditto
239
+ /*
240
+ [Fact]
241
+ public void HandleKeyChar_WhenSelectionIsNull_UsesSelectedDesignerControl()
242
+ {
243
+ Mock<ToolStripMenuItemDesigner> mockMenuDesigner = new();
244
+ _inSituService.TestAccessor().Dynamic._toolDesigner = null;
245
+ _inSituService.TestAccessor().Dynamic._toolItemDesigner = mockMenuDesigner.Object;
246
+
247
+ ToolStripDropDown dummyDropDown = new();
248
+ DesignerToolStripControlHost selectedControl = new(dummyDropDown);
249
+ ToolStripKeyboardHandlingService.SelectedDesignerControl = selectedControl;
250
+ object toolStripKeyBoardService = _inSituService.TestAccessor().Dynamic.ToolStripKeyBoardService;
251
+
252
+ _mockSelectionService.Setup(s => s.PrimarySelection).Returns(null);
253
+
254
+ _inSituService.HandleKeyChar();
255
+
256
+ mockMenuDesigner.Verify(d => d.EditTemplateNode(false), Times.Once);
257
+
258
+ ToolStripKeyboardHandlingService.SelectedDesignerControl = null; // cleanup
259
+ }
260
+ */
144
261
}
0 commit comments