ServiceModelConfigurationElementCollectionTest.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. //
  2. // ServiceModelConfigurationElementCollectionTest.cs
  3. //
  4. // Author:
  5. // Eyal Alaluf <[email protected]>
  6. //
  7. // Copyright (C) 2008 Mainsoft, Inc. http://www.mainsoft.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 System;
  29. using System.Collections.Generic;
  30. using System.Text;
  31. using NUnit.Framework;
  32. using System.ServiceModel.Channels;
  33. using System.ServiceModel.Configuration;
  34. using System.Configuration;
  35. namespace MonoTests.System.ServiceModel.Configuration
  36. {
  37. [TestFixture]
  38. public class ServiceModelConfigurationElementCollectionTest
  39. {
  40. ClaimTypeElementCollection collection;
  41. private ClaimTypeElement CreateClaimType (string claim, bool isOptional)
  42. {
  43. ClaimTypeElement elem = new ClaimTypeElement ();
  44. elem.ClaimType = claim;
  45. elem.IsOptional = isOptional;
  46. return elem;
  47. }
  48. [TearDown]
  49. public void TearDownCollection ()
  50. {
  51. collection = null;
  52. }
  53. [SetUp]
  54. public void SetupCollection ()
  55. {
  56. collection = new ClaimTypeElementCollection ();
  57. collection.Add (CreateClaimType ("test1", false));
  58. collection.Add (CreateClaimType ("test2", false));
  59. }
  60. [Test]
  61. public void Indexer ()
  62. {
  63. Assert.AreEqual ("test1", collection ["test1"].ClaimType, "#01");
  64. collection ["test3"] = CreateClaimType ("test3", false);
  65. Assert.AreEqual ("test3", collection ["test3"].ClaimType, "#02");
  66. collection ["test2"] = CreateClaimType ("test2", true);
  67. Assert.AreEqual (true, collection ["test2"].IsOptional, "#03");
  68. }
  69. [Test]
  70. [ExpectedException (typeof (ArgumentException))]
  71. public void IndexerSetWithIncorrectKey ()
  72. {
  73. collection ["test10"] = CreateClaimType ("test", false);
  74. }
  75. [Test]
  76. public void IndexOf ()
  77. {
  78. Assert.AreEqual (1, collection.IndexOf (CreateClaimType ("test2", false)), "#01");
  79. Assert.AreEqual (-1, collection.IndexOf (CreateClaimType ("test10", false)), "#02");
  80. }
  81. [Test]
  82. public void Remove ()
  83. {
  84. ClaimTypeElement elem = collection ["test2"];
  85. collection.Remove (elem);
  86. Assert.AreEqual (-1, collection.IndexOf (elem), "#01");
  87. collection.Add (elem);
  88. Assert.AreEqual (1, collection.IndexOf (elem), "#02");
  89. collection.RemoveAt (1);
  90. Assert.AreEqual (-1, collection.IndexOf (elem), "#03");
  91. collection.Add (elem);
  92. Assert.AreEqual (1, collection.IndexOf (elem), "#04");
  93. collection.RemoveAt ("test2");
  94. Assert.AreEqual (-1, collection.IndexOf (elem), "#05");
  95. }
  96. [Test]
  97. public void Clear ()
  98. {
  99. ClaimTypeElement elem = collection ["test2"];
  100. collection.Clear ();
  101. Assert.AreEqual (-1, collection.IndexOf (elem), "#01");
  102. Assert.AreEqual (0, collection.Count, "#02");
  103. }
  104. [Test]
  105. public void ContainsKey ()
  106. {
  107. Assert.AreEqual (true, collection.ContainsKey ("test1"), "#01");
  108. Assert.AreEqual (false, collection.ContainsKey ("test10"), "#02");
  109. }
  110. [Test]
  111. public void CopyTo ()
  112. {
  113. ClaimTypeElement[] array = new ClaimTypeElement [4];
  114. collection.CopyTo (array, 2);
  115. Assert.AreEqual ("test1", array [2].ClaimType, "#01");
  116. Assert.AreEqual ("test2", array [3].ClaimType, "#02");
  117. }
  118. }
  119. }