Author: kostat
Date: 2006-07-06 09:39:11 -0400 (Thu, 06 Jul 2006)
New Revision: 62314

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs
   trunk/mcs/class/System.Web/System.Web.UI/Control.cs
   trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/BoundFieldTest.cs
Log:
bug fixes found by Test/System.Web.UI.WebControls/BoundFieldTest

Modified: trunk/mcs/class/System.Web/System.Web.UI/Control.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2006-07-06 12:56:07 UTC 
(rev 62313)
+++ trunk/mcs/class/System.Web/System.Web.UI/Control.cs 2006-07-06 13:39:11 UTC 
(rev 62314)
@@ -183,7 +183,7 @@
                public Control BindingContainer {
                        get {
                                Control container = NamingContainer;
-                               if ((container.stateMask & BINDING_CONTAINER) 
== 0)
+                               if (container != null && (container.stateMask & 
BINDING_CONTAINER) == 0)
                                        container = container.BindingContainer;
                                return container;
                        }

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs  
2006-07-06 12:56:07 UTC (rev 62313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/BoundField.cs  
2006-07-06 13:39:11 UTC (rev 62314)
@@ -46,16 +46,15 @@
                
                PropertyDescriptor boundProperty;
 
-               [MonoTODO]
                [DefaultValueAttribute (false)]
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual bool ApplyFormatInEditMode {
                        get {
-                               throw new NotImplementedException ();
+                               return ViewState.GetBool 
("ApplyFormatInEditMode", false);
                        }
                        set {
-                               throw new NotImplementedException ();
+                               ViewState ["ApplyFormatInEditMode"] = value;
                        }
                }
                
@@ -63,7 +62,7 @@
                [WebSysDescription ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual bool ConvertEmptyStringToNull {
-                       get { return ViewState.GetBool 
("ConvertEmptyStringToNull", false); }
+                       get { return ViewState.GetBool 
("ConvertEmptyStringToNull", true); }
                        set {
                                ViewState ["ConvertEmptyStringToNull"] = value;
                                OnFieldChanged ();
@@ -108,7 +107,7 @@
                [DefaultValueAttribute ("")]
                [WebCategoryAttribute ("Behavior")]
                public virtual string NullDisplayText {
-                       get { return ViewState.GetString ("NullDisplaytext", 
""); }
+                       get { return ViewState.GetString ("NullDisplayText", 
""); }
                        set {
                                ViewState ["NullDisplayText"] = value;
                                OnFieldChanged ();
@@ -209,32 +208,36 @@
                {
                        return GetBoundValue (Control);
                }
-               
+
                object GetBoundValue (Control controlContainer)
                {
+                       object dataItem = DataBinder.GetDataItem 
(controlContainer);
+                       if (dataItem == null)
+                               throw new HttpException ("A data item was not 
found in the container. The container must either implement IDataItemContainer, 
or have a property named DataItem.");
+
                        if (DataField == ThisExpression)
-                               return controlContainer.ToString ();
-                       else {
-                               IDataItemContainer dic = (IDataItemContainer) 
controlContainer;
-                               if (boundProperty == null) {
-                                       boundProperty = 
TypeDescriptor.GetProperties (dic.DataItem) [DataField];
-                                       if (boundProperty == null)
-                                               throw new 
InvalidOperationException ("Property '" + DataField + "' not found in object of 
type " + dic.DataItem.GetType());
-                               }
-                               return boundProperty.GetValue (dic.DataItem);
-                       }
+                               return dataItem.ToString ();
+
+                       return DataBinder.GetPropertyValue (dataItem, 
DataField);
                }
                
                protected virtual void OnDataBindField (object sender, 
EventArgs e)
                {
-                       DataControlFieldCell cell = (DataControlFieldCell) 
sender;
+                       Control cell = (Control) sender;
+                       Control controlContainer = cell.BindingContainer;
+                       if (!(controlContainer is INamingContainer))
+                               throw new HttpException ("A DataControlField 
must be within an INamingContainer.");
+                       object val = GetValue (controlContainer);
+
                        if (cell.Controls.Count > 0) {
                                TextBox box = (TextBox) cell.Controls [0];
-                               object val = GetValue (cell.BindingContainer);
-                               box.Text = val != null ? val.ToString() : "";
+                               if (ApplyFormatInEditMode)
+                                       box.Text = FormatDataValue (val, 
SupportsHtmlEncode && HtmlEncode);
+                               else
+                                       box.Text = val != null ? val.ToString() 
: NullDisplayText;
                        }
                        else
-                               cell.Text = FormatDataValue (GetValue 
(cell.BindingContainer), SupportsHtmlEncode && HtmlEncode);
+                               ((DataControlFieldCell)cell).Text = 
FormatDataValue (val, SupportsHtmlEncode && HtmlEncode);
                }
                
                protected override DataControlField CreateField ()

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-07-06 12:56:07 UTC (rev 62313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2006-07-06 13:39:11 UTC (rev 62314)
@@ -1,3 +1,7 @@
+2006-07-06     Konstantin Triger <[EMAIL PROTECTED]>
+
+        * DataControlField.cs,BoundField.cs: bug fixes found by BoundFieldTest.
+
 2006-07-05     Konstantin Triger <[EMAIL PROTECTED]>
 
         * DataControlField.cs: correct handling empty header/footer text.

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs    
2006-07-06 12:56:07 UTC (rev 62313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataControlField.cs    
2006-07-06 13:39:11 UTC (rev 62314)
@@ -84,14 +84,15 @@
                {
                        if (cellType == DataControlCellType.Header)
                        {
-                               if (HeaderText.Length > 0 || 
HeaderImageUrl.Length > 0) {
-                                       if (sortingEnabled && 
SortExpression.Length > 0)
-                                               cell.Controls.Add (new 
DataControlButton (control, HeaderText, HeaderImageUrl, 
DataControlCommands.SortCommandName, SortExpression, true));
-                                       else
-                                               cell.Controls.Add (new 
DataControlButton (control, HeaderText, HeaderImageUrl, string.Empty, 
string.Empty, true));
+                               if (HeaderText.Length > 0 && sortingEnabled && 
SortExpression.Length > 0)
+                                       cell.Controls.Add (new 
DataControlButton (control, HeaderText, HeaderImageUrl, 
DataControlCommands.SortCommandName, SortExpression, true));
+                               else if (HeaderImageUrl.Length > 0) {
+                                       Image image = new Image ();
+                                       image.ImageUrl = HeaderImageUrl;
+                                       cell.Controls.Add (image);
                                }
                                else
-                                       cell.Text = "&nbsp;";
+                                       cell.Text = HeaderText.Length > 0 ? 
HeaderText : "&nbsp;";
                        }
                        else if (cellType == DataControlCellType.Footer) {
                                string footerText = FooterText;

Modified: 
trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/BoundFieldTest.cs
===================================================================
--- trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/BoundFieldTest.cs 
2006-07-06 12:56:07 UTC (rev 62313)
+++ trunk/mcs/class/System.Web/Test/System.Web.UI.WebControls/BoundFieldTest.cs 
2006-07-06 13:39:11 UTC (rev 62314)
@@ -39,7 +39,7 @@
 using System.Drawing;
 using System.Collections;
 using System.Collections.Specialized;
-using Image = System.Web.UI.WebControls.Image ;
+using Image = System.Web.UI.WebControls.Image;
 using NUnit.Framework;
 using System.Globalization;
 
@@ -51,64 +51,52 @@
        {
                public Button bindbutoon;
 
-               public PokerBoundField ()
-               {
+               public PokerBoundField () {
                        TrackViewState ();
                        bindbutoon = new Button ();
                        bindbutoon.DataBinding += new EventHandler 
(OnDataBindField);
                }
 
 
-               public StateBag StateBag
-               {
+               public StateBag StateBag {
                        get { return base.ViewState; }
                }
 
-               public bool DoSupportsHtmlEncode
-               {
-                       get
-                       {
+               public bool DoSupportsHtmlEncode {
+                       get {
                                return base.SupportsHtmlEncode;
                        }
                }
 
-               public void DoCopyProperties (DataControlField newField)
-               {
+               public void DoCopyProperties (DataControlField newField) {
                        base.CopyProperties (newField);
                }
 
-               public DataControlField DoCreateField ()
-               {
+               public DataControlField DoCreateField () {
                        return base.CreateField ();
                }
 
-               public string DoFormatDataValue (object dataValue, bool encode)
-               {
+               public string DoFormatDataValue (object dataValue, bool encode) 
{
                        return this.FormatDataValue (dataValue, encode);
                }
 
-               public object DoGetDesignTimeValue ()
-               {
+               public object DoGetDesignTimeValue () {
                        return base.GetDesignTimeValue ();
                }
 
-               public object DoGetValue (Control controlContainer)
-               {
+               public object DoGetValue (Control controlContainer) {
                        return base.GetValue (controlContainer);
                }
 
-               public void DoInitializeDataCell (DataControlFieldCell cell, 
DataControlRowState rowState)
-               {
+               public void DoInitializeDataCell (DataControlFieldCell cell, 
DataControlRowState rowState) {
                        base.InitializeDataCell (cell, rowState);
                }
 
-               public void DoOnDataBindField (object sender, EventArgs e)
-               {
+               public void DoOnDataBindField (object sender, EventArgs e) {
                        base.OnDataBindField (sender, e);
                }
 
-               public Control GetControl
-               {
+               public Control GetControl {
                        get { return base.Control; }
                }
        }
@@ -118,8 +106,7 @@
        public class BoundFieldTest
        {
                [Test]
-               public void BoundField_DefaultProperty ()
-               {
+               public void BoundField_DefaultProperty () {
                        PokerBoundField bf = new PokerBoundField ();
                        Assert.AreEqual ("!", PokerBoundField.ThisExpression, 
"StaticThisExpression");
                        Assert.AreEqual ("", bf.DataField, "DataField");
@@ -134,18 +121,14 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_DefaultPropertyNotWorking ()
-               {
+               public void BoundField_DefaultPropertyNotWorking () {
                        PokerBoundField bf = new PokerBoundField ();
                        Assert.AreEqual (false, bf.ApplyFormatInEditMode, 
"ApplyFormatInEditMode");
                        Assert.AreEqual (true, bf.ConvertEmptyStringToNull, 
"ConvertEmptyStringToNull");
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_AssignProperty ()
-               {
+               public void BoundField_AssignProperty () {
                        PokerBoundField bf = new PokerBoundField ();
                        bf.ConvertEmptyStringToNull = false;
                        Assert.AreEqual (false, bf.ConvertEmptyStringToNull, 
"ConvertEmptyStringToNull");
@@ -164,29 +147,25 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_AssignPropertyNotWorking ()
-               {
+               public void BoundField_AssignPropertyNotWorking () {
                        PokerBoundField bf = new PokerBoundField ();
                        bf.ApplyFormatInEditMode = true;
                        Assert.AreEqual (true, bf.ApplyFormatInEditMode, 
"ApplyFormatInEditMode");
                }
 
                [Test]
-               public void BoundField_ExtractValuesFromCell ()
-               {
+               public void BoundField_ExtractValuesFromCell () {
                        PokerBoundField bf = new PokerBoundField ();
                        OrderedDictionary dictionary = new OrderedDictionary ();
                        DataControlFieldCell cell = new DataControlFieldCell 
(null);
                        cell.Text = "test";
                        bf.ExtractValuesFromCell (dictionary, cell, 
DataControlRowState.Normal, true);
                        Assert.AreEqual (1, dictionary.Count, 
"ExtractValuesFromCellCount");
-                       Assert.AreEqual ("test", dictionary[0].ToString (), 
"ExtractValuesFromCellValue");
+                       Assert.AreEqual ("test", dictionary [0].ToString (), 
"ExtractValuesFromCellValue");
                }
 
                [Test]
-               public void BoundField_Initialize ()
-               {
+               public void BoundField_Initialize () {
                        // This method initilize to private fields in a base 
class DataControlField 
                        // Always return false
                        PokerBoundField bf = new PokerBoundField ();
@@ -198,68 +177,79 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_InitializeCell ()
-               {
+               public void BoundField_InitializeCell () {
                        PokerBoundField bf = new PokerBoundField ();
                        // Header text
                        DataControlFieldCell cell = new DataControlFieldCell 
(null);
                        bf.HeaderText = "headertext";
+
                        bf.InitializeCell (cell, DataControlCellType.Header, 
DataControlRowState.Edit, 1);
                        Assert.AreEqual ("headertext", cell.Text, 
"InitializeCellHeaderText");
                        // Empty header text
                        bf.HeaderText = "";
                        bf.InitializeCell (cell, DataControlCellType.Header, 
DataControlRowState.Edit, 1);
                        Assert.AreEqual ("&nbsp;", cell.Text, 
"InitializeCellEmpty");
+
+                       bf.HeaderText = "headertext";
                        // Header image url not empty
                        bf.HeaderImageUrl = "headerurl";
                        bf.InitializeCell (cell, DataControlCellType.Header, 
DataControlRowState.Edit, 1);
-                       if (cell.Controls[0] is Image) {
-                               Image image = (Image) cell.Controls[0];
+                       if (cell.Controls [0] is Image) {
+                               Image image = (Image) cell.Controls [0];
                                Assert.AreEqual ("headerurl", image.ImageUrl, 
"InitializeCellHeaderImageUrl");
                        }
                        else {
                                Assert.Fail ("Header Image dos not created");
                        }
 
+                       // Footer empty
+                       bf.FooterText = "footertext";
+                       bf.InitializeCell (cell, DataControlCellType.Footer, 
DataControlRowState.Edit, 1);
+                       Assert.AreEqual ("footertext", cell.Text, 
"InitializeCellFooterText");
+                       bf.FooterText = "";
+                       bf.InitializeCell (cell, DataControlCellType.Footer, 
DataControlRowState.Edit, 1);
+                       Assert.AreEqual ("&nbsp;", cell.Text, 
"InitializeCellFooterEmpty");
+               }
+
+               [Test]
+               public void BoundField_ValidateSupportsCallback () {
+                       //This method has been implemented as an empty method   
        
+               }
+
+               [Test]
+               public void BoundField_SortExpression () {
                        // Sorting enable = true , link button must be created
-                       cell.Controls.Clear ();
+                       PokerBoundField bf = new PokerBoundField ();
+                       // Header text
+                       DataControlFieldCell cell = new DataControlFieldCell 
(null);
+
                        bf.HeaderImageUrl = "";
                        bf.SortExpression = "a";
                        bf.HeaderText = "sortbutton";
                        bf.Initialize (true, new Control ());    // 
_base._sortingenable set to true
                        bf.InitializeCell (cell, DataControlCellType.Header, 
DataControlRowState.Edit, 1);
-                       if (cell.Controls[0] is LinkButton) {
-                               LinkButton lb = (LinkButton) cell.Controls[0];
+                       if (cell.Controls [0] is Button) { // mono
+                               Button lb = (Button) cell.Controls [0];
                                Assert.AreEqual ("Sort", lb.CommandName, 
"InitializeCellHeaderSortButtonCommand");
                                Assert.AreEqual ("a", lb.CommandArgument, 
"InitializeCellHeaderSortButtonArgument");
                                Assert.AreEqual ("sortbutton", lb.Text, 
"InitializeCellHeaderSortButtonText");
 
                        }
+                       else if (cell.Controls [0] is LinkButton) { // .net
+                               LinkButton lb = (LinkButton) cell.Controls [0];
+                               Assert.AreEqual ("Sort", lb.CommandName, 
"InitializeCellHeaderSortButtonCommand");
+                               Assert.AreEqual ("a", lb.CommandArgument, 
"InitializeCellHeaderSortButtonArgument");
+                               Assert.AreEqual ("sortbutton", lb.Text, 
"InitializeCellHeaderSortButtonText");
+
+                       }
                        else {
                                Assert.Fail ("Sort button does not created");
                        }
-
-                       // Footer empty
-                       bf.FooterText = "footertext";
-                       bf.InitializeCell (cell, DataControlCellType.Footer, 
DataControlRowState.Edit, 1);
-                       Assert.AreEqual ("footertext", cell.Text, 
"InitializeCellFooterText");
-                       bf.FooterText = "";
-                       bf.InitializeCell (cell, DataControlCellType.Footer, 
DataControlRowState.Edit, 1);
-                       Assert.AreEqual ("&nbsp;", cell.Text, 
"InitializeCellFooterEmpty");
                }
 
-               [Test]
-               public void BoundField_ValidateSupportsCallback ()
-               {
-                       //This method has been implemented as an empty method   
        
-               }
 
-
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_CopyProperties ()
-               {
+               public void BoundField_CopyProperties () {
                        PokerBoundField bf = new PokerBoundField ();
                        BoundField copy = new BoundField ();
                        // Look not working property
@@ -282,17 +272,14 @@
                }
 
                [Test]
-               public void BoundField_CreateField ()
-               {
+               public void BoundField_CreateField () {
                        PokerBoundField bf = new PokerBoundField ();
                        BoundField newfield = (BoundField) bf.DoCreateField ();
                        Assert.IsNotNull (newfield, "CreateField");
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_FormatDataValue ()
-               {
+               public void BoundField_FormatDataValue () {
                        string result;
                        PokerBoundField bf = new PokerBoundField ();
 
@@ -313,8 +300,7 @@
 
                [Test]
                [Category ("NotWorking")]
-               public void BoundField_GetDesignTimeValue ()
-               {
+               public void BoundField_GetDesignTimeValue () {
                        string result;
                        PokerBoundField bf = new PokerBoundField ();
                        result = (string) bf.DoGetDesignTimeValue ();
@@ -322,10 +308,17 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
-               public void BoundField_GetValue ()
-               {
+               [ExpectedException(typeof(HttpException), "A data item was not 
found in the container. The container must either implement IDataItemContainer, 
or have a property named DataItem.")]
+               public void BoundField_GetValueNull () {
                        PokerBoundField bf = new PokerBoundField ();
+                       SimpleSpreadsheetRow ds = new SimpleSpreadsheetRow (0, 
null);
+                       bf.DataField = PokerBoundField.ThisExpression;
+                       string result = (string) bf.DoGetValue (ds);
+               }
+
+               [Test]
+               public void BoundField_GetValue () {
+                       PokerBoundField bf = new PokerBoundField ();
                        SimpleSpreadsheetRow ds = new SimpleSpreadsheetRow (0, 
"test");
                        bf.DataField = PokerBoundField.ThisExpression;
                        string result = (string) bf.DoGetValue (ds);
@@ -333,9 +326,17 @@
                }
 
                [Test]
-               public void BoundField_InitializeDataCell ()
-               {
+               public void BoundField_GetValueDataItem () {
                        PokerBoundField bf = new PokerBoundField ();
+                       ControlWithDataItem ds = new ControlWithDataItem 
("test");
+                       bf.DataField = PokerBoundField.ThisExpression;
+                       string result = (string) bf.DoGetValue (ds);
+                       Assert.AreEqual ("test", result, 
"GetValueFromIDataItemContainer");
+               }
+
+               [Test]
+               public void BoundField_InitializeDataCell () {
+                       PokerBoundField bf = new PokerBoundField ();
                        bf.HeaderText = "headertest";
                        DataControlFieldCell cell = new DataControlFieldCell 
(null);
                        DataControlRowState state = DataControlRowState.Edit;
@@ -345,63 +346,64 @@
                }
 
                [Test]
-               [Category ("NotWorking")]
                [ExpectedException (typeof (HttpException))]
-               public void BoundField_OnDataBindFieldExeption ()
-               {
+               public void BoundField_OnDataBindFieldExeption () {
                        PokerBoundField bf = new PokerBoundField ();
                        bf.bindbutoon.DataBind ();
 
                }
 
                [Test]
-               [Category ("NotWorking")]
                [ExpectedException (typeof (HttpException))]
-               public void BoundField_GetValueExeption ()
-               {
+               public void BoundField_GetValueExeption () {
                        PokerBoundField bf = new PokerBoundField ();
                        bf.DoGetValue (null);
                }
 
+               class ControlWithDataItem : Control
+               {
+                       readonly object _data;
+                       public ControlWithDataItem (object data) {
+                               _data = data;
+                       }
+
+                       public object DataItem {
+                               get {
+                                       return _data;
+                               }
+                       }
+               }
+
                public class SimpleSpreadsheetRow : TableRow, IDataItemContainer
                {
                        private object data;
                        private int _itemIndex;
 
-                       public SimpleSpreadsheetRow (int itemIndex, object o)
-                       {
+                       public SimpleSpreadsheetRow (int itemIndex, object o) {
                                data = o;
                                _itemIndex = itemIndex;
                        }
 
-                       public virtual object Data
-                       {
-                               get
-                               {
+                       public virtual object Data {
+                               get {
                                        return data;
                                }
                        }
 
-                       object IDataItemContainer.DataItem
-                       {
-                               get
-                               {
+                       object IDataItemContainer.DataItem {
+                               get {
                                        return Data;
                                }
                        }
 
-                       int IDataItemContainer.DataItemIndex
-                       {
-                               get
-                               {
+                       int IDataItemContainer.DataItemIndex {
+                               get {
                                        return _itemIndex;
                                }
                        }
 
-                       int IDataItemContainer.DisplayIndex
-                       {
-                               get
-                               {
+                       int IDataItemContainer.DisplayIndex {
+                               get {
                                        return _itemIndex;
                                }
                        }

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to