Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have method I want to test and I get this error
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.


i understand this because of the form needs to run first but any alternatives?

C#
public partial class ImportForm : Form{
 public ImportForm()
        {
        }
  public bool Test(string[] fileNames)//Method to test
        {
          return true;
        }
}


What I have tried:

Here is my unit test
C#
[TestMethod]
public void TestTest()
{


    bool results=false;
    var files = new string[4];
    files[0] = @"filename1.xlsx";
    files[1] = @"filename2.xlsx";

    ImportForm form= new ImportForm();
     results = form.Test(files);

    Assert.AreEqual(true, results);
}
Posted
Comments
G3Coder 4-Jun-18 9:35am    
Encapsulate the functionality you need to test in a separate class, which you can unit test and call from the form - so you will new up this new class from inside the form and the unit test.
Anele Ngqandu 4-Jun-18 10:12am    
I have controls that am using, listviews that am populating in a foreach inside that functionality
G3Coder 5-Jun-18 4:51am    
Have the new class hold a list (public property) that you can either point the listview towards or foreach through to populate listview after its done its work. You are going to need something along those lines for the test anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900