public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { Type dockUiType = typeof(DockEditor) .GetNestedType("DockUI", BindingFlags.NonPublic); var dockUiConstructor = dockUiType.GetConstructors()[0]; var dockUiField = typeof(DockEditor) .GetField("dockUI", BindingFlags.Instance | BindingFlags.NonPublic); var dockUiObject = dockUiConstructor.Invoke(new[] { editor }) as Control; dockUiField.SetValue(editor, dockUiObject); var container = dockUiObject.Controls[0]; var none = dockUiObject.Controls[1]; var fill = container.Controls[0]; var left = container.Controls[1]; var right = container.Controls[2]; var top = container.Controls[3]; var bottom = container.Controls[4]; none.Enabled = false; fill.Enabled = false; top.Enabled = false; bottom.Enabled = false; return(editor.EditValue(context, provider, value)); }
public void DockEditor_EditValue_ValidProvider_ReturnsValue(object value) { var editor = new DockEditor(); var mockEditorService = new Mock <IWindowsFormsEditorService>(MockBehavior.Strict); var mockServiceProvider = new Mock <IServiceProvider>(MockBehavior.Strict); mockServiceProvider .Setup(p => p.GetService(typeof(IWindowsFormsEditorService))) .Returns(mockEditorService.Object) .Verifiable(); mockEditorService .Setup(e => e.DropDownControl(It.IsAny <Control>())) .Verifiable(); Assert.Equal(value, editor.EditValue(null, mockServiceProvider.Object, value)); mockServiceProvider.Verify(p => p.GetService(typeof(IWindowsFormsEditorService)), Times.Once()); mockEditorService.Verify(e => e.DropDownControl(It.IsAny <Control>()), Times.Once()); // Edit again. Assert.Equal(value, editor.EditValue(null, mockServiceProvider.Object, value)); mockServiceProvider.Verify(p => p.GetService(typeof(IWindowsFormsEditorService)), Times.Exactly(2)); mockServiceProvider.Verify(p => p.GetService(typeof(IWindowsFormsEditorService)), Times.Exactly(2)); }
public void DockEditor_EditValue_InvalidProvider_ReturnsValue(IServiceProvider provider, object value) { var editor = new DockEditor(); Assert.Same(value, editor.EditValue(null, provider, value)); }