2
0

MetadataElementTest.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // MetadataElementTest.cs
  3. //
  4. // Author:
  5. // Igor Zelmanovich <[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.Configuration;
  33. using System.Configuration;
  34. using System.ServiceModel.Channels;
  35. using System.ServiceModel.Description;
  36. namespace MonoTests.System.ServiceModel.Configuration
  37. {
  38. [TestFixture]
  39. public class MetadataElementTest
  40. {
  41. ServiceModelSectionGroup OpenConfig (string name) {
  42. return (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/" + name).GetSectionGroup ("system.serviceModel");
  43. }
  44. [Test]
  45. public void PolicyImporters () {
  46. ServiceModelSectionGroup config = OpenConfig ("client.metadata");
  47. PolicyImporterElementCollection col = config.Client.Metadata.PolicyImporters;
  48. Assert.AreEqual (2, col.Count, "Count");
  49. PolicyImporterElement item = col ["PolicyImporterType1"];
  50. if (item == null)
  51. Assert.Fail ("PolicyImporterType1 not exists");
  52. Assert.AreEqual ("PolicyImporterType1", item.Type, "PolicyImporterType1.Type");
  53. item = col ["PolicyImporterType2"];
  54. if (item == null)
  55. Assert.Fail ("PolicyImporterType2 not exists");
  56. Assert.AreEqual ("PolicyImporterType2", item.Type, "PolicyImporterType2.Type");
  57. }
  58. [Test]
  59. public void WsdlImporters () {
  60. ServiceModelSectionGroup config = OpenConfig ("client.metadata");
  61. WsdlImporterElementCollection col = config.Client.Metadata.WsdlImporters;
  62. Assert.AreEqual (2, col.Count, "Count");
  63. WsdlImporterElement item = col ["WSDLImporter1"];
  64. if (item == null)
  65. Assert.Fail ("WSDLImporter1 not exists");
  66. Assert.AreEqual ("WSDLImporter1", item.Type, "WSDLImporter1.Type");
  67. item = col ["WSDLImporter2"];
  68. if (item == null)
  69. Assert.Fail ("WSDLImporter2 not exists");
  70. Assert.AreEqual ("WSDLImporter2", item.Type, "WSDLImporter2.Type");
  71. }
  72. [Test]
  73. public void PolicyImporters_DefaultConfiguration () {
  74. ServiceModelSectionGroup config = OpenConfig ("empty");
  75. PolicyImporterElementCollection col = config.Client.Metadata.PolicyImporters;
  76. Type [] types = new Type [] {
  77. typeof(CompositeDuplexBindingElementImporter),
  78. typeof(MessageEncodingBindingElementImporter),
  79. typeof(OneWayBindingElementImporter),
  80. typeof(PrivacyNoticeBindingElementImporter),
  81. typeof(ReliableSessionBindingElementImporter),
  82. typeof(SecurityBindingElementImporter),
  83. typeof(TransactionFlowBindingElementImporter),
  84. typeof(TransportBindingElementImporter),
  85. typeof(UseManagedPresentationBindingElementImporter)
  86. };
  87. foreach (Type type in types) {
  88. PolicyImporterElement item = col [type.AssemblyQualifiedName];
  89. if (item == null)
  90. Assert.Fail (type.Name + " not exists");
  91. Assert.AreEqual (type.AssemblyQualifiedName, item.Type, type.Name);
  92. }
  93. }
  94. [Test]
  95. public void WsdlImporters_DefaultConfiguration () {
  96. ServiceModelSectionGroup config = OpenConfig ("empty");
  97. WsdlImporterElementCollection col = config.Client.Metadata.WsdlImporters;
  98. Type [] types = new Type [] {
  99. typeof(MessageEncodingBindingElementImporter),
  100. typeof(StandardBindingImporter),
  101. typeof(TransportBindingElementImporter),
  102. typeof(DataContractSerializerMessageContractImporter),
  103. typeof(XmlSerializerMessageContractImporter)
  104. };
  105. foreach (Type type in types) {
  106. WsdlImporterElement item = col [type.AssemblyQualifiedName];
  107. if (item == null)
  108. Assert.Fail (type.Name + " not exists");
  109. Assert.AreEqual (type.AssemblyQualifiedName, item.Type, type.Name);
  110. }
  111. }
  112. }
  113. }