Merge pull request #4219 from marek-safar/corert-bump
[mono.git] / mcs / class / System.ServiceModel.Web / Test / System.ServiceModel.Description / WebHttpBehaviorTest.cs
index 009ba909588b97c5ce13553181b2570306bcaaab..dd4d46ab0133615b66f107213ab113efa683a7e0 100644 (file)
@@ -22,7 +22,7 @@ namespace MonoTests.System.ServiceModel.Description
                {
                        return GetRequestClientFormatter (operationDescription, endpoint);
                }
-
+#if !MOBILE
                public IDispatchMessageFormatter DoGetReplyDispatchFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
                {
                        return GetReplyDispatchFormatter (operationDescription, endpoint);
@@ -32,7 +32,7 @@ namespace MonoTests.System.ServiceModel.Description
                {
                        return GetRequestDispatchFormatter (operationDescription, endpoint);
                }
-
+#endif
                public event Action<ServiceEndpoint, ClientRuntime> ApplyClientBehaviorInvoked;
 
                public override void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime client)
@@ -52,6 +52,18 @@ namespace MonoTests.System.ServiceModel.Description
                                                    new EndpointAddress ("http://localhost:37564"));
                }
 
+               [Test]
+               public void DefaultValues ()
+               {
+                       var b = new WebHttpBehavior ();
+                       Assert.AreEqual (WebMessageBodyStyle.Bare, b.DefaultBodyStyle, "#1");
+                       Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingRequestFormat, "#2");
+                       Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingResponseFormat, "#3");
+                       Assert.IsFalse (b.AutomaticFormatSelectionEnabled, "#11");
+                       Assert.IsFalse (b.FaultExceptionEnabled, "#12");
+                       Assert.IsFalse (b.HelpEnabled, "#13");
+               }
+
                [Test]
                public void AddBiningParameters ()
                {
@@ -62,6 +74,7 @@ namespace MonoTests.System.ServiceModel.Description
                        Assert.AreEqual (0, pl.Count, "#1");
                }
 
+#if !MOBILE && !MONOMAC
                [Test]
                public void ApplyDispatchBehavior ()
                {
@@ -106,6 +119,7 @@ namespace MonoTests.System.ServiceModel.Description
 
                        Assert.AreEqual (0, ed.DispatchRuntime.Operations.Count, "#4-0"); // hmm... really?
                }
+#endif
 
                [Test]
                public void GetMessageFormatters ()
@@ -115,8 +129,10 @@ namespace MonoTests.System.ServiceModel.Description
                        var b = new WebHttpBehaviorExt ();
                        Assert.IsNotNull (b.DoGetRequestClientFormatter (od, se), "#1");
                        Assert.IsNotNull (b.DoGetReplyClientFormatter (od, se), "#2");
+#if !MOBILE
                        Assert.IsNotNull (b.DoGetRequestDispatchFormatter (od, se), "#3");
                        Assert.IsNotNull (b.DoGetReplyDispatchFormatter (od, se), "#4");
+#endif
                }
 
                [Test]
@@ -139,6 +155,7 @@ namespace MonoTests.System.ServiceModel.Description
                        }
                }
 
+#if !MOBILE
                [Test]
                public void RequestClientFormatter2 ()
                {
@@ -160,6 +177,7 @@ namespace MonoTests.System.ServiceModel.Description
 
                        // TODO: test DeserializeReply too (it is supported unlike above).
                }
+#endif
 
                [ServiceContract]
                public interface IMyService
@@ -175,7 +193,9 @@ namespace MonoTests.System.ServiceModel.Description
 
                public class MyService: IMyService
                {
+#if !MOBILE
                        [OperationBehavior]
+#endif
                        public string Echo (string input)
                        {
                                return input;
@@ -190,9 +210,11 @@ namespace MonoTests.System.ServiceModel.Description
                        Assert.IsTrue (od.Behaviors.Contains (typeof (WebGetAttribute)), "Operation is recognized as WebGet");
                }
 
+#if !MOBILE
                [Test]
                public void MessageFormatterSupportsRaw ()
                {
+                       // serializing reply
                        var ms = new MemoryStream ();
                        var bytes = new byte [] {0, 1, 2, 0xFF};
                        ms.Write (bytes, 0, bytes.Length);
@@ -213,6 +235,82 @@ namespace MonoTests.System.ServiceModel.Description
                        wme.WriteMessage (msg, ms2);
                        Assert.AreEqual (bytes, ms2.ToArray (), "#3");
                }
+
+               [Test]
+               public void MessageFormatterSupportsRaw2 ()
+               {
+                       // deserializing request
+                       var ms = new MemoryStream ();
+                       ms.Write (new byte [] {0, 1, 2, 0xFF}, 0, 4);
+                       ms.Position = 0;
+                       var cd = ContractDescription.GetContract (typeof (ITestService));
+                       var od = cd.Operations [0];
+                       var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
+                       var wmebe = new WebMessageEncodingBindingElement ();
+                       var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
+                       var msg = wme.ReadMessage (ms, 100, null); // "application/xml" causes error.
+                       var formatter = new WebHttpBehaviorExt ().DoGetRequestDispatchFormatter (od, se);
+                       object [] pars = new object [1];
+                       formatter.DeserializeRequest (msg, pars);
+                       Assert.IsTrue (pars [0] is Stream, "ret");
+               }
+#endif
+               [ServiceContract]
+               public interface IMultipleParametersGet
+               {
+                       [OperationContract]
+                       [WebGet (UriTemplate = "get")]
+                       void Get (string p1, string p2);
+               }
+
+               [ServiceContract]
+               public interface IMultipleParameters
+               {
+                       [OperationContract]
+                       [WebInvoke (UriTemplate = "posturi?p1={p1}&p2={p2}")]
+                       string PostUri (string p1, string p2);
+
+                       [OperationContract]
+                       [WebInvoke (UriTemplate = "postone?p1={p1}")]
+                       string PostOne (string p1, string p2);
+
+                       [OperationContract]
+                       [WebInvoke (UriTemplate = "postwrapped", BodyStyle=WebMessageBodyStyle.WrappedRequest)]
+                       string PostWrapped (string p1, string p2);
+
+                       [OperationContract]
+                       [WebInvoke (UriTemplate = "out?p1={p1}&p2={p2}", BodyStyle=WebMessageBodyStyle.WrappedResponse)]
+                       void PostOut (string p1, string p2, out string ret);
+               }
+
+               [Test]
+               public void MultipleParameters ()
+               {
+                       var behavior = new WebHttpBehaviorExt ();
+                       var cd = ContractDescription.GetContract (typeof (IMultipleParameters));
+                       var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
+                       behavior.Validate (se);
+
+                       foreach (var od in cd.Operations)
+                               behavior.DoGetRequestClientFormatter (od, se);
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void MultipleParameters2 ()
+               {
+                       var behavior = new WebHttpBehaviorExt ();
+                       var cd = ContractDescription.GetContract (typeof (IMultipleParametersGet));
+                       var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
+                       behavior.Validate (se);
+
+                       try {
+                               foreach (var od in cd.Operations)
+                                       behavior.DoGetRequestClientFormatter (od, se);
+                               Assert.Fail ("Should result in invalid operation");
+                       } catch (InvalidOperationException) {
+                       }
+               }
        }
 
        [ServiceContract]