public void Defaults() { var field = new PokerFieldTemplateUserControl(); // And for another time - not a single null check in the code... // // All the asserts commented out below throw a NREX // //Assert.IsNull (field.ChildrenColumn, "#A1"); //Assert.IsNull (field.GetChildrenPath (), "#A2"); //Assert.IsNull (field.Column, "#A3"); Assert.IsNull(field.DataControl, "#A4"); //Assert.IsNull (field.FieldValue, "#A5"); //Assert.IsNull (field.FieldValueEditString, "#A6"); //Assert.IsNull (field.FieldValueString, "#A7"); //Assert.IsNull (field.ForeignKeyColumn, "#A8"); //Assert.IsNull (field.GetForeignKeyPath (), "#A9"); Assert.IsNull(field.Host, "#A10"); //Assert.IsNull (field.MetadataAttributes, "#A11"); //Assert.IsNull (field.Mode, "#A12"); //Assert.IsNull (field.Row, "#A13"); //Assert.IsNull (field.Table, "#A14"); }
static void Defaults_WithHost_OnLoad(Page p) { // Not many "defaults" here var lc = p.FindControl("ListView1") as ListView; Assert.IsNotNull(lc, "#A1"); var dc = lc.FindChild <DynamicControl> ("FirstName"); Assert.IsNotNull(dc, "#B1-1"); Assert.AreEqual("FirstName", dc.ID, "#B1-2"); var field = new PokerFieldTemplateUserControl(); // Without it Row NREXes... However, with Page set, we still get an exception // this time from Page.GetDataItem () as we're not bound to data. So, there is // no way to test the "defaults" as if we used a field control retrieved from // DataControl it would already be initialized field.Page = p; ((IFieldTemplate)field).SetHost(dc); AssertExtensions.Throws <Exception> (() => { var f = field.ChildrenColumn; }, "#C1"); // The FirstName column is not a children one AssertExtensions.Throws <Exception> (() => { field.GetChildrenPath(); }, "#C2"); Assert.IsNotNull(field.Column, "#C3"); Assert.AreEqual(dc.Column, field.Column, "#C3-1"); Assert.IsNull(field.DataControl, "#C4"); // The tests below fail with exception: // // MonoTests.System.Web.DynamicData.FieldTemplateUserControlTest.Defaults_WithHost: // System.InvalidOperationException : System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. // at System.Web.UI.Page.GetDataItem() // at System.Web.DynamicData.FieldTemplateUserControl.get_Row() // at System.Web.DynamicData.FieldTemplateUserControl.GetColumnValue(MetaColumn column) // at System.Web.DynamicData.FieldTemplateUserControl.get_FieldValue() // at System.Web.DynamicData.FieldTemplateUserControl.get_FieldValueEditString() // at MonoTests.System.Web.DynamicData.FieldTemplateUserControlTest.Defaults_WithHost_OnLoad(Page p) // at MonoTests.SystemWeb.Framework.PageInvoker.Invoke(PageDelegate callback) // at MonoTests.SystemWeb.Framework.PageInvoker.OnLoad(Object sender, EventArgs a) // at System.EventHandler.Invoke(Object sender, EventArgs e) // at System.Web.UI.Control.OnLoad(EventArgs e) // at System.Web.UI.Control.LoadRecursive() // at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) // ----> System.InvalidOperationException : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. //Assert.IsNull (field.FieldValue, "#C5"); //Assert.IsNull (field.FieldValueEditString, "#C6"); //Assert.IsNull (field.FieldValueString, "#C7"); // The FirstName column is not a foreign key one AssertExtensions.Throws <Exception> (() => { var f = field.ForeignKeyColumn; }, "#C8"); AssertExtensions.Throws <Exception> (() => { var f = field.GetForeignKeyPath(); }, "#C9"); Assert.IsNotNull(field.Host, "#C10"); Assert.AreEqual(dc, field.Host, "#C10-1"); Assert.IsNotNull(field.MetadataAttributes, "#C11"); Assert.AreEqual(dc.Column.Attributes, field.MetadataAttributes, "#C11-1"); Assert.AreEqual(DataBoundControlMode.ReadOnly, field.Mode, "#C12"); Assert.AreEqual(field.Host.Mode, field.Mode, "#C12-1"); // Failure with the same exception as above //Assert.IsNull (field.Row, "#C13"); Assert.IsNotNull(field.Table, "#C14"); Assert.AreEqual(dc.Table, field.Table, "#C14-1"); }