user2236165
user2236165

Reputation: 741

Create a Control in Unit Test for WPF application

I have a WPF-application with a method which takes in a TextBox and return true or false. I have created a Test project, but I cannot create an object of a TextBox to test my method. Is it not possible to add a Control like that in a Test-class? I want to do something like this:

    [TestClass]
public class UnitTest1
{

    [TestMethod]
    public void TestMethod1()
    {
        TextBox textBox = New Textbox();
        Assert.AreEqual(MyMethodWithTextBox(textBox), true);
    }
}

Upvotes: 0

Views: 659

Answers (1)

k.m
k.m

Reputation: 31484

Make sure you add reference to PresentationFramework.dll (this is the assembly where WPF TextBox class lives). Test project template most likely doesn't include it by itself, as opposed to WPF application project template.

Upvotes: 2

Related Questions