WebScriptServiceHostFactoryTest.cs 2.0 KB

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