Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you are suggesting won't even compile if your code relies on System.Windows.Forms.Control. Your version of Control and Textbox are simply the wrong type.</p> <p>If, instead, you separated your UI and Logic with interfaces, then you could do this... Something like this:</p> <pre><code>public interface ITextBox { public string Text {get; set;} } public class TextBoxAdapter : ITextBox { private readonly System.Windows.Forms.TextBox _textBox; public TextBoxAdapter(System.Windows.Forms.TextBox textBox) { _textBox = textBox; } public string Text { get { return _textBox.Text; } set { _textBox.Text = value; } } } public class YourClass { private ITextBox _textBox; public YourClass(ITextBox textBox) { _textBox = textBox; } public void DoSomething() { _textBox.Text = "twiddleMe"; } } </code></pre> <p>Then, in your test, all you need to do is create a mock, fake or stub ITextBox and pass it in.</p> <p>When I do something like this, I create an interface at a slightly higher level... I create an interface that looks a lot like the entire UI and have the UI implement the interface. Then, I can twiddle the UI all I need, without ever really knowing that it is a Forms control.</p> <p>By the way, if you want to go with the approach of creating actual controls, consider this blog post about it: <a href="http://www.houseofbilz.com/archive/2008/10/12/winforms-automation-extensions.aspx" rel="nofollow noreferrer">http://www.houseofbilz.com/archive/2008/10/12/winforms-automation-extensions.aspx</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload