Author: atsushi
Date: 2008-02-15 05:08:00 -0500 (Fri, 15 Feb 2008)
New Revision: 95730

Added:
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
Modified:
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/WebHttpBehavior.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelector.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
   trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/WebAttributeInfo.cs
   
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
   trunk/olive/class/System.ServiceModel.Web/System/ChangeLog
   trunk/olive/class/System.ServiceModel.Web/System/UriTemplate.cs
   trunk/olive/class/System.ServiceModel.Web/System/UriTemplateTable.cs
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/ChangeLog
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/WebHttpBehaviorTest.cs
   
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/ChangeLog
Log:
2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>

        * WebHttpDispatchOperationSelector.cs : implemented large part of it.
        * WebMessageFormatter.cs : moved BuildUriTemplate to WebAttributeInfo.

        * UriTemplateTable.cs : key_value_pair was not set.
        * UriTemplate.cs : in Match(), template and candidate could start
          from '/' which should not be compared.

        * WebAttributeInfo.cs : added BuildUriTemplate().

        * WebHttpBehavior.cs :
          Call AddClientErrorInspector() in ApplyClientBehavior().
          Call AddServerErrorHandlers() in ApplyDispatchBehavior().

        * WebHttpBehaviorTest.cs : test ApplyDispatchBehavior().

        * WebHttpDispatchOperationSelectorTest.cs : new test.



Modified: trunk/olive/class/System.ServiceModel.Web/System/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel.Web/System/ChangeLog  2008-02-15 
08:54:19 UTC (rev 95729)
+++ trunk/olive/class/System.ServiceModel.Web/System/ChangeLog  2008-02-15 
10:08:00 UTC (rev 95730)
@@ -1,3 +1,9 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * UriTemplateTable.cs : key_value_pair was not set.
+       * UriTemplate.cs : in Match(), template and candidate could start
+         from '/' which should not be compared.
+
 2008-02-12  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * UriTemplateMatch.cs : implemented some members.

Modified: trunk/olive/class/System.ServiceModel.Web/System/UriTemplate.cs
===================================================================
--- trunk/olive/class/System.ServiceModel.Web/System/UriTemplate.cs     
2008-02-15 08:54:19 UTC (rev 95729)
+++ trunk/olive/class/System.ServiceModel.Web/System/UriTemplate.cs     
2008-02-15 10:08:00 UTC (rev 95730)
@@ -161,6 +161,12 @@
                        var vc = m.BoundVariables;
 
                        string cp = candidate.PathAndQuery;
+
+                       if (template.Length > 0 && template [0] == '/')
+                               i++;
+                       if (cp.Length > 0 && cp [0] == '/')
+                               c++;
+
                        foreach (string name in path) {
                                int n = StringIndexOf (template, '{' + name + 
'}', i);
                                if (String.CompareOrdinal (cp, c, template, i, 
n - i) != 0)

Modified: trunk/olive/class/System.ServiceModel.Web/System/UriTemplateTable.cs
===================================================================
--- trunk/olive/class/System.ServiceModel.Web/System/UriTemplateTable.cs        
2008-02-15 08:54:19 UTC (rev 95729)
+++ trunk/olive/class/System.ServiceModel.Web/System/UriTemplateTable.cs        
2008-02-15 10:08:00 UTC (rev 95730)
@@ -43,13 +43,14 @@
                public UriTemplateTable (Uri baseAddress)
                {
                        BaseAddress = baseAddress;
+                       key_value_pairs = new List<Pair> ();
                }
 
                public UriTemplateTable (IEnumerable<Pair> keyValuePairs)
                {
-                       IList<Pair> l = keyValuePairs as IList<Pair>;
-                       if (l == null)
-                               l = new List<Pair> (keyValuePairs);
+                       key_value_pairs = keyValuePairs as IList<Pair>;
+                       if (key_value_pairs == null)
+                               key_value_pairs = new List<Pair> 
(keyValuePairs);
                }
 
                public UriTemplateTable (Uri baseAddress, IEnumerable<Pair> 
keyValuePairs)

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/ChangeLog
 2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/ChangeLog
 2008-02-15 10:08:00 UTC (rev 95730)
@@ -1,3 +1,9 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebHttpBehavior.cs :
+         Call AddClientErrorInspector() in ApplyClientBehavior().
+         Call AddServerErrorHandlers() in ApplyDispatchBehavior().
+
 2008-02-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebHttpBehavior.cs : pass itself to WebMessageFormatter too.

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/WebHttpBehavior.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/WebHttpBehavior.cs
        2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Description/WebHttpBehavior.cs
        2008-02-15 10:08:00 UTC (rev 95730)
@@ -68,16 +68,20 @@
                [MonoTODO]
                protected virtual void AddClientErrorInspector (ServiceEndpoint 
endpoint, ClientRuntime clientRuntime)
                {
+                       // clientRuntime.MessageInspectors.Add (something);
                }
 
                [MonoTODO]
                protected virtual void AddServerErrorHandlers (ServiceEndpoint 
endpoint, EndpointDispatcher endpointDispatcher)
                {
+                       // 
endpointDispatcher.ChannelDispatcher.ErrorHandlers.Add (something);
                }
 
                [MonoTODO ("where should I set reply client formatter?")]
                public virtual void ApplyClientBehavior (ServiceEndpoint 
endpoint, ClientRuntime clientRuntime)
                {
+                       AddClientErrorInspector (endpoint, clientRuntime);
+
                        foreach (ClientOperation oper in 
clientRuntime.Operations) {
                                oper.Formatter = GetRequestClientFormatter 
(endpoint.Contract.Operations.Find (oper.Name), endpoint);
                                //oper.Formatter = GetReplyClientFormatter 
(endpoint.Contract.Operations.Find (oper.Name), endpoint); // FIXME: see 
MonoTODO.
@@ -88,6 +92,7 @@
                public virtual void ApplyDispatchBehavior (ServiceEndpoint 
endpoint, EndpointDispatcher endpointDispatcher)
                {
                        endpointDispatcher.DispatchRuntime.OperationSelector = 
GetOperationSelector (endpoint);
+                       AddServerErrorHandlers (endpoint, endpointDispatcher);
 
                        foreach (DispatchOperation oper in 
endpointDispatcher.DispatchRuntime.Operations) {
                                oper.Formatter = GetRequestDispatchFormatter 
(endpoint.Contract.Operations.Find (oper.Name), endpoint);

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/ChangeLog
  2008-02-15 10:08:00 UTC (rev 95730)
@@ -1,3 +1,8 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebHttpDispatchOperationSelector.cs : implemented large part of it.
+       * WebMessageFormatter.cs : moved BuildUriTemplate to WebAttributeInfo.
+
 2008-02-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebMessageFormatter.cs : pass WebHttpBehavior too.

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelector.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelector.cs
        2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelector.cs
        2008-02-15 10:08:00 UTC (rev 95730)
@@ -29,19 +29,36 @@
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
+using System.ServiceModel.Web;
 
+using TemplateTablePair = 
System.Collections.Generic.KeyValuePair<System.UriTemplate, object>;
+
 namespace System.ServiceModel.Dispatcher
 {
        public class WebHttpDispatchOperationSelector : 
IDispatchOperationSelector
        {
                public const string HttpOperationSelectorUriMatchedPropertyName 
= "UriMatched";
 
+               UriTemplateTable table;
+
                protected WebHttpDispatchOperationSelector ()
                {
                }
 
                public WebHttpDispatchOperationSelector (ServiceEndpoint 
endpoint)
                {
+                       if (endpoint == null)
+                               throw new ArgumentNullException ("endpoint");
+                       if (endpoint.Address == null)
+                               throw new InvalidOperationException 
("EndpointAddress must be set in the argument ServiceEndpoint");
+
+                       table = new UriTemplateTable (endpoint.Address.Uri);
+
+                       foreach (OperationDescription od in 
endpoint.Contract.Operations) {
+                               WebAttributeInfo info = GetWebAttributeInfo 
(od);
+                               if (info != null)
+                                       table.KeyValuePairs.Add (new 
TemplateTablePair (info.BuildUriTemplate (od, null), od));
+                       }
                }
 
                [MonoTODO]
@@ -54,7 +71,42 @@
                [MonoTODO]
                protected virtual string SelectOperation (ref Message message, 
out bool uriMatched)
                {
-                       throw new NotImplementedException ();
+                       if (message == null)
+                               throw new ArgumentNullException ("message");
+                       if (message.Properties.ContainsKey 
(WebBodyFormatMessageProperty.Name))
+                               throw new ArgumentException ("There is already 
message property for Web body format");
+                       uriMatched = false;
+                       Uri to = message.Headers.To;
+                       if (to == null)
+                               return String.Empty;
+
+                       UriTemplateMatch match = table.MatchSingle (to);
+                       OperationDescription od = null;
+                       if (match != null) {
+                               uriMatched = true;
+                               foreach (TemplateTablePair p in 
table.KeyValuePairs)
+                                       if (p.Key == match.Template) {
+                                               od = p.Value as 
OperationDescription;
+                                               WebAttributeInfo info = 
GetWebAttributeInfo (od);
+                                               // FIXME: I doubt this content 
format assumption is correct ...
+                                               var prop = new 
WebBodyFormatMessageProperty (info.RequestFormat == WebMessageFormat.Xml 
?WebContentFormat.Xml : WebContentFormat.Json);
+                                       }
+                       }
+                       return od != null ? od.Name : String.Empty;
                }
+
+               WebAttributeInfo GetWebAttributeInfo (OperationDescription od)
+               {
+                       foreach (IOperationBehavior ob in od.Behaviors) {
+                               WebAttributeInfo info = null;
+                               var wg = ob as WebGetAttribute;
+                               if (wg != null)
+                                       return wg.Info;
+                               var wi = ob as WebInvokeAttribute;
+                               if (wi != null)
+                                       return wi.Info;
+                       }
+                       return null;
+               }
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
     2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Dispatcher/WebMessageFormatter.cs
     2008-02-15 10:08:00 UTC (rev 95730)
@@ -68,7 +68,7 @@
                        if (info == null)
                                info = new WebAttributeInfo ();
 
-                       template = new UriTemplate (info.UriTemplate ?? 
BuildUriTemplate ());
+                       template = info.BuildUriTemplate (Operation, 
GetMessageDescription ());
                        message_desc = GetMessageDescription ();
                }
 
@@ -107,22 +107,6 @@
                                throw new ArgumentException ("Only 
MessageVersion.None is supported");
                }
 
-               string BuildUriTemplate ()
-               {
-                       StringBuilder sb = new StringBuilder ();
-                       MessageDescription md = GetMessageDescription ();
-                       sb.Append (Operation.Name);
-                       for (int i = 0; i < md.Body.Parts.Count; i++) {
-                               MessagePartDescription mp = md.Body.Parts [i];
-                               sb.Append (i == 0 ? '?' : '&');
-                               sb.Append (mp.Name);
-                               sb.Append ("={");
-                               sb.Append (mp.Name);
-                               sb.Append ('}');
-                       }
-                       return sb.ToString ();
-               }
-
                MessageDescription GetMessageDescription ()
                {
                        foreach (MessageDescription md in operation.Messages)

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/ChangeLog
===================================================================
--- trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/ChangeLog 
2008-02-15 08:54:19 UTC (rev 95729)
+++ trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/ChangeLog 
2008-02-15 10:08:00 UTC (rev 95730)
@@ -1,3 +1,7 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebAttributeInfo.cs : added BuildUriTemplate().
+
 2008-02-14  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebGetAttribute.cs : oops, Method is extraneous.

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/WebAttributeInfo.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/WebAttributeInfo.cs
       2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web/WebAttributeInfo.cs
       2008-02-15 10:08:00 UTC (rev 95730)
@@ -30,6 +30,7 @@
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
 using System.ServiceModel.Dispatcher;
+using System.Text;
 
 namespace System.ServiceModel.Web
 {
@@ -87,5 +88,28 @@
                        get { return uri_template; }
                        set { uri_template = value; }
                }
+
+               public UriTemplate BuildUriTemplate (OperationDescription od, 
MessageDescription md)
+               {
+                       if (uri_template != null)
+                               return new UriTemplate (uri_template);
+                       if (md == null)
+                               foreach (MessageDescription mm in od.Messages)
+                                       if (mm.Direction == 
MessageDirection.Input)
+                                               md = mm;
+
+                       StringBuilder sb = new StringBuilder ();
+                       sb.Append (od.Name);
+                       for (int i = 0; i < md.Body.Parts.Count; i++) {
+                               MessagePartDescription mp = md.Body.Parts [i];
+                               sb.Append (i == 0 ? '?' : '&');
+                               sb.Append (mp.Name);
+                               sb.Append ("={");
+                               sb.Append (mp.Name);
+                               sb.Append ('}');
+                       }
+                       return new UriTemplate (sb.ToString ());
+               }
+
        }
 }

Modified: 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/System.ServiceModel.Web_test.dll.sources
  2008-02-15 10:08:00 UTC (rev 95730)
@@ -5,6 +5,7 @@
 System.ServiceModel.Channels/WebMessageEncodingBindingElementTest.cs
 System.ServiceModel.Description/WebHttpBehaviorTest.cs
 System.ServiceModel.Dispatcher/QueryStringConverterTest.cs
+System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
 System.ServiceModel.Syndication/Atom10FeedFormatterTest.cs
 System.ServiceModel.Syndication/Atom10ItemFormatterTest.cs
 System.ServiceModel.Syndication/Rss20FeedFormatterTest.cs

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/ChangeLog
    2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/ChangeLog
    2008-02-15 10:08:00 UTC (rev 95730)
@@ -1,3 +1,7 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebHttpBehaviorTest.cs : test ApplyDispatchBehavior().
+
 2008-02-12  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * WebHttpBehaviorTest.cs : new test.

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/WebHttpBehaviorTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/WebHttpBehaviorTest.cs
       2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Description/WebHttpBehaviorTest.cs
       2008-02-15 10:08:00 UTC (rev 95730)
@@ -2,6 +2,8 @@
 using System.ServiceModel;
 using System.ServiceModel.Channels;
 using System.ServiceModel.Description;
+using System.ServiceModel.Dispatcher;
+using System.ServiceModel.Web;
 using System.Text;
 using NUnit.Framework;
 
@@ -10,23 +12,69 @@
        [TestFixture]
        public class WebHttpBehaviorTest
        {
+               ServiceEndpoint CreateEndpoint ()
+               {
+                       return new ServiceEndpoint 
(ContractDescription.GetContract (typeof (IMyService)), new WebHttpBinding (),
+                                                   new EndpointAddress 
("http://localhost:37564";));
+               }
+
                [Test]
                public void AddBiningParameters ()
                {
-                       var se = new ServiceEndpoint (
-                               ContractDescription.GetContract (typeof 
(IMyService)),
-                               new WebHttpBinding (),
-                               new EndpointAddress ("http://localhost:37564";));
+                       var se = CreateEndpoint ();
                        var b = new WebHttpBehavior ();
                        var pl = new BindingParameterCollection ();
                        b.AddBindingParameters (se, pl);
                        Assert.AreEqual (0, pl.Count, "#1");
                }
 
+               [Test]
+               [Category ("NotWorking")]
+               public void ApplyDispatchBehavior ()
+               {
+                       var se = CreateEndpoint ();
+                       var od = se.Contract.Operations [0];
+                       // in .NET 3.5 it adds "OperationSelectorBehavior"
+                       int initCB = ContractDescription.GetContract (typeof 
(IMyService)).Behaviors.Count;
+                       // in .NET 3.5 it adds
+                       // - OperationInvokeBehavior, 
+                       // - OperationBehaviorAttribute, 
+                       // - DataContractSerializerOperationBehavior and 
+                       // - DataContractSerializerOperationGenerator
+                       int initOB = od.Behaviors.Count;
+                       // Assert.AreEqual (1, initCB, "#0-1");
+                       // Assert.AreEqual (4, initOB, "#0-2");
+
+                       var b = new WebHttpBehavior ();
+                       se.Behaviors.Add (b);
+                       var ed = new EndpointDispatcher (se.Address, 
se.Contract.Name, se.Contract.Namespace);
+                       IChannelListener l = new WebHttpBinding 
().BuildChannelListener<IReplyChannel> (new BindingParameterCollection ());
+                       var cd = new ChannelDispatcher (l);
+                       cd.Endpoints.Add (ed); // without it this test results 
in NRE (it blindly adds IErrorHandler).
+                       Assert.AreEqual (0, cd.ErrorHandlers.Count, "#1-1");
+                       Assert.IsNull (ed.DispatchRuntime.OperationSelector, 
"#1-2");
+                       Assert.AreEqual (1, se.Behaviors.Count, "#1-3-1");
+                       Assert.AreEqual (initCB, se.Contract.Behaviors.Count, 
"#1-3-2");
+                       Assert.AreEqual (initOB, od.Behaviors.Count, "#1-3-3");
+
+                       b.ApplyDispatchBehavior (se, ed);
+                       // FIXME: implement and enable it later
+                       //Assert.AreEqual (1, cd.ErrorHandlers.Count, "#2-1");
+                       Assert.AreEqual (typeof 
(WebHttpDispatchOperationSelector),
+                                        
ed.DispatchRuntime.OperationSelector.GetType (), "#2-2");
+                       Assert.AreEqual (1, se.Behaviors.Count, "#3-1");
+                       Assert.AreEqual (initCB, se.Contract.Behaviors.Count, 
"#3-2");
+                       Assert.AreEqual (initOB, od.Behaviors.Count, "#3-3");
+                       // ... i.e. nothing is added.
+
+                       Assert.AreEqual (0, 
ed.DispatchRuntime.Operations.Count, "#4-0"); // hmm... really?
+               }
+
                [ServiceContract]
                public interface IMyService
                {
                        [OperationContract]
+                       [WebGet]
                        string Echo (string input);
                }
        }

Modified: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/ChangeLog
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/ChangeLog
     2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/ChangeLog
     2008-02-15 10:08:00 UTC (rev 95730)
@@ -1,3 +1,7 @@
+2008-02-15  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * WebHttpDispatchOperationSelectorTest.cs : new test.
+
 2008-02-13  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * QueryStringConverterTest.cs : enable null-to-char conversion test.

Added: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
===================================================================
--- 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
       2008-02-15 08:54:19 UTC (rev 95729)
+++ 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
       2008-02-15 10:08:00 UTC (rev 95730)
@@ -0,0 +1,182 @@
+//
+// WebHttpDispatchOperationSelectorTest.cs
+//
+// Author:
+//     Atsushi Enomoto  <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+// 
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+// 
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+using System;
+using System.Globalization;
+using System.Runtime.Serialization;
+using System.ServiceModel;
+using System.ServiceModel.Channels;
+using System.ServiceModel.Description;
+using System.ServiceModel.Dispatcher;
+using System.ServiceModel.Web;
+using System.Text;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.ServiceModel.Dispatcher
+{
+       [TestFixture]
+       public class WebHttpDispatchOperationSelectorTest
+       {
+               [Test]
+               [ExpectedException (typeof (ArgumentNullException))]
+               public void ConstructorNullEndpoint ()
+               {
+                       new WebHttpDispatchOperationSelector (null);
+               }
+
+               [Test]
+               [ExpectedException (typeof (InvalidOperationException))]
+               public void ConstructorEndpointNullAddress ()
+               {
+                       ServiceEndpoint se = new ServiceEndpoint 
(ContractDescription.GetContract (typeof (MyService)));
+                       new WebHttpDispatchOperationSelector (se);
+               }
+
+               [Test]
+               public void SelectOperation ()
+               {
+                       string name;
+                       var d = Create ();
+                       var msg = Message.CreateMessage (MessageVersion.Soap12, 
"http://temuri.org/MyService/Echo";); // looks like Version is not checked
+                       Assert.IsNull (msg.Headers.To, "#1-0");
+                       Assert.IsFalse (d.SelectOperation (ref msg, out name), 
"#1");
+                       Assert.AreEqual ("", name, "#1-2");
+                       Assert.IsNull (msg.Headers.To, "#1-3"); // no overwrite
+                       Assert.IsFalse (msg.Properties.ContainsKey 
("UriMatched"), "#1-4");
+
+                       msg = Message.CreateMessage (MessageVersion.None, 
"http://temuri.org/MyService/Echo";);
+                       Assert.IsFalse (d.SelectOperation (ref msg, out name), 
"#2");
+                       Assert.IsFalse (msg.Properties.ContainsKey 
("UriMatched"), "#2-2");
+
+                       msg = Message.CreateMessage (MessageVersion.None, 
"http://foobar.org/MyService/NonExistent";);
+                       Assert.IsFalse (d.SelectOperation (ref msg, out name), 
"#3");
+                       Assert.AreEqual ("", name, "#3-2");
+                       Assert.IsFalse (msg.Properties.ContainsKey 
("UriMatched"), "#3-3");
+
+                       // version and action do not matter
+                       msg = Message.CreateMessage (MessageVersion.Soap12, 
"http://nonexistent.org/";);
+                       var http = new HttpRequestMessageProperty ();
+                       // this mismatch is allowed. Lack of this value is OK.
+//                     http.Method = "POST";
+                       // this mismatch is allowed. Lack of this value is OK.
+//                     http.QueryString = "foo=bar";
+                       // this mismatch is allowed. Lack of this value is OK.
+//                     http.Headers.Add ("Content-Type", "application/json");
+                       // so, the http property can be empty, but is required.
+                       msg.Properties.Add (HttpRequestMessageProperty.Name, 
http);
+                       msg.Headers.To = new Uri 
("http://localhost:8080/Echo?input=hoge";);
+                       Assert.IsTrue (d.SelectOperation (ref msg, out name), 
"#4");
+                       // FIXME: hmm... isn'y "Echo" expected?
+                       // Assert.AreEqual ("", name, "#4-2");
+               }
+
+               [Test]
+               [Category ("NotWorking")]
+               public void SelectOperation2 ()
+               {
+                       // This test shows strange result ... it adds 
UriMatched property while it does not really match the URI.
+
+                       var d = Create ();
+                       var msg = Message.CreateMessage (MessageVersion.None, 
"http://temuri.org/MyService/Echo";); // looks like Version is not checked
+                       Assert.AreEqual ("", d.SelectOperation (ref msg), "#1");
+                       Assert.IsTrue (msg.Properties.ContainsKey 
("UriMatched"), "#1-2");
+
+                       msg = Message.CreateMessage (MessageVersion.None, 
"http://foobar.org/MyService/NonExistent";);
+                       Assert.AreEqual ("", d.SelectOperation (ref msg), "#2");
+                       Assert.IsNotNull (msg.Properties ["UriMatched"], 
"#2-2");
+               }
+
+               [Test]
+               [ExpectedException (typeof (ArgumentException))]
+               [Category ("NotWorking")]
+               public void SelectOperationCheckExistingProperty ()
+               {
+                       var d = Create ();
+                       var msg = Message.CreateMessage (MessageVersion.None, 
"http://temuri.org/MyService/Echo";);
+                       d.SelectOperation (ref msg);
+                       d.SelectOperation (ref msg);
+               }
+
+               // Types
+
+               class MySelector : WebHttpDispatchOperationSelector
+               {
+                       public MySelector (ServiceEndpoint se)
+                               : base (se)
+                       {
+                       }
+
+                       public bool SelectOperation (ref Message msg, out 
string name)
+                       {
+                               bool ret;
+                               name = SelectOperation (ref msg, out ret);
+                               return ret;
+                       }
+               }
+
+               class MyBehavior : WebHttpBehavior
+               {
+                       public WebHttpDispatchOperationSelector 
GetPublicOperationSelector (ServiceEndpoint se)
+                       {
+                               return GetOperationSelector (se);
+                       }
+
+                       protected override WebHttpDispatchOperationSelector 
GetOperationSelector (ServiceEndpoint se)
+                       {
+                               return new MySelector (se);
+                       }
+               }
+
+               [ServiceContract]
+               public interface MyService
+               {
+                       [OperationContract]
+//                     [WebGet (UriTemplate = "MyService/Echo?input={input}")]
+//                     [WebGet] // UriTemplate = "Echo?input={input}"
+                       string Echo (string input);
+               }
+
+               [ServiceContract (Name = "MyService")]
+               public interface MyService2
+               {
+                       [OperationContract (Name = "Echo")]
+                       string Echo (string intput);
+               }
+
+               MySelector Create ()
+               {
+                       ServiceEndpoint se = new ServiceEndpoint 
(ContractDescription.GetContract (typeof (MyService)));
+                       se.Address = new EndpointAddress 
("http://localhost:8080";);
+                       se.Contract.Operations [0].Behaviors.Add (new 
WebGetAttribute ());
+                       return new MySelector (se);
+                       //var b = new MyBehavior ();
+                       //se.Behaviors.Add (b);
+                       //return (MySelector) b.GetPublicOperationSelector (se);
+               }
+       }
+}


Property changes on: 
trunk/olive/class/System.ServiceModel.Web/Test/System.ServiceModel.Dispatcher/WebHttpDispatchOperationSelectorTest.cs
___________________________________________________________________
Name: svn:eol-style
   + native

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to