Handle overrides on events when retrieving cattrs.
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel / ServiceHostBaseTest.cs
index e668e387b3acd2dfba474166d3a2de02acc0a9e4..ac8ec625618c60f432588ef6f571c89f1eee00bb 100644 (file)
@@ -324,34 +324,94 @@ namespace MonoTests.System.ServiceModel
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void RunDestinationUnreachableTest ()
+               {
+                       RunDestinationUnreachableTest ("BasicHttp", new BasicHttpBinding ());
+               }
+
+               [Test]
+               public void RunDestinationUnreachableTest2 ()
+               {
+                       RunDestinationUnreachableTest ("CustomSoap12", new CustomBinding (new HttpTransportBindingElement ()));
+               }
+
+               void RunDestinationUnreachableTest (string label, Binding binding)
                {
                        string address = "http://localhost:37564/";
-                       var host = OpenHost (address);
-                       
-                       var binding = new BasicHttpBinding ();
-                       var client = new DestinationUnreachableClient (binding, address);
+                       var host = OpenHost (address, binding);
                        
                        try {
+                               var client = new DestinationUnreachableClient (binding, address);
                                client.NotImplementedOperation ();
-                               Assert.Fail ("ActionNotSupportedException is expected");
+                               Assert.Fail (label + " ActionNotSupportedException is expected");
                        } catch (ActionNotSupportedException) {
                                // catching it instead of ExpectedException to distinguish errors at service side.
+                       } finally {
+                               host.Close ();
                        }
                }
                
-               ServiceHost OpenHost (string address)
+               ServiceHost OpenHost (string address, Binding binding)
                {
                        var baseAddresses = new Uri[] { new Uri(address) };
 
                        var host = new ServiceHost (typeof (DummyService), baseAddresses);
-                       var basicBinding = new BasicHttpBinding ();
-                       host.AddServiceEndpoint (typeof (IDummyService), basicBinding, new Uri ("", UriKind.Relative));
+                       host.AddServiceEndpoint (typeof (IDummyService), binding, new Uri ("", UriKind.Relative));
                        host.Open ();
                        return host;
                }
 
+#if NET_4_0
+               [Test]
+               public void AddServiceEndpoint_Directly ()
+               {
+                       var host = new ServiceHost (typeof (DummyService));
+                       var address = new EndpointAddress ("http://localhost:8080");
+                       var binding = new BasicHttpBinding ();
+                       var contract = ContractDescription.GetContract (typeof (IDummyService));
+                       host.AddServiceEndpoint (new ServiceEndpoint (contract, binding, address));
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void AddServiceEndpoint_Directly_NullAddress ()
+               {
+                       var host = new ServiceHost (typeof (DummyService));
+                       var binding = new BasicHttpBinding ();
+                       var contract = ContractDescription.GetContract (typeof (IDummyService));
+                       host.AddServiceEndpoint (new ServiceEndpoint (contract, binding, null));
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void AddServiceEndpoint_Directly_NullBinding ()
+               {
+                       var host = new ServiceHost (typeof (DummyService));
+                       var address = new EndpointAddress ("http://localhost:8080");
+                       var contract = ContractDescription.GetContract (typeof (IDummyService));
+                       host.AddServiceEndpoint (new ServiceEndpoint (contract, null, address));
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               public void AddServiceMetadataEndpoint ()
+               {
+                       var host = new ServiceHost (typeof (DummyService));
+                       host.AddServiceEndpoint (new ServiceMetadataEndpoint ());
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void AddServiceEndpoint_Directly_ContractMismatch ()
+               {
+                       var host = new ServiceHost (typeof (DummyService));
+                       var address = new EndpointAddress ("http://localhost:8080");
+                       var binding = new BasicHttpBinding ();
+                       var contract = ContractDescription.GetContract (typeof (INotImplementedService));
+                       host.AddServiceEndpoint (new ServiceEndpoint (contract, binding, address));
+               }
+#endif
+
                #region helpers
 
                public enum Stage