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