I´m trying to create new Controls (TextBox, ComboBox and CheckBox) to a Control.ControlCollection, but it doesn´t work. Normally my WinForm would pass its controls to that method, but now I´m trying to write a unit test for it.
Here´s the code:
TestClass target = new TestClass();
Control.ControlCollection controls = null;
CheckBox checkBox = new CheckBox();
checkBox.Name = "SomeCheckBox";
checkBox.Checked = true;
ComboBox comboBox = new ComboBox();
comboBox.Name = "SomeComboBox";
checkBox.Text = "Some text in CB";
TextBox count = new TextBox();
count.Name = "CountTextBox";
count.Text = "20";
TextBox date = new TextBox();
date.Name = "DateNow";
date.Text = System.DateTime.Now.ToString("dd.MM.yyyy");
controls.AddRange(new Control[] {checkBox, comboBox, count, date });
string actual;
actual = target.saveEverything(controls);
Test fails in the AddRange-Row. What mistake did I make?