WebHttpBindingElementTest.cs 2.0 KB

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