Merge pull request #409 from Alkarex/patch-1
[mono.git] / mcs / class / System.ServiceModel / Test / System.ServiceModel.Dispatcher / DispatchOperationTest.cs
index 37b1210c88c6d4ac931b4f9cffc456ea64dff8f4..e8881b27d8a3d1771c1372d0de6d3de5abce9f95 100644 (file)
@@ -88,17 +88,38 @@ namespace MonoTests.System.ServiceModel.Dispatcher
                public void FaultContractInfos ()
                {
                        var host = new ServiceHost (typeof (TestFaultContract));
-                       host.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true;
+                       host.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = false;
                        host.AddServiceEndpoint (typeof (ITestFaultContract), new BasicHttpBinding (), new Uri ("http://localhost:37564"));
                        host.Open ();
                        try {
                                var cf = new ChannelFactory<ITestFaultContract> (new BasicHttpBinding (), new EndpointAddress ("http://localhost:37564"));
                                var cli = cf.CreateChannel ();
-                               cli.Run ("test");
-                       } catch (FaultException<PrivateAffairError> ex) {
-                               var p  = ex.Detail;
-                               Assert.AreEqual (5, p.ErrorCode, "#1");
-                               Assert.AreEqual ("foobarerror", p.Text, "#2");
+                               try {
+                                       cli.Run ("default");
+                                       Assert.Fail ("#1");
+                               } catch (FaultException<PrivateAffairError> ex) {
+                                       var p  = ex.Detail;
+                                       Assert.AreEqual (5, p.ErrorCode, "#2");
+                                       Assert.AreEqual ("foobarerror", p.Text, "#3");
+                               }
+
+                               try {
+                                       cli.Run ("deriveddata");
+                                       Assert.Fail ("#4");
+                               } catch (Exception ex) {
+                                       // The type must be explicitly listed in the [FaultContract],
+                                       // it is not allowed to use a subclass of the exception data type.
+                                       Assert.AreEqual (typeof (FaultException), ex.GetType (), "#5");
+                               }
+
+                               try {
+                                       cli.Run ("derivedexception");
+                                       Assert.Fail ("#6");
+                               } catch (Exception ex) {
+                                       // However, it is allowed to derive from FaultException<T>, provided
+                                       // that T is explicitly listed in [FaultContract].  Bug #7177.
+                                       Assert.AreEqual (typeof (FaultException<PrivateAffairError>), ex.GetType (), "#7");
+                               }
                        } finally {
                                host.Close ();
                        }
@@ -125,7 +146,14 @@ namespace MonoTests.System.ServiceModel.Dispatcher
                                Assert.AreEqual (1, dop.FaultContractInfos.Count, "s#2");
                                var fci = dop.FaultContractInfos [0];
                                Assert.AreEqual (typeof (PrivateAffairError), fci.Detail, "s#3");
-                               throw new FaultException<PrivateAffairError> (new PrivateAffairError () { ErrorCode = 5, Text = "foobarerror" });
+                               if (input.Equals ("default"))
+                                       throw new FaultException<PrivateAffairError> (new PrivateAffairError () { ErrorCode = 5, Text = "foobarerror" });
+                               else if (input.Equals ("deriveddata"))
+                                       throw new FaultException<DerivedPrivateAffairError> (new DerivedPrivateAffairError () { ErrorCode = 5, Text = "foobarerror" });
+                               else if (input.Equals ("derivedexception"))
+                                       throw new DerivedFaultException (new PrivateAffairError () { ErrorCode = 5, Text = "foobarerror" });
+                               else
+                                       throw new FaultException ("Invalid operation");
                        }
                }
 
@@ -137,5 +165,17 @@ namespace MonoTests.System.ServiceModel.Dispatcher
                        [DataMember]
                        public string Text { get; set; }
                }
+
+               [DataContract]
+               class DerivedPrivateAffairError : PrivateAffairError
+               {
+               }
+
+               class DerivedFaultException : FaultException<PrivateAffairError>
+               {
+                       public DerivedFaultException (PrivateAffairError error)
+                               : base (error)
+                       { }
+               }
        }
 }
\ No newline at end of file