WebScriptServiceHostFactoryTest.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #if !MOBILE
  2. using System;
  3. using System.ServiceModel;
  4. using System.ServiceModel.Activation;
  5. using System.ServiceModel.Channels;
  6. using System.ServiceModel.Web;
  7. using NUnit.Framework;
  8. namespace MonoTests.System.ServiceModel.Activation
  9. {
  10. class MyHostFactory : WebScriptServiceHostFactory
  11. {
  12. public ServiceHost DoCreateServiceHost (Type type, params Uri [] baseAddresses)
  13. {
  14. return CreateServiceHost (type, baseAddresses);
  15. }
  16. }
  17. [TestFixture]
  18. public class WebScriptServiceHostFactoryTest
  19. {
  20. [Test]
  21. public void CreateServiceHost ()
  22. {
  23. var f = new MyHostFactory ();
  24. var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ("http://localhost:37564")});
  25. Assert.IsFalse (host is WebServiceHost, "#1");
  26. host.Open ();
  27. host.Close ();
  28. }
  29. [Test]
  30. [ExpectedException (typeof (NotSupportedException))]
  31. public void ResponseWrappedIsInvalid ()
  32. {
  33. var f = new MyHostFactory ();
  34. var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ("http://localhost:37564")});
  35. host.Open (); // should raise an error here.
  36. }
  37. [Test]
  38. [ExpectedException (typeof (InvalidOperationException))]
  39. public void MultipleContract ()
  40. {
  41. var f = new MyHostFactory ();
  42. var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ("http://localhost:37564")});
  43. host.Open ();
  44. }
  45. }
  46. [ServiceContract]
  47. public interface ITestService
  48. {
  49. [OperationContract]
  50. string DoWork (string s1, string s2);
  51. }
  52. public class TestService : ITestService
  53. {
  54. public string DoWork (string s1, string s2)
  55. {
  56. return s1 + s2;
  57. }
  58. }
  59. [ServiceContract]
  60. public interface ITestService2
  61. {
  62. [OperationContract]
  63. [WebGet (BodyStyle = WebMessageBodyStyle.WrappedResponse)]
  64. string DoWork (string s1, string s2);
  65. }
  66. public class TestService2 : ITestService2
  67. {
  68. public string DoWork (string s1, string s2)
  69. {
  70. return s1 + s2;
  71. }
  72. }
  73. public class TestServiceMultiple : ITestService, ITestService2
  74. {
  75. public string DoWork (string s1, string s2)
  76. {
  77. return s1 + s2;
  78. }
  79. }
  80. }
  81. #endif