Hello,
I have this test setup:
var targetLabel = new Label { ID = "label" };
var p = Isolate.Fake.Instance<Panel>();
Isolate.WhenCalled(() => p.ID).WillReturn("panel");
p.Controls.Add(targetLabel);
p.Controls.Add(new TextBox { ID = "text" });
var p2 = Isolate.Fake.Instance<Panel>();
Isolate.WhenCalled(() => p2.ID).WillReturn("panel2");
p2.Controls.Add(new Label { ID = "label2" });
p2.Controls.Add(new TextBox { ID = "text2" });
p.Controls.Add(p2);
Isolate.WhenCalled(() => p2.FindControl("label")).WithExactArguments().WillReturn(null);
Isolate.WhenCalled(() => p.FindControl("label")).WithExactArguments().WillReturn(targetLabel);
This is for a processing component that loops through the structure. As it loops through the structure, I want, when it gets to the p2 element, to return null, which will continue the looping, but when p is hit, it will return a match, which gets returned to the caller.
The issue is, FindControl returns a control, so it doesn't actually return a targetLabel; the assert;
Assert.IsInstanceOf<Label>(result)
Fails because the FindControl() method returns a faked control instance,not my targetLabel control reference.... so how can I mock FindControl, because the issue is its referring to all the controls as Control, and not their respective types.
Thanks.