public void TestGetHardCodedXmlNodes_ForDesignerOnly() { FPnl = new TPnlCollapsible(THostedControlKind.hckTaskList, TTestTaskList.GetTestXmlNode()); // Need to resort to .NET Reflection as GetHardCodedXmlNodes_ForDesignerOnly() is a Private Method... MethodInfo InvokedPrivateMethod = FPnl.GetType().GetMethod("GetHardCodedXmlNodes_ForDesignerOnly", BindingFlags.NonPublic | BindingFlags.Instance); XmlNode Nodes = (XmlNode)InvokedPrivateMethod.Invoke(FPnl, new object[] { }); Assert.IsNotNull(Nodes); }
public void TestEvents() { // Not just test that Events are fired, but that the RIGHT Events are fired under // the RIGHT circumstances, and that no wrong Event is fired under wrong circumstances! // (Uses EventHandlerCapture Class for that as NUnit doesn't provide Asserts for // something nifty like that!) FPnl = new TPnlCollapsible(THostedControlKind.hckUserControl, HOSTEDUSERCONTROL); var EhcExpanded = new TNUnitEventHandlerCheck <System.EventArgs>(); var EhcCollapsed = new TNUnitEventHandlerCheck <System.EventArgs>(); FPnl.Expanded += EhcExpanded.Handler; FPnl.Collapsed += EhcCollapsed.Handler; // Assert that the Expanded Event is fired when the Control is Expanded (and that the Collapsed Event isn't) TNUnitEventAsserter.Assert(EhcExpanded, TNUnitEventAsserter.GotRaised <System.EventArgs>(), () => FPnl.Expand()); TNUnitEventAsserter.Assert(EhcCollapsed, TNUnitEventAsserter.DidNotGetRaised <System.EventArgs>(), () => FPnl.Expand()); // Assert that the Collapsed Event is fired when the Control is Expanded (and that the Expanded Event isn't) TNUnitEventAsserter.Assert(EhcCollapsed, TNUnitEventAsserter.GotRaised <System.EventArgs>(), () => FPnl.Collapse()); TNUnitEventAsserter.Assert(EhcExpanded, TNUnitEventAsserter.DidNotGetRaised <System.EventArgs>(), () => FPnl.Collapse()); FPnl.Expanded -= EhcExpanded.Handler; FPnl.Collapsed -= EhcCollapsed.Handler; // Assert that the Expanded/Collapsed Events are fired when the Control's Toggle Button is clicked // Need to resort to .NET Reflection as BtnToggleClick() is a Private Method... MethodInfo InvokedPrivateMethod = FPnl.GetType().GetMethod("BtnToggleClick", BindingFlags.NonPublic | BindingFlags.Instance); // It might look a bit weird to check Assert AreNotSame, but only this way we find out that the // .Invoke calls below do in fact do something! FPnl.Expanded += delegate(object sender, EventArgs e) { Assert.AreNotSame(FPnl, null); }; FPnl.Expanded += delegate(object sender, EventArgs e) { Assert.AreSame(FPnl, sender); }; FPnl.Collapsed += delegate(object sender, EventArgs e) { Assert.AreNotSame(FPnl, null); }; FPnl.Collapsed += delegate(object sender, EventArgs e) { Assert.AreSame(FPnl, sender); }; InvokedPrivateMethod.Invoke(FPnl, new object[] { FPnl, null }); InvokedPrivateMethod.Invoke(FPnl, new object[] { FPnl, null }); }