Merge pull request #2698 from esdrubal/iosxmlarray
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel / ServiceHostBaseTest.cs
index 0fef7a6e903996907ebf989eb7c7b5fa69cb1141..a2082bdfa07234b968ab40f11c08d527c5b6e14d 100644 (file)
@@ -131,7 +131,8 @@ namespace MonoTests.System.ServiceModel
                public void InitializeRuntime () {
                        Poker host = new Poker ();
                        host.CallInitializeDescription ();
-                       EndpointAddress address = new EndpointAddress ("http://localhost:8090/");
+                       var port = NetworkHelpers.FindFreePort ();
+                       EndpointAddress address = new EndpointAddress ("http://localhost:" + port + "/");
                        ContractDescription contract = ContractDescription.GetContract (typeof (IMyContract));
                        ServiceEndpoint endpoint = new ServiceEndpoint (contract, new BasicHttpBinding (), address);
                        endpoint.ListenUri = address.Uri;
@@ -273,9 +274,9 @@ namespace MonoTests.System.ServiceModel
                {
                        var host = new Poker ();
                        Assert.AreEqual (0, host.BaseAddresses.Count, "#1");
-                       host.DoAddBaseAddress (new Uri ("http://localhost:37564"));
+                       host.DoAddBaseAddress (new Uri ("http://localhost:" + NetworkHelpers.FindFreePort ()));
                        Assert.AreEqual (1, host.BaseAddresses.Count, "#1");
-                       host.DoAddBaseAddress (new Uri ("net.tcp://localhost:893"));
+                       host.DoAddBaseAddress (new Uri ("net.tcp://localhost:" + NetworkHelpers.FindFreePort ()));
                        Assert.AreEqual (2, host.BaseAddresses.Count, "#1");
                }
 
@@ -285,31 +286,33 @@ namespace MonoTests.System.ServiceModel
                {
                        var host = new Poker ();
                        Assert.AreEqual (0, host.BaseAddresses.Count, "#1");
-                       host.DoAddBaseAddress (new Uri ("http://localhost:37564"));
+                       host.DoAddBaseAddress (new Uri ("http://localhost:" + NetworkHelpers.FindFreePort ()));
                        // http base address is already added.
-                       host.DoAddBaseAddress (new Uri ("http://localhost:893"));
+                       host.DoAddBaseAddress (new Uri ("http://localhost:" + NetworkHelpers.FindFreePort ()));
                }
 
                [Test]
                public void AddServiceEndpointUri ()
                {
+                       int port = NetworkHelpers.FindFreePort ();
                        var host = new ServiceHost (typeof (AllActions),
-                               new Uri ("http://localhost:37564"));
+                               new Uri ("http://localhost:" + port));
                        var se = host.AddServiceEndpoint (typeof (AllActions),
                                new BasicHttpBinding (), "foobar");
-                       Assert.AreEqual ("http://localhost:37564/foobar", se.Address.Uri.AbsoluteUri, "#1");
-                       Assert.AreEqual ("http://localhost:37564/foobar", se.ListenUri.AbsoluteUri, "#2");
+                       Assert.AreEqual ("http://localhost:" + port + "/foobar", se.Address.Uri.AbsoluteUri, "#1");
+                       Assert.AreEqual ("http://localhost:" + port + "/foobar", se.ListenUri.AbsoluteUri, "#2");
                }
 
                [Test]
                public void AddServiceEndpointUri2 ()
                {
+                       int port = NetworkHelpers.FindFreePort ();
                        var host = new ServiceHost (typeof (AllActions),
-                               new Uri ("http://localhost:37564"));
+                               new Uri ("http://localhost:" + port));
                        var se = host.AddServiceEndpoint (typeof (AllActions),
                                new BasicHttpBinding (), String.Empty);
-                       Assert.AreEqual ("http://localhost:37564/", se.Address.Uri.AbsoluteUri, "#1");
-                       Assert.AreEqual ("http://localhost:37564/", se.ListenUri.AbsoluteUri, "#2");
+                       Assert.AreEqual ("http://localhost:" + port + "/", se.Address.Uri.AbsoluteUri, "#1");
+                       Assert.AreEqual ("http://localhost:" + port + "/", se.ListenUri.AbsoluteUri, "#2");
                }
 
                [Test]
@@ -371,12 +374,12 @@ namespace MonoTests.System.ServiceModel
                        return host;
                }
 
-#if NET_4_0
                [Test]
                public void AddServiceEndpoint_Directly ()
                {
                        var host = new ServiceHost (typeof (DummyService));
-                       var address = new EndpointAddress ("http://localhost:30158");
+                       var port = NetworkHelpers.FindFreePort ();
+                       var address = new EndpointAddress ("http://localhost:" + port);
                        var binding = new BasicHttpBinding ();
                        var contract = ContractDescription.GetContract (typeof (IDummyService));
                        host.AddServiceEndpoint (new ServiceEndpoint (contract, binding, address));
@@ -397,7 +400,8 @@ namespace MonoTests.System.ServiceModel
                public void AddServiceEndpoint_Directly_NullBinding ()
                {
                        var host = new ServiceHost (typeof (DummyService));
-                       var address = new EndpointAddress ("http://localhost:30158");
+                       var port = NetworkHelpers.FindFreePort ();
+                       var address = new EndpointAddress ("http://localhost:" + port);
                        var contract = ContractDescription.GetContract (typeof (IDummyService));
                        host.AddServiceEndpoint (new ServiceEndpoint (contract, null, address));
                }
@@ -415,12 +419,12 @@ namespace MonoTests.System.ServiceModel
                public void AddServiceEndpoint_Directly_ContractMismatch ()
                {
                        var host = new ServiceHost (typeof (DummyService));
-                       var address = new EndpointAddress ("http://localhost:30158");
+                       var port = NetworkHelpers.FindFreePort ();
+                       var address = new EndpointAddress ("http://localhost:" + port);
                        var binding = new BasicHttpBinding ();
                        var contract = ContractDescription.GetContract (typeof (INotImplementedService));
                        host.AddServiceEndpoint (new ServiceEndpoint (contract, binding, address));
                }
-#endif
 
                #region helpers