StateBagCas.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. //
  2. // StateBagCas.cs - CAS unit tests for System.Web.UI.StateBag
  3. //
  4. // Author:
  5. // Sebastien Pouliot <[email protected]>
  6. //
  7. // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using NUnit.Framework;
  29. using System;
  30. using System.Collections;
  31. using System.Security.Permissions;
  32. using System.Web;
  33. using System.Web.UI;
  34. namespace MonoCasTests.System.Web.UI {
  35. [TestFixture]
  36. [Category ("CAS")]
  37. public class StateBagCas : AspNetHostingMinimal {
  38. [Test]
  39. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  40. public void Deny_Unrestricted ()
  41. {
  42. StateBag bag = new StateBag (true);
  43. Assert.IsNotNull (bag.Add ("key", "value"), "Add");
  44. Assert.AreEqual (1, bag.Count, "Count");
  45. Assert.IsNotNull (bag.GetEnumerator (), "GetEnumerator");
  46. bag.SetItemDirty ("key", true);
  47. Assert.IsTrue (bag.IsItemDirty ("key"), "IsItemDirty");
  48. bag.Remove ("key");
  49. bag.Clear ();
  50. bag["key"] = "value";
  51. Assert.IsNotNull (bag["key"], "this[string]");
  52. Assert.IsNotNull (bag.Keys, "Keys");
  53. Assert.IsNotNull (bag.Values, "Values");
  54. #if NET_2_0
  55. bag.SetDirty (true);
  56. #endif
  57. }
  58. [Test]
  59. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  60. public void IStateManager_Deny_Unrestricted ()
  61. {
  62. IStateManager sm = new StateBag ();
  63. Assert.IsFalse (sm.IsTrackingViewState, "IsTrackingViewState");
  64. object state = sm.SaveViewState ();
  65. sm.LoadViewState (state);
  66. sm.TrackViewState ();
  67. }
  68. [Test]
  69. [PermissionSet (SecurityAction.Deny, Unrestricted = true)]
  70. public void IDictionary_Deny_Unrestricted ()
  71. {
  72. IDictionary d = new StateBag ();
  73. d.Add ("key", "value");
  74. Assert.IsTrue (d.Contains ("key"), "Contains");
  75. Assert.AreEqual (1, d.Count, "Count");
  76. d.Remove ("key");
  77. d["key"] = "value";
  78. Assert.AreEqual ("value", d["key"], "this[string]");
  79. d.Clear ();
  80. Assert.IsFalse (d.IsFixedSize, "IsFixedSize");
  81. Assert.IsFalse (d.IsReadOnly, "IsReadOnly");
  82. ICollection c = (d as ICollection);
  83. Assert.IsFalse (c.IsSynchronized, "IsSynchronized");
  84. Assert.IsNotNull (c.SyncRoot, "SyncRoot");
  85. }
  86. // LinkDemand
  87. public override Type Type {
  88. get { return typeof (StateBag); }
  89. }
  90. }
  91. }