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