CacheItemPriorityQueueTestSupport.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. // Authors:
  2. // Marek Habersack <[email protected]>
  3. //
  4. // Copyright (C) 2010 Novell Inc. http://novell.com
  5. //
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining
  8. // a copy of this software and associated documentation files (the
  9. // "Software"), to deal in the Software without restriction, including
  10. // without limitation the rights to use, copy, modify, merge, publish,
  11. // distribute, sublicense, and/or sell copies of the Software, and to
  12. // permit persons to whom the Software is furnished to do so, subject to
  13. // the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be
  16. // included in all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  22. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  23. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  24. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25. //
  26. using System;
  27. using System.Web.Caching;
  28. namespace MonoTests.System.Web.Caching
  29. {
  30. public enum QueueOperation
  31. {
  32. Enqueue,
  33. Dequeue,
  34. Disable,
  35. Peek,
  36. QueueSize,
  37. Update
  38. }
  39. public sealed class CacheItemPriorityQueueTestItem
  40. {
  41. public int ListIndex = -1;
  42. public int QueueCount = -1;
  43. public QueueOperation Operation;
  44. public bool IsDisabled;
  45. public bool IsNull;
  46. public bool Disable;
  47. public int OperationCount = -1;
  48. public string Guid;
  49. public int PriorityQueueIndex = -1;
  50. public long ExpiresAt = 0;
  51. public CacheItemPriorityQueueTestItem ()
  52. {}
  53. public CacheItemPriorityQueueTestItem (string serialized)
  54. {
  55. if (String.IsNullOrEmpty (serialized))
  56. throw new ArgumentException ("serialized");
  57. string[] parts = serialized.Split (';');
  58. if (parts.Length != 10)
  59. throw new InvalidOperationException ("Invalid serialized data.");
  60. ListIndex = Int32.Parse (parts [0]);
  61. QueueCount = Int32.Parse (parts [1]);
  62. int i = Int32.Parse (parts [2]);
  63. if (i < (int)QueueOperation.Enqueue || i > (int)QueueOperation.Update)
  64. throw new InvalidOperationException ("Invalid value for Operation in the serialized data.");
  65. Operation = (QueueOperation)i;
  66. IsDisabled = GetBool (parts [3]);
  67. IsNull = GetBool (parts [4]);
  68. Disable = GetBool (parts [5]);
  69. OperationCount = Int32.Parse (parts [6]);
  70. Guid = parts [7];
  71. PriorityQueueIndex = Int32.Parse (parts [8]);
  72. ExpiresAt = Int64.Parse (parts [9]);
  73. if (Guid.Length == 0)
  74. Guid = null;
  75. }
  76. bool GetBool (string s)
  77. {
  78. if (s == "t")
  79. return true;
  80. if (s == "f")
  81. return false;
  82. throw new InvalidOperationException ("Invalid bool string in serialized data.");
  83. }
  84. public string Serialize ()
  85. {
  86. return String.Format ("{0};{1};{2};{3};{4};{5};{6};{7};{8};{9}",
  87. ListIndex,
  88. QueueCount,
  89. (int)Operation,
  90. IsDisabled ? "t" : "f",
  91. IsNull ? "t" : "f",
  92. Disable ? "t" : "f",
  93. OperationCount,
  94. Guid == null ? "null" : Guid.ToString (),
  95. PriorityQueueIndex,
  96. ExpiresAt);
  97. }
  98. }
  99. }