Merge pull request #2799 from BrzVlad/fix-conc-card-clean
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel / ServiceHostTest.cs
index a120402ff7cc6bbcdcaadc235ad311843ca49752..baf704655ca9ad618c1a50753b68dea39b22986d 100644 (file)
@@ -270,7 +270,8 @@ namespace MonoTests.System.ServiceModel
                [ExpectedException (typeof (InvalidOperationException))]
                public void AddServiceEndpointMexWithNoImpl ()
                {
-                       using (ServiceHost h = new ServiceHost (typeof (Foo), new Uri ("http://localhost:8080"))) {
+                       var port = NetworkHelpers.FindFreePort ();
+                       using (ServiceHost h = new ServiceHost (typeof (Foo), new Uri ("http://localhost:" + port))) {
                                // it expects ServiceMetadataBehavior
                                h.AddServiceEndpoint (ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding (), "mex");
                        }
@@ -279,21 +280,23 @@ namespace MonoTests.System.ServiceModel
                [Test]
                public void AddServiceEndpointMetadataExchange ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        // MyMetadataExchange implements IMetadataExchange
                        ServiceHost host = new ServiceHost (typeof (MyMetadataExchange));
                        host.AddServiceEndpoint ("IMetadataExchange",
                                                 new BasicHttpBinding (),
-                                                "http://localhost:8080/");
+                                                "http://localhost:" + port + "/");
                }
 
                [Test]
                [ExpectedException (typeof (InvalidOperationException))]
                public void AddServiceEndpointMetadataExchangeFullNameFails ()
                {
+                       var port = NetworkHelpers.FindFreePort ();
                        ServiceHost host = new ServiceHost (typeof (MyMetadataExchange));
                        host.AddServiceEndpoint ("System.ServiceModel.Description.IMetadataExchange",
                                                 new BasicHttpBinding (),
-                                                "http://localhost:8080");
+                                                "http://localhost:" + port);
                }
 
                [Test]
@@ -353,6 +356,29 @@ namespace MonoTests.System.ServiceModel
                        }
                }
 
+               [Test]
+               public void InstanceWithSingletonMode_InheritServiceBehavior ()
+               {
+                       // # 37035
+
+                       var ep = NetworkHelpers.LocalEphemeralEndPoint ().ToString ();
+
+                       ChildSingletonService instance = new ChildSingletonService ();
+                       ServiceHost host = new ServiceHost (instance);
+
+                       host.AddServiceEndpoint (typeof (SingletonService),
+                                                new BasicHttpBinding (),
+                                                new Uri ("http://" + ep + "/s3"));
+
+                       try {
+                               host.Open ();
+                       } catch (InvalidOperationException ex) {
+                               Assert.Fail ("InstanceContextMode was not inherited from parent, exception was: {0}", ex);
+                       } finally {
+                               host.Close ();
+                       }
+               }
+
                [ServiceContract]
                interface IBar
                {
@@ -446,7 +472,14 @@ namespace MonoTests.System.ServiceModel
                public class SingletonService
                {
                        [OperationContract]
-                       public void Process (string input)
+                       public virtual void Process (string input)
+                       {
+                       }
+               }
+
+               public class ChildSingletonService : SingletonService
+               {
+                       public override void Process (string input)
                        {
                        }
                }