Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,177 @@
//
// Tests for System.Web.UI.WebControls.AccessDataSource
//
// Author:
// Chris Toshok (toshok@novell.com)
//
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Configuration;
using System.Data.Common;
using System.Data.OleDb;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.System.Web.UI.WebControls
{
class AccessPoker : AccessDataSource {
public AccessPoker ()
{
TrackViewState ();
}
public object SaveToViewState ()
{
return SaveViewState ();
}
public void LoadFromViewState (object savedState)
{
LoadViewState (savedState);
}
public DbProviderFactory GetFactory ()
{
return GetDbProviderFactory ();
}
}
[TestFixture]
public class AccessDataSourceTest {
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ProviderName ()
{
AccessPoker sql = new AccessPoker ();
sql.ProviderName = "foo";
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void SqlCacheDependency1 ()
{
AccessPoker sql = new AccessPoker ();
Assert.AreEqual ("", sql.SqlCacheDependency, "A1");
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void SqlCacheDependency2 ()
{
AccessPoker sql = new AccessPoker ();
sql.SqlCacheDependency = "hi";
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ConnectionString1 ()
{
AccessPoker sql = new AccessPoker ();
sql.ConnectionString = "hi";
}
[Test]
public void ConnectionString2 ()
{
AccessPoker sql = new AccessPoker ();
sql.DataFile = "";
Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void ConnectionString3 ()
{
AccessPoker sql = new AccessPoker ();
sql.DataFile = "hi there";
Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A1");
}
#if notyet
// XXX enable this test once mono gets System.Data.OleDb.OleDbFactory
//
[Test]
public void ProviderFactory ()
{
AccessPoker sql = new AccessPoker ();
Assert.AreEqual (typeof (OleDbFactory), sql.GetFactory ().GetType());
}
#endif
[Test]
[Category ("NotWorking")]
public void Defaults ()
{
AccessPoker sql = new AccessPoker ();
Assert.AreEqual ("", sql.CacheKeyDependency, "A1");
Assert.IsTrue (sql.CancelSelectOnNullParameter, "A2");
Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A3");
Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "A5");
Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "A6");
Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A7");
Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A8");
// SqlCacheDependency access should raise an exception
// Assert.AreEqual ("", sql.SqlCacheDependency, "A9");
Assert.AreEqual ("", sql.SortParameterName, "A10");
Assert.AreEqual (0, sql.CacheDuration, "A11");
Assert.AreEqual (DataSourceCacheExpiry.Absolute, sql.CacheExpirationPolicy, "A12");
Assert.IsFalse (sql.EnableCaching, "A13");
Assert.AreEqual ("System.Data.OleDb", sql.ProviderName, "A14");
Assert.AreEqual ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=", sql.ConnectionString, "A15");
Assert.AreEqual (SqlDataSourceMode.DataSet, sql.DataSourceMode, "A16");
Assert.AreEqual ("", sql.DeleteCommand, "A17");
Assert.IsNotNull (sql.DeleteParameters, "A18");
Assert.AreEqual (0, sql.DeleteParameters.Count, "A18.1");
Assert.IsNotNull (sql.FilterParameters, "A19");
Assert.AreEqual (0, sql.FilterParameters.Count, "A19.1");
Assert.AreEqual ("", sql.InsertCommand, "A20");
Assert.IsNotNull (sql.InsertParameters, "A21");
Assert.AreEqual (0, sql.InsertParameters.Count, "A21.1");
Assert.AreEqual ("", sql.SelectCommand, "A22");
Assert.IsNotNull (sql.SelectParameters, "A23");
Assert.AreEqual (0, sql.SelectParameters.Count, "A23.1");
Assert.AreEqual ("", sql.UpdateCommand, "A24");
Assert.IsNotNull (sql.UpdateParameters, "A25");
Assert.AreEqual (0, sql.UpdateParameters.Count, "A25.1");
Assert.AreEqual ("", sql.FilterExpression, "A26");
Assert.AreEqual ("", sql.DataFile, "A27");
}
}
}
#endif

View File

@@ -0,0 +1,71 @@
//
// AdCreatedEventArgsCas.cs
// - CAS unit tests for System.Web.UI.WebControls.AdCreatedEventArgs
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Reflection;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class AdCreatedEventArgsCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
AdCreatedEventArgsTest unit = new AdCreatedEventArgsTest ();
unit.Defaults ();
unit.SetPropsInCtor ();
unit.SetProps ();
unit.ModifyProps ();
}
// LinkDemand
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[1] { typeof (IDictionary) });
Assert.IsNotNull (ci, ".ctor(IDictionary)");
return ci.Invoke (new object[1] { null });
}
public override Type Type {
get { return typeof (AdCreatedEventArgs); }
}
}
}

View File

@@ -0,0 +1,139 @@
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//
// System.Web.UI.WebControls.AdCreatedEventArgsTest.cs
//
// Author:
// Jackson Harper (jackson@ximian.com)
//
using System;
using System.Collections;
using System.Web.UI.WebControls;
using NUnit.Framework;
namespace MonoTests.System.Web.UI.WebControls {
[TestFixture]
public class AdCreatedEventArgsTest {
[Test]
public void Defaults ()
{
Hashtable table = new Hashtable ();
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
Assert.AreEqual (e.AdProperties, table, "Constructor");
e = new AdCreatedEventArgs (null);
Assert.AreEqual (e.AdProperties, null, "Null Constructor");
}
[Test]
public void SetPropsInCtor ()
{
Hashtable table = new Hashtable ();
table ["AlternateText"] = "alt text";
table ["ImageUrl"] = "image url";
table ["NavigateUrl"] = "nav url";
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
Assert.AreEqual (e.AlternateText, "alt text", "alt text");
Assert.AreEqual (e.ImageUrl, "image url", "image url");
Assert.AreEqual (e.NavigateUrl, "nav url", "nav url");
}
[Test]
public void SetProps ()
{
AdCreatedEventArgs e = new AdCreatedEventArgs (null);
e.AlternateText = "alt text";
Assert.AreEqual (e.AlternateText, "alt text", "alt text");
e.AlternateText = null;
Assert.AreEqual (e.AlternateText, null, "null alt text");
e.ImageUrl = "image url";
Assert.AreEqual (e.ImageUrl, "image url", "image url");
e.ImageUrl = null;
Assert.AreEqual (e.ImageUrl, null, "null image url");
e.NavigateUrl = "nav url";
Assert.AreEqual (e.NavigateUrl, "nav url", "nav url");
e.NavigateUrl = null;
Assert.AreEqual (e.NavigateUrl, null, "null nav url");
}
[Test]
public void ModifyProps ()
{
Hashtable table = new Hashtable ();
table ["AlternateText"] = "alt text";
table ["ImageUrl"] = "image url";
table ["NavigateUrl"] = "nav url";
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
e.AlternateText = "foo";
Assert.AreEqual (e.AdProperties ["AlternateText"],
"alt text", "alt text");
e.ImageUrl = "bar";
Assert.AreEqual (e.AdProperties ["ImageUrl"],
"image url", "image url");
e.NavigateUrl = "baz";
Assert.AreEqual (e.AdProperties ["NavigateUrl"],
"nav url", "nav url");
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void BadCastAlternateText ()
{
Hashtable table = new Hashtable ();
table ["AlternateText"] = 52;
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void BadCastImageUrl ()
{
Hashtable table = new Hashtable ();
table ["ImageUrl"] = 52;
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void BadCastNavigateUrl ()
{
Hashtable table = new Hashtable ();
table ["NavigateUrl"] = 52;
AdCreatedEventArgs e = new AdCreatedEventArgs (table);
}
}
}

View File

@@ -0,0 +1,153 @@
//
// Tests for System.Web.UI.WebControls.AutoGeneratedField.cs
//
// Author:
// Yoni Klein (yonik@mainsoft.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if NET_2_0
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using NUnit.Framework;
namespace MonoTests.System.Web.UI.WebControls
{
[TestFixture]
public class AutoGeneratedFieldTest
{
[Test]
public void AutoGeneratedField_DefaultProperty ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
Assert.AreEqual (true, field.ConvertEmptyStringToNull, "ConvertEmptyStringToNull");
Assert.AreEqual (string.Empty, field.DataFormatString, "DataFormatString");
Assert.AreEqual (true, field.InsertVisible, "InsertVisible");
}
[Test]
public void AutoGeneratedField_DefaultPropertyNotWorking ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
Assert.AreEqual (typeof (String), field.DataType, "DataType");
}
[Test]
public void AutoGeneratedField_AssignProperty ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
Assert.AreEqual ("test", field.DataField, "DataField");
field.DataType = typeof (bool);
Assert.AreEqual (typeof (bool), field.DataType, "DataType");
}
[Test]
public void AutoGeneratedField_ExtractValuesFromCell()
{
AutoGeneratedField field = new AutoGeneratedField ("field");
OrderedDictionary dictionary = new OrderedDictionary ();
DataControlFieldCell cell = new DataControlFieldCell (null);
cell.Text = "cell";
field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
Assert.AreEqual ("cell", dictionary[0].ToString (), "ExtractValuesFromCellValue");
}
[Test]
public void AutoGeneratedField_ExtractValuesFromCellCheckbox ()
{
// Aditional implementation for bollean data type
AutoGeneratedField field = new AutoGeneratedField ("field");
field.DataType = typeof (bool);
OrderedDictionary dictionary = new OrderedDictionary ();
DataControlFieldCell cell = new DataControlFieldCell(null);
cell.Controls.Add (new CheckBox ());
field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
Assert.AreEqual ("False", dictionary[0].ToString (), "ExtractValuesFromCellValue");
CheckBox cb = new CheckBox ();
cb.Checked = true;
cell.Controls.Clear ();
cell.Controls.Add (cb);
field.ExtractValuesFromCell (dictionary, cell, DataControlRowState.Normal, true);
Assert.AreEqual (1, dictionary.Count, "ExtractValuesFromCellCount");
Assert.AreEqual ("True", dictionary[0].ToString (), "ExtractValuesFromCellValue");
}
[Test]
public void AutoGeneratedField_ValidateSupportsCallback ()
{
//This method has been implemented as an empty method
}
[Test]
public void AutoGeneratedField_BoolArray () {
GridView GridView1 = new GridView ();
GridView1.DataSource = new bool [] { true };
GridView1.DataBind ();
}
[Test]
[ExpectedException(typeof(NotSupportedException))]
public void AutoGeneratedField_ConvertEmptyStringToNullExeption ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
field.ConvertEmptyStringToNull = false;
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void AutoGeneratedField_DataFormatStringExeption ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
field.DataFormatString = "test";
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void AutoGeneratedField_InsertVisibleExeption ()
{
AutoGeneratedField field = new AutoGeneratedField ("test");
field.InsertVisible = false;
}
}
}
#endif

View File

@@ -0,0 +1,84 @@
//
// BaseCompareValidatorCas.cs
// - CAS unit tests for System.Web.UI.WebControls.BaseCompareValidator
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class BaseCompareValidatorCas {
// note: we do not inherit from AspNetHostingMinimal because
// BaseCompareValidator is an abstract class
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
BaseCompareValidatorTest unit = new BaseCompareValidatorTest ();
unit.ViewState ();
unit.CanConvert ();
unit.Convert ();
unit.Compare ();
// can't call MiscPropertiesAndMethods because it change the
// thread's culture (which requires ControlThread)
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void MiscPropertiesAndMethods ()
{
BaseCompareValidatorPoker p = new BaseCompareValidatorPoker ();
Assert.AreEqual (p.GetCutoffYear (), 2029, "E1");
Assert.AreEqual (p.GetFullYear (29), 2029, "E2");
#if NET_2_0
Assert.AreEqual (p.GetFullYear (30), 1930, "E3");
#else
Assert.AreEqual (p.GetFullYear (30), 2030, "E3"); // XXX this is broken
#endif
Assert.IsNotNull (p.GetDateElementOrder (), "E4");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,68 @@
//
// BaseDataBoundControlCas.cs
// - CAS unit tests for System.Web.UI.WebControls.BaseDataBoundControl
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class BaseDataBoundControlCas {
// note: we do not inherit from AspNetHostingMinimal because
// BaseDataBoundControl is an abstract class
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
BaseDataBoundControlTest unit = new BaseDataBoundControlTest ();
unit.Defaults ();
unit.ViewState ();
}
}
}
#endif

View File

@@ -0,0 +1,201 @@
//
// Tests for System.Web.UI.WebControls.BaseDataBoundControl.cs
//
// Author:
// Chris Toshok (toshok@ximian.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace MonoTests.System.Web.UI.WebControls
{
[TestFixture]
public class BaseDataBoundControlTest {
class Poker : BaseDataBoundControl {
public bool OnDataPropertyChangedCalled;
public bool ValidateDataSourceCalled;
public Poker () {
TrackViewState ();
}
public object SaveState () {
return SaveViewState ();
}
public void LoadState (object state) {
LoadViewState (state);
}
protected override void PerformSelect ()
{
Assert.IsTrue (RequiresDataBinding);
//Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
}
protected override void ValidateDataSource (object dataSource)
{
ValidateDataSourceCalled = true;
//Console.WriteLine ("PerformSelect\n{0}", Environment.StackTrace);
}
public bool GetIsBoundUsingDataSourceID ()
{
return IsBoundUsingDataSourceID;
}
public bool GetInitialized ()
{
return Initialized;
}
protected override void OnDataPropertyChanged () {
base.OnDataPropertyChanged ();
OnDataPropertyChangedCalled = true;
}
public void SetRequiresDataBinding (bool val)
{
RequiresDataBinding = val;
}
public bool GetRequiresDataBinding ()
{
return RequiresDataBinding;
}
public override void DataBind ()
{
Assert.IsTrue (RequiresDataBinding);
base.DataBind ();
Assert.IsTrue (RequiresDataBinding);
}
public void DoEnsureDataBound ()
{
Assert.IsTrue (RequiresDataBinding);
EnsureDataBound ();
Assert.IsTrue (RequiresDataBinding);
}
}
[Test]
public void Defaults ()
{
Poker p = new Poker ();
Assert.IsNull (p.DataSource, "A1");
Assert.AreEqual ("", p.DataSourceID, "A2");
Assert.IsFalse (p.GetIsBoundUsingDataSourceID(), "A3");
Assert.IsFalse (p.GetInitialized(), "A4");
}
[Test]
public void ViewState ()
{
Poker p = new Poker ();
Poker copy = new Poker ();
p.DataSourceID = "hi";
object state = p.SaveState ();
copy.LoadState (state);
Assert.AreEqual ("hi", copy.DataSourceID, "A1");
}
[Test]
public void OnDataPropertyChanged ()
{
Poker p = new Poker ();
Assert.IsFalse (p.OnDataPropertyChangedCalled);
p.DataSourceID = "hi";
Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSourceID");
}
[Test]
public void OnDataPropertyChanged2 ()
{
Poker p = new Poker ();
Assert.IsFalse (p.OnDataPropertyChangedCalled);
p.DataSource = null;
Assert.IsTrue (p.OnDataPropertyChangedCalled, "OnDataPropertyChanged: DataSource");
}
[Test]
public void DataBind ()
{
Poker p = new Poker ();
p.DataSourceID = "DataSourceID";
p.SetRequiresDataBinding (true);
p.DataBind ();
}
[Test]
public void EnsureDataBound ()
{
Poker p = new Poker ();
p.DataSourceID = "DataSourceID";
p.SetRequiresDataBinding (true);
p.DoEnsureDataBound ();
}
[Test]
public void DataSource_ValidateDataSource ()
{
Poker p = new Poker ();
p.DataSource = null;
Assert.AreEqual (false, p.ValidateDataSourceCalled);
p.DataSource = new Object();
Assert.AreEqual (true, p.ValidateDataSourceCalled);
}
#if NET_4_0
[Test]
public void SupportsDisabledAttribute ()
{
var ver40 = new Version (4, 0);
var ver35 = new Version (3, 5);
var p = new Poker ();
Assert.AreEqual (ver40, p.RenderingCompatibility, "#A1-1");
Assert.IsFalse (p.SupportsDisabledAttribute, "#A1-2");
p.RenderingCompatibility = new Version (3, 5);
Assert.AreEqual (ver35, p.RenderingCompatibility, "#A2-1");
Assert.IsTrue (p.SupportsDisabledAttribute, "#A2-2");
}
#endif
}
}
#endif

View File

@@ -0,0 +1,91 @@
//
// BaseDataListCas.cs
// - CAS unit tests for System.Web.UI.WebControls.BaseDataList
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class BaseDataListCas {
// note: we do not inherit from AspNetHostingMinimal because
// BaseDataList is an abstract class
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
BaseDataListTest unit = new BaseDataListTest ();
unit.DefaultProperties ();
unit.NullProperties ();
unit.CleanProperties ();
unit.TableCaption ();
unit.DataSource_IEnumerable ();
unit.DataSource_IListSource ();
unit.AddParsedSubObject ();
unit.Render_Empty ();
unit.Render ();
unit.Events ();
unit.OnDataBinding ();
#if NET_2_0
unit.DataSourceID ();
unit.EnsureDataBound_WithoutDataSourceID ();
unit.EnsureDataBound_WithDataSourceID ();
unit.GetData ();
unit.GetData_WithoutDataSourceID ();
unit.OnDataBinding_True ();
unit.OnDataBinding_False ();
unit.OnDataPropertyChanged ();
unit.OnInit ();
unit.OnDataSourceViewChanged ();
unit.OnLoad_WithoutPage ();
unit.OnLoad_WithoutPageWithoutViewState ();
unit.OnLoad_WithPage ();
unit.OnLoad_WithPageWithoutViewState ();
unit.OnLoad_WithDataSource ();
#endif
unit.IsBindableType ();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,108 @@
//
// BaseValidatorCas.cs
// - CAS unit tests for System.Web.UI.WebControls.BaseValidator
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class BaseValidatorCas {
// note: we do not inherit from AspNetHostingMinimal because
// BaseValidator is an abstract class
[SetUp]
public virtual void SetUp ()
{
if (!SecurityManager.SecurityEnabled)
Assert.Ignore ("SecurityManager.SecurityEnabled is OFF");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
BaseValidatorTest unit = new BaseValidatorTest ();
unit.ViewState ();
unit.ControlPropertiesValid1 ();
unit.CustomDescriptor ();
unit.NoCustomDescriptor ();
}
[Test]
[AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
[ExpectedException (typeof (TargetInvocationException))]
public void ValidationProperty_Deny_Minimal ()
{
BaseValidatorTest unit = new BaseValidatorTest ();
unit.ValidationProperty ();
// note: this is a failing security check on reflection,
// the SecurityException is the InnerException of the
// TargetInvocationException
}
[Test]
[AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
public void ValidationProperty_PermitOnly_Minimal ()
{
BaseValidatorTest unit = new BaseValidatorTest ();
unit.ValidationProperty ();
}
[Test]
[AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
[ExpectedException (typeof (TargetInvocationException))]
public void GetControlValidationValue_Deny_Minimal ()
{
BaseValidatorTest unit = new BaseValidatorTest ();
unit.GetControlValidationValue ();
// note: this is a failing security check on reflection,
// the SecurityException is the InnerException of the
// TargetInvocationException
}
[Test]
[AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
public void GetControlValidationValue_PermitOnly_Minimal ()
{
BaseValidatorTest unit = new BaseValidatorTest ();
unit.GetControlValidationValue ();
}
}
}

View File

@@ -0,0 +1,343 @@
//
// Tests for System.Web.UI.WebControls.BaseValidator
//
// Author:
// Chris Toshok (toshok@novell.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.ComponentModel;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Alternate;
namespace Alternate {
[ValidationProperty ("SomeProperty")]
class MyTextBox : ICustomTypeDescriptor {
public string SomeProperty {
get { return null; }
set {}
}
public System.ComponentModel.AttributeCollection GetAttributes ()
{
// This one is called and then GetProperties
//Console.WriteLine ("GetAttributes ");
return TypeDescriptor.GetAttributes (this, true);
}
public string GetClassName()
{
//Console.WriteLine ("GetClassName");
return TypeDescriptor.GetClassName (this, true);
}
public string GetComponentName()
{
//Console.WriteLine ("GetComponentName");
return TypeDescriptor.GetComponentName (this, true);
}
public TypeConverter GetConverter()
{
//Console.WriteLine ("GetConverter");
return TypeDescriptor.GetConverter (this, true);
}
public EventDescriptor GetDefaultEvent()
{
//Console.WriteLine ("GetDefaultEvent");
return TypeDescriptor.GetDefaultEvent (this, true);
}
public PropertyDescriptor GetDefaultProperty()
{
//Console.WriteLine ("GetDefaultProperty");
return TypeDescriptor.GetDefaultProperty (this, true);
}
public object GetEditor(Type editorBaseType)
{
//Console.WriteLine ("GetEditor (editorBaseType");
return null;
}
public EventDescriptorCollection GetEvents()
{
//Console.WriteLine ("GetEvents");
return TypeDescriptor.GetEvents (this, true);
}
public EventDescriptorCollection GetEvents(Attribute[] arr)
{
//Console.WriteLine ("GetEvents");
return TypeDescriptor.GetEvents (arr, true);
}
public PropertyDescriptorCollection GetProperties()
{
//Console.WriteLine ("GetProperties");
return TypeDescriptor.GetProperties (this, true);
}
public PropertyDescriptorCollection GetProperties(Attribute[] arr)
{
//Console.WriteLine ("GetProperties");
return TypeDescriptor.GetProperties (this, arr, true);
}
public object GetPropertyOwner(PropertyDescriptor pd)
{
//Console.WriteLine ("GetPropertyOwner (pd)");
return null;
}
}
}
namespace MonoTests.System.Web.UI.WebControls
{
class BaseValidatorPoker : BaseValidator {
public BaseValidatorPoker ()
{
TrackViewState ();
}
public object SaveState ()
{
return SaveViewState ();
}
public void LoadState (object o)
{
LoadViewState (o);
}
public void CheckControlProperties ()
{
ControlPropertiesValid ();
}
protected override bool EvaluateIsValid ()
{
return IsValid;
}
public new PropertyDescriptor GetValidationProperty (object o)
{
return BaseValidator.GetValidationProperty (o);
}
public string DoGetControlValidationValue (string name)
{
return GetControlValidationValue (name);
}
public virtual bool DoControlPropertiesValid ()
{
return ControlPropertiesValid ();
}
public void DoCheckControlValidationProperty (string name, string propertyName)
{
CheckControlValidationProperty (name, propertyName);
}
}
[TestFixture]
public class BaseValidatorTest : ValidatorTest {
[Test]
public void ViewState ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
/* defaults */
Assert.AreEqual (String.Empty, p.ControlToValidate, "D1");
Assert.AreEqual (ValidatorDisplay.Static, p.Display, "D2");
Assert.AreEqual (true, p.EnableClientScript, "D3");
Assert.AreEqual (true, p.Enabled, "D4");
Assert.AreEqual (String.Empty, p.ErrorMessage, "D5");
Assert.AreEqual (Color.Red, p.ForeColor, "D6");
Assert.AreEqual (true, p.IsValid, "D7");
/* get/set */
p.ControlToValidate = "foo";
Assert.AreEqual ("foo", p.ControlToValidate, "D8");
p.Display = ValidatorDisplay.Dynamic;
Assert.AreEqual (ValidatorDisplay.Dynamic, p.Display, "D9");
p.EnableClientScript = false;
Assert.AreEqual (false, p.EnableClientScript, "D9");
p.Enabled = false;
Assert.AreEqual (false, p.Enabled, "D10");
p.ErrorMessage = "stupid monkey";
Assert.AreEqual ("stupid monkey", p.ErrorMessage, "D11");
p.ForeColor = Color.Blue;
Assert.AreEqual (Color.Blue, p.ForeColor, "D12");
//XXX add check to see if setting the color alters the style at all.
p.IsValid = false;
Assert.AreEqual (false, p.IsValid, "D13");
}
[Test]
public void ValidationProperty ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
PropertyDescriptor d;
StartValidationTest (p);
TextBox box = AddTextBox ("textbox", "hello world");
d = p.GetValidationProperty (box);
Assert.AreEqual ("Text", d.Name, "A1");
Assert.AreEqual ("hello world", p.DoGetControlValidationValue ("textbox"), "A2");
StopValidationTest ();
}
[Test]
public void ControlPropertiesValid1 ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
StartValidationTest (p);
TextBox box = SetValidationTextBox ("textbox", "hello world");
Assert.IsTrue (p.DoControlPropertiesValid (), "B1");
StopValidationTest ();
}
[Test]
public void NullValidationProperty ()
{
BaseValidatorPoker v = new BaseValidatorPoker ();
Page p = new Page ();
p.Controls.Add (v);
RadioButtonList l = new RadioButtonList ();
p.Controls.Add (l);
l.ID = "XXX";
v.ControlToValidate = "XXX";
Assert.AreEqual (String.Empty, v.DoGetControlValidationValue ("XXX"), "#A1");
}
[Test]
[ExpectedException (typeof (HttpException))]
public void ControlPropertiesValid2 ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
StartValidationTest (p);
TextBox box = AddTextBox ("textbox", "hello world");
/* successful */
p.DoCheckControlValidationProperty ("textbox", "Text");
/* failure (exception) due to unknown control */
p.DoCheckControlValidationProperty ("textbox2", "Text");
StopValidationTest ();
}
[Test]
[ExpectedException (typeof (HttpException))]
public void ControlPropertiesValid3 ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
StartValidationTest (p);
p.ControlToValidate = "textbox";
/* failure (exception) due to unknown control */
p.DoCheckControlValidationProperty ("textbox", "Text2");
StopValidationTest ();
}
[Test]
[ExpectedException(typeof(HttpException))]
public void BasicExceptionTest () {
BaseValidatorPoker p = new BaseValidatorPoker ();
p.CheckControlProperties();
}
[Test]
public void GetControlValidationValue ()
{
BaseValidatorPoker p = new BaseValidatorPoker ();
StartValidationTest (p);
TextBox box = AddTextBox ("textbox", "hello world");
Label label = new Label ();
label.ID = "label";
Page.Controls.Add (label);
/* successful */
Assert.AreEqual ("hello world", p.DoGetControlValidationValue ("textbox"), "C1");
/* failure (non-existant control)*/
Assert.IsNull (p.DoGetControlValidationValue ("textbox2"), "C2");
/* failure (control without a ValidationProperty */
Assert.IsNull (p.DoGetControlValidationValue ("label"), "C3");
StopValidationTest ();
}
[Test]
public void CustomDescriptor ()
{
PropertyDescriptor pd = BaseValidator.GetValidationProperty (new MyTextBox ());
Assert.AreEqual ("SomeProperty", pd.Name);
}
[Test]
public void NoCustomDescriptor ()
{
PropertyDescriptor pd = BaseValidator.GetValidationProperty (new TextBox ());
Assert.AreEqual ("Text", pd.Name);
}
}
}

View File

@@ -0,0 +1,62 @@
//
// BoundColumnCas.cs
// - CAS unit tests for System.Web.UI.WebControls.BoundColumn
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class BoundColumnCas : AspNetHostingMinimal {
// note: we do not inherit from AspNetHostingMinimal because
// BaseValidator is an abstract class
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
BoundColumnTest unit = new BoundColumnTest ();
unit.FormatDataValue ();
}
// LinkDemand
public override Type Type {
get { return typeof (BoundColumn); }
}
}
}

View File

@@ -0,0 +1,80 @@
//
// BoundColumnTest.cs
//
// Author:
// Jackson Harper (jackson@ximian.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Diagnostics;
using System.Web.UI.WebControls;
namespace MonoTests.System.Web.UI.WebControls {
public class BoundColumnPoker : BoundColumn {
public string FormatData (object data)
{
return FormatDataValue (data);
}
}
[TestFixture]
public class BoundColumnTest {
[Test]
public void FormatDataValue ()
{
BoundColumnPoker p = new BoundColumnPoker ();
p.DataFormatString = String.Empty;
p.Initialize ();
Assert.AreEqual ("test", p.FormatData ("test"), "A1");
p.DataFormatString = "{0} hello";
p.Initialize ();
Assert.AreEqual ("test hello", p.FormatData ("test"), "A2");
p.DataFormatString = "{0}";
p.Initialize ();
Assert.AreEqual ("test", p.FormatData ("test"), "A3");
p.DataFormatString = "{0}";
p.Initialize ();
Assert.AreEqual (String.Empty, p.FormatData (String.Empty), "A4");
p.DataFormatString = "{0}";
p.Initialize ();
p.DataFormatString = "i am bad";
Assert.AreEqual ("foo", p.FormatData ("foo"), "A5");
p.DataFormatString = "{0}";
p.Initialize ();
Assert.AreEqual (String.Empty, p.FormatData (null), "A6");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,408 @@
//
// Tests for System.Web.UI.WebControls.BulletedList.cs
//
// Author:
// Yoni Klein (yonik@mainsoft.com)
// Merav Sudri(meravs@mainsoft.com)
// Tal Klahr (talk@mainsoft.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using NUnit.Framework;
using System;
using System.Collections;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MonoTests.SystemWeb.Framework;
using MonoTests.stand_alone.WebHarness;
namespace MonoTests.System.Web.UI.WebControls
{
class PokerBulletedList : BulletedList
{
public PokerBulletedList ()
{
TrackViewState ();
}
public object SaveState ()
{
return SaveViewState ();
}
public void LoadState (object o)
{
LoadViewState (o);
}
public StateBag StateBag
{
get { return base.ViewState; }
}
public string Render ()
{
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
tw.NewLine = "\n";
Render (tw);
return sw.ToString ();
}
public void DoRenderContents (HtmlTextWriter tw)
{
RenderContents (tw);
}
public void DoRenderBulletText (ListItem item, int index, HtmlTextWriter tw)
{
RenderBulletText (item, index, tw);
}
public void DoOnClick (BulletedListEventArgs e)
{
OnClick (e);
}
}
class VerifyMultiSelectBulletedList : BulletedList
{
public new virtual void VerifyMultiSelect()
{
base.VerifyMultiSelect();
}
}
[TestFixture]
public class BulletedListTest
{
[TestFixtureSetUp]
public void SetUp ()
{
WebTest.CopyResource (GetType (), "NoEventValidation.aspx", "NoEventValidation.aspx");
}
[Test]
public void BulletedList_DefaultProperties ()
{
PokerBulletedList b = new PokerBulletedList ();
Assert.AreEqual (0, b.StateBag.Count, "ViewState.Count");
Assert.AreEqual (string.Empty, b.BulletImageUrl, "BulletImageUrl");
Assert.AreEqual (BulletStyle.NotSet, b.BulletStyle, "BulletStyle");
EmptyControlCollection c = new EmptyControlCollection (b);
EmptyControlCollection c2 = (EmptyControlCollection) b.Controls;
Assert.AreEqual ("System.Web.UI.EmptyControlCollection", b.Controls.GetType ().ToString (), "Controls");
Assert.AreEqual ("Text", b.DisplayMode.ToString (), "DisplayMode");
Assert.AreEqual (1, b.FirstBulletNumber, "FirstBulletNumber");
Assert.AreEqual (-1, b.SelectedIndex, "SelectedIndex");
Assert.AreEqual (null, b.SelectedItem, "SelectedItem");
Assert.AreEqual (string.Empty, b.Target, "Target");
}
[Test]
public void BulletedList_DefaultPropertiesNotWorking ()
{
PokerBulletedList b = new PokerBulletedList ();
Assert.AreEqual (string.Empty, b.SelectedValue, "SelectedValue"); // NotImplementedException on Mono
Assert.AreEqual (string.Empty, b.Text, "Text");
}
[Test]
public void BulletedList_AssignToDefaultProperties ()
{
PokerBulletedList b = new PokerBulletedList ();
Assert.AreEqual (0, b.StateBag.Count, "ViewState.Count");
b.BulletImageUrl = "Images/edit.gif";
Assert.AreEqual ("Images/edit.gif", b.BulletImageUrl, "BulletImageUrl");
b.BulletStyle = BulletStyle.Numbered;
Assert.AreEqual (BulletStyle.Numbered, b.BulletStyle, "BulletStyle");
b.BulletStyle = BulletStyle.LowerAlpha;
Assert.AreEqual (BulletStyle.LowerAlpha, b.BulletStyle, "BulletStyle");
b.BulletStyle = BulletStyle.CustomImage;
Assert.AreEqual (BulletStyle.CustomImage, b.BulletStyle, "BulletStyle");
b.BulletStyle = BulletStyle.Square;
Assert.AreEqual (BulletStyle.Square, b.BulletStyle, "BulletStyle");
b.DisplayMode = BulletedListDisplayMode.HyperLink;
Assert.AreEqual (BulletedListDisplayMode.HyperLink, b.DisplayMode, "DisplayMode");
b.FirstBulletNumber = 4;
Assert.AreEqual (4, b.FirstBulletNumber, "FirstBulletNumber");
b.Target = "_search";
Assert.AreEqual ("_search", b.Target, "Target_search");
b.Target = "_top";
Assert.AreEqual ("_top", b.Target, "Target_top");
b.Target = "_parent";
Assert.AreEqual ("_parent", b.Target, "Target_parent");
b.Target = "_blank";
Assert.AreEqual ("_blank", b.Target, "Target_blank");
b.Target = "_self";
Assert.AreEqual ("_self", b.Target, "Target_self");
}
[Test]
public void BulletedList_NullProperties ()
{
PokerBulletedList b = new PokerBulletedList ();
Assert.AreEqual (0, b.StateBag.Count, "ViewState.Count");
b.BulletImageUrl = null;
Assert.AreEqual (string.Empty, b.BulletImageUrl, "BulletImageUrl");
b.Target = null;
Assert.AreEqual (string.Empty, b.Target, "Target");
}
[Test]
public void BulletedList_BulletStyle_Render ()
{
PokerBulletedList b = new PokerBulletedList ();
AddListItems (b);
Assert.AreEqual (b.Render (), "<ul>\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "Render1");
b.BulletStyle = BulletStyle.Square;
Assert.AreEqual (b.Render (), "<ul style=\"list-style-type:square;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "BulletStyle.Square");
b.BulletStyle = BulletStyle.LowerRoman;
Assert.AreEqual (b.Render (), "<ol style=\"list-style-type:lower-roman;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "BulletStyle.LowerRoman");
b.BulletStyle = BulletStyle.Circle;
Assert.AreEqual (b.Render (), "<ul style=\"list-style-type:circle;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "BulletStyle.Circle");
b.BulletStyle = BulletStyle.Disc;
Assert.AreEqual (b.Render (), "<ul style=\"list-style-type:disc;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "BulletStyle.Disc");
b.BulletStyle = BulletStyle.LowerAlpha;
Assert.AreEqual (b.Render (), "<ol style=\"list-style-type:lower-alpha;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "BulletStyle.LowerAlpha");
b.BulletStyle = BulletStyle.Numbered;
Assert.AreEqual (b.Render (), "<ol style=\"list-style-type:decimal;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "BulletStyle.Numbered");
b.BulletStyle = BulletStyle.UpperAlpha;
Assert.AreEqual (b.Render (), "<ol style=\"list-style-type:upper-alpha;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "BulletStyle.UpperAlpha");
b.BulletStyle = BulletStyle.UpperRoman;
Assert.AreEqual (b.Render (), "<ol style=\"list-style-type:upper-roman;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "BulletStyle.UpperRoman");
b.BulletStyle = BulletStyle.NotSet;
Assert.AreEqual (b.Render (), "<ul>\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "BulletStyle.NotSet");
b.BulletStyle = BulletStyle.CustomImage;
b.BulletImageUrl = "Images/edit.gif";
Assert.AreEqual (b.Render (), "<ul style=\"list-style-image:url(Images/edit.gif);\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ul>", "BulletStyle.CustomImage");
}
[Test]
public void BulletedList_HyperLinkDisplayMode_Render ()
{
PokerBulletedList b = new PokerBulletedList ();
ListItem item1 = new ListItem ("HyperLink1", "TextFile1.txt");
ListItem item2 = new ListItem ("HyperLink2", "TextFile2.txt");
b.Items.Add (item1);
b.Items.Add (item2);
b.DisplayMode = BulletedListDisplayMode.HyperLink;
Assert.AreEqual (b.Render (), "<ul>\n\t<li><a href=\"TextFile1.txt\">HyperLink1</a></li><li><a href=\"TextFile2.txt\">HyperLink2</a></li>\n</ul>", "BulletedListDisplayMode.HyperLink");
}
[Test]
public void BulletedList_ButtonLinkDisplayMode_Render ()
{
PokerBulletedList b = new PokerBulletedList ();
AddListItems (b);
b.DisplayMode = BulletedListDisplayMode.LinkButton;
b.ID = "BulletedListTest";
Page p = new Page ();
p.Controls.Add (b);
p.EnableEventValidation = false;
string html = b.Render ();
MonoTests.stand_alone.WebHarness.HtmlDiff.AssertAreEqual (b.Render (), "<ul id=\"BulletedListTest\">\n\t<li><a href=\"javascript:__doPostBack('BulletedListTest','0')\">Item1</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','1')\">Item2</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','2')\">Item3</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','3')\">Item4</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','4')\">Item5</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','5')\">Item6</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','6')\">Item7</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','7')\">Item8</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','8')\">Item9</a></li><li><a href=\"javascript:__doPostBack('BulletedListTest','9')\">Item10</a></li>\n</ul>", "BulletedListDisplayMode.LinkButton");
}
[Test]
public void BulletedList_FirstBulletNumber_Render ()
{
PokerBulletedList b = new PokerBulletedList ();
AddListItems (b);
b.BulletStyle = BulletStyle.Numbered;
b.FirstBulletNumber = 3;
Assert.AreEqual (b.Render (), "<ol start=\"3\" style=\"list-style-type:decimal;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "FirstBulletNumber1");
b.FirstBulletNumber = 6;
Assert.AreEqual (b.Render (), "<ol start=\"6\" style=\"list-style-type:decimal;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "FirstBulletNumber2");
b.FirstBulletNumber = -2;
Assert.AreEqual (b.Render (), "<ol start=\"-2\" style=\"list-style-type:decimal;\">\n\t<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>\n</ol>", "FirstBulletNumber3");
}
[Test]
public void BulletedList_ViewState ()
{
PokerBulletedList b = new PokerBulletedList ();
b.BulletImageUrl = "Images/edit.gif";
Assert.AreEqual ("Images/edit.gif", b.BulletImageUrl, "ViewState1");
b.BulletStyle = BulletStyle.Numbered;
Assert.AreEqual (BulletStyle.Numbered, b.BulletStyle, "ViewState2");
b.Target = "_search";
Assert.AreEqual ("_search", b.Target, "ViewState3");
b.DisplayMode = BulletedListDisplayMode.HyperLink;
Assert.AreEqual (BulletedListDisplayMode.HyperLink, b.DisplayMode, "ViewState4");
b.FirstBulletNumber = 5;
Assert.AreEqual (5, b.FirstBulletNumber, "ViewState5");
object state = b.SaveState ();
PokerBulletedList copy = new PokerBulletedList ();
copy.LoadState (state);
Assert.AreEqual ("Images/edit.gif", b.BulletImageUrl, "ViewState6");
Assert.AreEqual (BulletStyle.Numbered, b.BulletStyle, "ViewState7");
Assert.AreEqual ("_search", b.Target, "ViewState8");
Assert.AreEqual (BulletedListDisplayMode.HyperLink, b.DisplayMode, "ViewState9");
Assert.AreEqual (5, b.FirstBulletNumber, "ViewState10");
}
//Protected Methods
[Test]
public void BulletedList_RenderContents ()
{
PokerBulletedList p = new PokerBulletedList ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
AddListItems (p);
p.DoRenderContents (tw);
Assert.AreEqual (sw.ToString (), "<li>Item1</li><li>Item2</li><li>Item3</li><li>Item4</li><li>Item5</li><li>Item6</li><li>Item7</li><li>Item8</li><li>Item9</li><li>Item10</li>", "BulletedList_RenderContents");
}
[Test]
public void BulletedList_RenderBulletText ()
{
PokerBulletedList p = new PokerBulletedList ();
StringWriter sw = new StringWriter ();
HtmlTextWriter tw = new HtmlTextWriter (sw);
AddListItems (p);
p.DoRenderBulletText (p.Items[0], 0, tw);
Assert.AreEqual (sw.ToString (), "Item1", "BulletedList_RenderBulletText1");
p.DoRenderBulletText (p.Items[5], 5, tw);
Assert.AreEqual (sw.ToString (), "Item1Item6", "BulletedList_RenderBulletText2");
}
//Events
private bool clicked = false;
private void BulletedListClickHandler (object sender, BulletedListEventArgs e)
{
clicked = true;
}
private void ResetEvents ()
{
clicked = false;
}
[Test]
public void BulletedList_Events ()
{
PokerBulletedList pb = new PokerBulletedList ();
AddListItems (pb);
ResetEvents ();
pb.Click += new BulletedListEventHandler (BulletedListClickHandler);
Assert.AreEqual (false, clicked, "BeforeClick");
pb.DoOnClick (new BulletedListEventArgs (0));
Assert.AreEqual (true, clicked, "BeforeClick");
}
//PostBack raise event
[Test]
[Category ("NunitWeb")]
public void BulletedList_PostBackEvent ()
{
WebTest t = new WebTest ("NoEventValidation.aspx");
t.Invoker = PageInvoker.CreateOnInit (new PageDelegate (_PostBackEvent));
string html = t.Run ();
if (html.IndexOf ("Test_Item") < 0)
Assert.Fail ("BulletedList not created");
FormRequest fr = new FormRequest (t.Response, "form1");
fr.Controls.Add ("__EVENTTARGET");
fr.Controls.Add ("__EVENTARGUMENT");
fr.Controls["__EVENTTARGET"].Value = "BL";
fr.Controls["__EVENTARGUMENT"].Value = "0";
t.Request = fr;
html = t.Run ();
if (t.UserData == null || (string) t.UserData != "list_Click Fired_0")
Assert.Fail ("list_Click Not Fired");
}
#region _PostBackEvent_helper
public static void _PostBackEvent (Page p)
{
BulletedList list = new BulletedList ();
list.ID = "BL";
list.DisplayMode = BulletedListDisplayMode.LinkButton;
list.Items.Add (new ListItem ("Test_Item", "Test_Value", true));
list.Click += new BulletedListEventHandler (list_Click);
p.Controls.Add (list);
}
static void list_Click (object sender, BulletedListEventArgs e)
{
WebTest.CurrentTest.UserData = "list_Click Fired_" + e.Index.ToString();
}
#endregion
[Test]
[ExpectedException (typeof (HttpException))]
public void VerifyMultiSelectTest ()
{
VerifyMultiSelectBulletedList list = new VerifyMultiSelectBulletedList ();
list.VerifyMultiSelect ();
}
[TestFixtureTearDown]
public void TearDown ()
{
WebTest.Unload ();
}
// Help class for DS creation
private void AddListItems (PokerBulletedList b)
{
ListItem item1 = new ListItem ("Item1", "Item1");
ListItem item2 = new ListItem ("Item2", "Item2");
ListItem item3 = new ListItem ("Item3", "Item3");
ListItem item4 = new ListItem ("Item4", "Item4");
ListItem item5 = new ListItem ("Item5", "Item5");
ListItem item6 = new ListItem ("Item6", "Item6");
ListItem item7 = new ListItem ("Item7", "Item7");
ListItem item8 = new ListItem ("Item8", "Item8");
ListItem item9 = new ListItem ("Item9", "Item9");
ListItem item10 = new ListItem ("Item10", "Item10");
b.Items.Add (item1);
b.Items.Add (item2);
b.Items.Add (item3);
b.Items.Add (item4);
b.Items.Add (item5);
b.Items.Add (item6);
b.Items.Add (item7);
b.Items.Add (item8);
b.Items.Add (item9);
b.Items.Add (item10);
}
}
}
#endif

View File

@@ -0,0 +1,60 @@
//
// ButtonColumnCas.cs
// - CAS unit tests for System.Web.UI.WebControls.ButtonColumn
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web.UI.WebControls;
using MonoTests.System.Web.UI.WebControls;
namespace MonoCasTests.System.Web.UI.WebControls {
[TestFixture]
[Category ("CAS")]
public class ButtonColumnCas : AspNetHostingMinimal {
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Deny_Unrestricted ()
{
ButtonColumnTest unit = new ButtonColumnTest ();
unit.FormatDataValue ();
}
// LinkDemand
public override Type Type {
get { return typeof (ButtonColumn); }
}
}
}

View File

@@ -0,0 +1,104 @@
//
// ButtonColumnTest.cs
//
// Author:
// Jackson Harper (jackson@ximian.com)
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Collections;
using System.Diagnostics;
using System.Web.UI.WebControls;
namespace MonoTests.System.Web.UI.WebControls {
public class ButtonColumnPoker : ButtonColumn {
public string FormatData (object data)
{
return FormatDataTextValue (data);
}
}
[TestFixture]
public class ButtonColumnTest {
[Test]
public void Defaults ()
{
ButtonColumn bc = new ButtonColumn ();
#if NET_2_0
Assert.AreEqual ("", bc.ValidationGroup, "ValidationGroup");
Assert.AreEqual (false, bc.CausesValidation, "CausesValidation");
#endif
}
[Test]
public void AssignedProperties ()
{
ButtonColumn bc = new ButtonColumn ();
#if NET_2_0
Assert.AreEqual ("", bc.ValidationGroup, "ValidationGroup#1");
bc.ValidationGroup = "test";
Assert.AreEqual ("test", bc.ValidationGroup, "ValidationGroup#2");
Assert.AreEqual (false, bc.CausesValidation, "CausesValidation#1");
bc.CausesValidation = true;
Assert.AreEqual (true, bc.CausesValidation, "CausesValidation#2");
#endif
}
[Test]
public void FormatDataValue ()
{
ButtonColumnPoker p = new ButtonColumnPoker ();
p.DataTextFormatString = String.Empty;
p.Initialize ();
Assert.AreEqual ("test", p.FormatData ("test"), "A1");
p.DataTextFormatString = "{0} hello";
p.Initialize ();
Assert.AreEqual ("test hello", p.FormatData ("test"), "A2");
p.DataTextFormatString = "{0}";
p.Initialize ();
Assert.AreEqual ("test", p.FormatData ("test"), "A3");
p.DataTextFormatString = "{0}";
p.Initialize ();
Assert.AreEqual (String.Empty, p.FormatData (String.Empty), "A4");
p.DataTextFormatString = "{0}";
p.Initialize ();
p.DataTextFormatString = "i am bad";
Assert.AreEqual ("i am bad", p.FormatData ("foo"), "A5");
p.DataTextFormatString = "{0}";
p.Initialize ();
Assert.AreEqual (String.Empty, p.FormatData (null), "A6");
}
}
}

View File

@@ -0,0 +1,130 @@
//
// Tests for System.Web.UI.WebControls.ButtonFieldBaseTest.cs
//
// Author:
// Yoni Klein (yonik@mainsoft.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if NET_2_0
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using NUnit.Framework;
using System.Data;
namespace MonoTests.System.Web.UI.WebControls
{
class PokerButtonFieldBase : ButtonFieldBase
{
// View state Stuff
public PokerButtonFieldBase ()
: base ()
{
TrackViewState ();
}
public object SaveState ()
{
return SaveViewState ();
}
public void LoadState (object o)
{
LoadViewState (o);
}
public StateBag StateBag
{
get { return base.ViewState; }
}
protected override DataControlField CreateField ()
{
throw new Exception ("The method or operation is not implemented.");
}
public void DoCopyProperties (DataControlField newField)
{
base.CopyProperties (newField);
}
}
[TestFixture]
public class ButtonFieldBaseTest
{
[Test]
public void ButtonFieldBase_DefaultProperty ()
{
PokerButtonFieldBase button = new PokerButtonFieldBase ();
Assert.AreEqual (ButtonType.Link, button.ButtonType, "ButtonType");
Assert.AreEqual (false, button.CausesValidation, "CausesValidation");
Assert.AreEqual (false, button.ShowHeader, "ShowHeader");
Assert.AreEqual ("", button.ValidationGroup, "ValidationGroup");
}
[Test]
public void ButtonFieldBase_AssignProperty ()
{
PokerButtonFieldBase button = new PokerButtonFieldBase ();
button.ButtonType = ButtonType.Image;
Assert.AreEqual (ButtonType.Image, button.ButtonType, "ButtonType");
button.CausesValidation = true;
Assert.AreEqual (true, button.CausesValidation, "CausesValidation");
button.ShowHeader = true;
Assert.AreEqual (true, button.ShowHeader, "ShowHeader");
button.ValidationGroup = "test";
Assert.AreEqual ("test", button.ValidationGroup, "ValidationGroup");
}
[Test]
public void ButtonFieldBase_CopyProperties ()
{
PokerButtonFieldBase button = new PokerButtonFieldBase ();
PokerButtonFieldBase copy = new PokerButtonFieldBase ();
button.ButtonType = ButtonType.Image;
button.CausesValidation = true;
button.ShowHeader = true;
button.ValidationGroup = "test";
button.DoCopyProperties (copy);
Assert.AreEqual ("test", copy.ValidationGroup, "ValidationGroup");
Assert.AreEqual (ButtonType.Image, copy.ButtonType, "ButtonType");
Assert.AreEqual (true, copy.CausesValidation, "CausesValidation");
Assert.AreEqual (true, copy.ShowHeader, "ShowHeader");
}
}
}
#endif

View File

@@ -0,0 +1,209 @@
//
// Tests for System.Web.UI.WebControls.ButtonFieldTest.cs
//
// Author:
// Yoni Klein (yonik@mainsoft.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#if NET_2_0
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Drawing;
using System.Collections;
using System.Collections.Specialized;
using NUnit.Framework;
using System.Data;
namespace MonoTests.System.Web.UI.WebControls
{
class PokerButtonField : ButtonField
{
// View state Stuff
public PokerButtonField ()
: base ()
{
TrackViewState ();
}
public object SaveState ()
{
return SaveViewState ();
}
public void LoadState (object o)
{
LoadViewState (o);
}
public StateBag StateBag
{
get { return base.ViewState; }
}
public void DoCopyProperties (DataControlField newField)
{
base.CopyProperties (newField);
}
public DataControlField DoCreateField ()
{
return base.CreateField ();
}
public string DoFormatDataTextValue (object dataTextValue)
{
return base.FormatDataTextValue (dataTextValue);
}
public Control GetControl
{
get { return base.Control; }
}
}
[TestFixture]
public class ButtonFieldTest
{
[Test]
public void ButtonField_DefaultProperty ()
{
PokerButtonField button = new PokerButtonField ();
Assert.AreEqual ("", button.CommandName, "CommandName");
Assert.AreEqual ("", button.DataTextField, "DataTextField");
Assert.AreEqual ("", button.DataTextFormatString, "DataTextFormatString");
Assert.AreEqual ("", button.ImageUrl, "ImageUrl");
Assert.AreEqual ("", button.Text, "Text");
}
[Test]
public void ButtonField_AssignProperty ()
{
PokerButtonField button = new PokerButtonField ();
button.CommandName = "test";
Assert.AreEqual ("test", button.CommandName, "CommandName");
button.DataTextField = "test";
Assert.AreEqual ("test", button.DataTextField, "DataTextField");
button.DataTextFormatString = "test";
Assert.AreEqual ("test", button.DataTextFormatString, "DataTextFormatString");
button.ImageUrl = "test";
Assert.AreEqual ("test", button.ImageUrl, "ImageUrl");
button.Text = "test";
Assert.AreEqual ("test", button.Text, "Text");
}
[Test]
public void ButtonField_Initialize ()
{
Control control = new Control ();
control.ID = "test";
PokerButtonField button = new PokerButtonField ();
bool result = button.Initialize (true, control);
Assert.AreEqual (false, result, "Initialize");
Assert.AreEqual ("test", button.GetControl.ID, "InitializeControl");
}
[Test]
public void ButtonField_InitializeCell ()
{
ButtonField field = new ButtonField();
field.Text = "FieldText";
field.HeaderText = "HeaderText";
field.FooterText = "FooterText";
field.CommandName = "Commandname";
DataControlFieldCell cell = new DataControlFieldCell (null);
field.InitializeCell (cell, DataControlCellType.Header, DataControlRowState.Normal, 0);
Assert.AreEqual ("HeaderText", cell.Text, "HeaderText");
field.InitializeCell (cell, DataControlCellType.Footer, DataControlRowState.Normal, 0);
Assert.AreEqual ("FooterText", cell.Text, "FooterText");
Assert.AreEqual (0, cell.Controls.Count, "BeforeInitilizeDataField");
field.InitializeCell (cell, DataControlCellType.DataCell, DataControlRowState.Normal, 0);
Assert.AreEqual (1, cell.Controls.Count, "AfterInitilizeDataField");
Assert.AreEqual ("FieldText",((IButtonControl)cell.Controls[0]).Text ,"FieldText" );
Assert.AreEqual ("Commandname", ((IButtonControl) cell.Controls[0]).CommandName , "Commandname");
Assert.AreEqual ("0", ((IButtonControl) cell.Controls[0]).CommandArgument, "CommandArgument");
//Assert.AreEqual ("System.Web.UI.WebControls.DataControlLinkButton", ((IButtonControl) cell.Controls[0]).GetType ().ToString(), "TypeOfDataControlLinkButton");
cell.Controls.Clear ();
field.ButtonType = ButtonType.Image;
field.InitializeCell (cell, DataControlCellType.DataCell, DataControlRowState.Normal, 0);
//Assert.AreEqual ("System.Web.UI.WebControls.ImageButton", ((IButtonControl) cell.Controls[0]).GetType ().ToString (), "TypeOfDataControlLinkButton");
cell.Controls.Clear ();
field.ButtonType = ButtonType.Button;
field.InitializeCell (cell, DataControlCellType.DataCell, DataControlRowState.Normal, 0);
//Assert.AreEqual ("System.Web.UI.WebControls.Button", ((IButtonControl) cell.Controls[0]).GetType ().ToString (), "TypeOfDataControlLinkButton");
}
[Test]
public void ButtonField_ValidateSupportsCallback ()
{
//This method has been implemented as an empty method
}
[Test]
public void ButtonField_CopyProperties ()
{
PokerButtonField button = new PokerButtonField ();
ButtonField copy = new ButtonField ();
button.CommandName = "CommandName";
button.DataTextField = "DataTextField";
button.DataTextFormatString = "DataTextFormatString";
button.ImageUrl = "ImageUrl";
button.Text = "Text";
button.DoCopyProperties (copy);
Assert.AreEqual ("CommandName", copy.CommandName, "CommandName");
Assert.AreEqual ("DataTextField", copy.DataTextField, "DataTextField");
Assert.AreEqual ("DataTextFormatString", copy.DataTextFormatString, "DataTextFormatString");
Assert.AreEqual ("ImageUrl", copy.ImageUrl, "ImageUrl");
Assert.AreEqual ("Text", copy.Text, "Text");
}
[Test]
public void ButtonField_CreateField ()
{
PokerButtonField button = new PokerButtonField ();
DataControlField newfield = button.DoCreateField ();
if (!(newfield is ButtonField)) {
Assert.Fail ("New buttonfield was not created");
}
}
[Test]
public void ButtonField_FormatDataTextValue ()
{
PokerButtonField button = new PokerButtonField ();
button.DataTextFormatString = "-{0,8:G}-";
string result = button.DoFormatDataTextValue(10);
Assert.AreEqual ("- 10-", result, "FormatDataValueWithFormat");
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More