WebHttpBindingElementTest.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using System;
  2. using System.ServiceModel.Configuration;
  3. using NUnit.Framework;
  4. using System.ServiceModel;
  5. using System.Text;
  6. using System.Configuration;
  7. namespace MonoTests.System.ServiceModel.Configuration
  8. {
  9. [TestFixture]
  10. public class WebHttpBindingElementTest
  11. {
  12. class Poker : WebHttpBindingElement
  13. {
  14. public Type GetBindingElementType ()
  15. {
  16. return BindingElementType;
  17. }
  18. }
  19. [Test]
  20. public void BindingElementType ()
  21. {
  22. Poker poker = new Poker ();
  23. Assert.AreEqual (typeof (WebHttpBinding), poker.GetBindingElementType (), "BindingElementType");
  24. }
  25. [Test]
  26. public void ApplyConfiguration ()
  27. {
  28. WebHttpBinding b = CreateBindingFromConfig ();
  29. Assert.AreEqual (true, b.AllowCookies, "#1");
  30. Assert.AreEqual (true, b.BypassProxyOnLocal, "#2");
  31. Assert.AreEqual (HostNameComparisonMode.Exact, b.HostNameComparisonMode, "#3");
  32. Assert.AreEqual (262144, b.MaxBufferPoolSize, "#4");
  33. Assert.AreEqual (32768, b.MaxBufferSize, "#5");
  34. Assert.AreEqual (16384, b.MaxReceivedMessageSize, "#6");
  35. Assert.AreEqual ("proxy", b.ProxyAddress.ToString (), "#7");
  36. Assert.AreEqual (Encoding.Unicode, b.WriteEncoding, "#8");
  37. Assert.AreEqual (TransferMode.Streamed, b.TransferMode, "#9");
  38. }
  39. [Test]
  40. public void Security ()
  41. {
  42. WebHttpBinding b = CreateBindingFromConfig ();
  43. Assert.AreEqual (WebHttpSecurityMode.TransportCredentialOnly, b.Security.Mode, "#1");
  44. Assert.AreEqual (HttpClientCredentialType.Basic, b.Security.Transport.ClientCredentialType, "#2");
  45. }
  46. private WebHttpBinding CreateBindingFromConfig ()
  47. {
  48. ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/webHttpBinding").GetSectionGroup ("system.serviceModel");
  49. WebHttpBindingCollectionElement collectionElement = (WebHttpBindingCollectionElement) config.Bindings ["webHttpBinding"];
  50. WebHttpBindingElement el = collectionElement.Bindings ["WebHttpBinding1_Service"];
  51. WebHttpBinding b = new WebHttpBinding ();
  52. el.ApplyConfiguration (b);
  53. return b;
  54. }
  55. }
  56. }