Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
//
// ActionMessageFilterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 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.Collections.ObjectModel;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.Text;
using NUnit.Framework;
using Element = System.ServiceModel.Channels.TextMessageEncodingBindingElement;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class ActionMessageFilterTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNull ()
{
new ActionMessageFilter (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNull2 ()
{
new ActionMessageFilter ("foo", null);
}
[Test]
public void Match ()
{
ActionMessageFilter f = new ActionMessageFilter ("foo");
Assert.AreEqual (1, f.Actions.Count, "#1");
Message msg = Message.CreateMessage (MessageVersion.Default, "foo");
Assert.AreEqual ("foo", msg.Headers.Action, "#2");
Assert.IsTrue (f.Match (msg), "#3");
msg = Message.CreateMessage (MessageVersion.Default, "bar");
Assert.IsFalse (f.Match (msg), "#4");
f = new ActionMessageFilter ("foo", "bar");
Assert.AreEqual (2, f.Actions.Count, "#5");
Assert.IsTrue (f.Match (msg), "#6");
}
/*
[Test]
public void CreateMessageFilterTable ()
{
ActionMessageFilter f = new ActionMessageFilter ("foo");
IMessageFilterTable<int> t = f.CreateFilterTable<int> ();
Assert.AreEqual (0, t.Count, "#1");
t.Add (f, 0);
Assert.AreEqual (1, t.Count, "#2");
}
*/
}
}

View File

@@ -0,0 +1,378 @@
//
// Authors:
// David Straw
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2011 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.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Threading;
using NUnit.Framework;
using WebServiceMoonlightTest.ServiceReference1;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class Bug652331Test
{
[Test]
public void Bug652331_2 () // test in one of the comment
{
// Init service
ServiceHost serviceHost = new ServiceHost (typeof (Service1), new Uri ("http://localhost:37564/Service1"));
serviceHost.AddServiceEndpoint (typeof (IService1), new BasicHttpBinding (), string.Empty);
// Enable metadata exchange (WSDL publishing)
var mexBehavior = new ServiceMetadataBehavior ();
mexBehavior.HttpGetEnabled = true;
serviceHost.Description.Behaviors.Add (mexBehavior);
serviceHost.AddServiceEndpoint (typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding (), "mex");
serviceHost.Open ();
try {
// client
var binding = new BasicHttpBinding ();
var remoteAddress = new EndpointAddress ("http://localhost:37564/Service1");
var client = new Service1Client (binding, remoteAddress);
var wait = new ManualResetEvent (false);
client.GetDataCompleted += delegate (object o, GetDataCompletedEventArgs e) {
if (e.Error != null)
throw e.Error;
Assert.AreEqual ("A", ((DataType1) e.Result).Id, "#1");
wait.Set ();
};
client.GetDataAsync ();
if (!wait.WaitOne (TimeSpan.FromSeconds (10)))
Assert.Fail ("timeout");
} finally {
serviceHost.Close ();
}
}
public class Service1 : IService1
{
public object GetData ()
{
return new DataType1 { Id = "A" };
}
Func<object> d;
public IAsyncResult BeginGetData (AsyncCallback callback, object state)
{
if (d == null)
d = new Func<object> (GetData);
return d.BeginInvoke (callback, state);
}
public object EndGetData (IAsyncResult result)
{
return d.EndInvoke (result);
}
}
}
}
// below are part of autogenerated code in comment #1 on bug #652331.
namespace WebServiceMoonlightTest.ServiceReference1 {
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="DataType1", Namespace="http://mynamespace")]
public partial class DataType1 : object, System.ComponentModel.INotifyPropertyChanged {
private string IdField;
[System.Runtime.Serialization.DataMemberAttribute()]
public string Id {
get {
return this.IdField;
}
set {
if ((object.ReferenceEquals(this.IdField, value) != true)) {
this.IdField = value;
this.RaisePropertyChanged("Id");
}
}
}
public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertyName) {
System.ComponentModel.PropertyChangedEventHandler propertyChanged = this.PropertyChanged;
if ((propertyChanged != null)) {
propertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://mynamespace", ConfigurationName="ServiceReference1.IService1")]
[ServiceKnownType (typeof (DataType1))]
public interface IService1 {
[System.ServiceModel.OperationContractAttribute(AsyncPattern=true, Action="http://mynamespace/IService1/GetData", ReplyAction="http://mynamespace/IService1/GetDataResponse")]
[System.ServiceModel.ServiceKnownTypeAttribute(typeof(WebServiceMoonlightTest.ServiceReference1.DataType1))]
System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState);
object EndGetData(System.IAsyncResult result);
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public interface IService1Channel : WebServiceMoonlightTest.ServiceReference1.IService1, System.ServiceModel.IClientChannel {
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class GetDataCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs {
private object[] results;
public GetDataCompletedEventArgs(object[] results, System.Exception exception, bool cancelled, object userState) :
base(exception, cancelled, userState) {
this.results = results;
}
public object Result {
get {
base.RaiseExceptionIfNecessary();
return ((object)(this.results[0]));
}
}
}
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
public partial class Service1Client : System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
private BeginOperationDelegate onBeginGetDataDelegate;
private EndOperationDelegate onEndGetDataDelegate;
private System.Threading.SendOrPostCallback onGetDataCompletedDelegate;
private BeginOperationDelegate onBeginOpenDelegate;
private EndOperationDelegate onEndOpenDelegate;
private System.Threading.SendOrPostCallback onOpenCompletedDelegate;
private BeginOperationDelegate onBeginCloseDelegate;
private EndOperationDelegate onEndCloseDelegate;
private System.Threading.SendOrPostCallback onCloseCompletedDelegate;
public Service1Client() {
}
public Service1Client(string endpointConfigurationName) :
base(endpointConfigurationName) {
}
public Service1Client(string endpointConfigurationName, string remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public Service1Client(string endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) :
base(endpointConfigurationName, remoteAddress) {
}
public Service1Client(System.ServiceModel.Channels.Binding binding, System.ServiceModel.EndpointAddress remoteAddress) :
base(binding, remoteAddress) {
}
/*
public System.Net.CookieContainer CookieContainer {
get {
System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
if ((httpCookieContainerManager != null)) {
return httpCookieContainerManager.CookieContainer;
}
else {
return null;
}
}
set {
System.ServiceModel.Channels.IHttpCookieContainerManager httpCookieContainerManager = this.InnerChannel.GetProperty<System.ServiceModel.Channels.IHttpCookieContainerManager>();
if ((httpCookieContainerManager != null)) {
httpCookieContainerManager.CookieContainer = value;
}
else {
throw new System.InvalidOperationException("Unable to set the CookieContainer. Please make sure the binding contains an HttpC" +
"ookieContainerBindingElement.");
}
}
}
*/
public event System.EventHandler<GetDataCompletedEventArgs> GetDataCompleted;
public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> OpenCompleted;
public event System.EventHandler<System.ComponentModel.AsyncCompletedEventArgs> CloseCompleted;
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
System.IAsyncResult WebServiceMoonlightTest.ServiceReference1.IService1.BeginGetData(System.AsyncCallback callback, object asyncState) {
return base.Channel.BeginGetData(callback, asyncState);
}
[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]
object WebServiceMoonlightTest.ServiceReference1.IService1.EndGetData(System.IAsyncResult result) {
return base.Channel.EndGetData(result);
}
private System.IAsyncResult OnBeginGetData(object[] inValues, System.AsyncCallback callback, object asyncState) {
return ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).BeginGetData(callback, asyncState);
}
private object[] OnEndGetData(System.IAsyncResult result) {
object retVal = ((WebServiceMoonlightTest.ServiceReference1.IService1)(this)).EndGetData(result);
return new object[] {
retVal};
}
private void OnGetDataCompleted(object state) {
if ((this.GetDataCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.GetDataCompleted(this, new GetDataCompletedEventArgs(e.Results, e.Error, e.Cancelled, e.UserState));
}
}
public void GetDataAsync() {
this.GetDataAsync(null);
}
public void GetDataAsync(object userState) {
if ((this.onBeginGetDataDelegate == null)) {
this.onBeginGetDataDelegate = new BeginOperationDelegate(this.OnBeginGetData);
}
if ((this.onEndGetDataDelegate == null)) {
this.onEndGetDataDelegate = new EndOperationDelegate(this.OnEndGetData);
}
if ((this.onGetDataCompletedDelegate == null)) {
this.onGetDataCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnGetDataCompleted);
}
base.InvokeAsync(this.onBeginGetDataDelegate, null, this.onEndGetDataDelegate, this.onGetDataCompletedDelegate, userState);
}
private System.IAsyncResult OnBeginOpen(object[] inValues, System.AsyncCallback callback, object asyncState) {
return ((System.ServiceModel.ICommunicationObject)(this)).BeginOpen(callback, asyncState);
}
private object[] OnEndOpen(System.IAsyncResult result) {
((System.ServiceModel.ICommunicationObject)(this)).EndOpen(result);
return null;
}
private void OnOpenCompleted(object state) {
if ((this.OpenCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.OpenCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
public void OpenAsync() {
this.OpenAsync(null);
}
public void OpenAsync(object userState) {
if ((this.onBeginOpenDelegate == null)) {
this.onBeginOpenDelegate = new BeginOperationDelegate(this.OnBeginOpen);
}
if ((this.onEndOpenDelegate == null)) {
this.onEndOpenDelegate = new EndOperationDelegate(this.OnEndOpen);
}
if ((this.onOpenCompletedDelegate == null)) {
this.onOpenCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnOpenCompleted);
}
base.InvokeAsync(this.onBeginOpenDelegate, null, this.onEndOpenDelegate, this.onOpenCompletedDelegate, userState);
}
private System.IAsyncResult OnBeginClose(object[] inValues, System.AsyncCallback callback, object asyncState) {
return ((System.ServiceModel.ICommunicationObject)(this)).BeginClose(callback, asyncState);
}
private object[] OnEndClose(System.IAsyncResult result) {
((System.ServiceModel.ICommunicationObject)(this)).EndClose(result);
return null;
}
private void OnCloseCompleted(object state) {
if ((this.CloseCompleted != null)) {
InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
this.CloseCompleted(this, new System.ComponentModel.AsyncCompletedEventArgs(e.Error, e.Cancelled, e.UserState));
}
}
public void CloseAsync() {
this.CloseAsync(null);
}
public void CloseAsync(object userState) {
if ((this.onBeginCloseDelegate == null)) {
this.onBeginCloseDelegate = new BeginOperationDelegate(this.OnBeginClose);
}
if ((this.onEndCloseDelegate == null)) {
this.onEndCloseDelegate = new EndOperationDelegate(this.OnEndClose);
}
if ((this.onCloseCompletedDelegate == null)) {
this.onCloseCompletedDelegate = new System.Threading.SendOrPostCallback(this.OnCloseCompleted);
}
base.InvokeAsync(this.onBeginCloseDelegate, null, this.onEndCloseDelegate, this.onCloseCompletedDelegate, userState);
}
/*
protected override WebServiceMoonlightTest.ServiceReference1.IService1 CreateChannel() {
return new Service1ClientChannel(this);
}
private class Service1ClientChannel : ChannelBase<WebServiceMoonlightTest.ServiceReference1.IService1>, WebServiceMoonlightTest.ServiceReference1.IService1 {
public Service1ClientChannel(System.ServiceModel.ClientBase<WebServiceMoonlightTest.ServiceReference1.IService1> client) :
base(client) {
}
public System.IAsyncResult BeginGetData(System.AsyncCallback callback, object asyncState) {
object[] _args = new object[0];
System.IAsyncResult _result = base.BeginInvoke("GetData", _args, callback, asyncState);
return _result;
}
public object EndGetData(System.IAsyncResult result) {
object[] _args = new object[0];
object _result = ((object)(base.EndInvoke("GetData", _args, result)));
return _result;
}
}
*/
}
}

View File

@@ -0,0 +1,145 @@
2010-06-22 Atsushi Enomoto <atsushi@ximian.com>
* DispatchRuntimeTest.cs : add another line of assertion.
2010-06-18 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : had to disable a test that regressed from
validating duplicate listen URI. Possible remedy is described too.
2010-04-05 Atsushi Enomoto <atsushi@ximian.com>
* EndpointAddressMessageFilterTest.cs :
Add null arg case. Enable working test.
2010-04-05 Atsushi Enomoto <atsushi@ximian.com>
* DispatchRuntimeTest.cs : enabled working tests again.
2010-04-02 Atsushi Enomoto <atsushi@ximian.com>
* DispatchOperationTest.cs : added not-working FaultContractInfo test.
2010-03-18 Atsushi Enomoto <atsushi@ximian.com>
* XPathMessageContextTest.cs : new.
2010-01-06 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : format message correctly.
2009-12-02 Atsushi Enomoto <atsushi@ximian.com>
* DispatchRuntimeTest.cs :
I have to disable a lot of connective tests that somehow blocks
test runs. No idea why it started to happen though.
2009-09-17 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : add a test to make sure that
EndpointDispatcher.ChannelDispatcher property is filled by Add().
2009-09-11 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : refine AcceptChannel invocation check
and make it not to fail on .NET.
2009-07-02 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : add singleton instance context test
(but disabled, for some weird conflict).
2009-06-25 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : add some instance provider tests.
2009-06-23 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : make sure that the port to be in use is
available before running the tests. Check attach state.
* DispatchRuntimeTest.cs : make sure that it runs through all the
behavior tests.
2009-06-16 Atsushi Enomoto <atsushi@ximian.com>
* DispatchRuntimeTest.cs : add reasonable timeout and close client
appropriately. Objects are disposed in different ways than .NET.
Do not expect things automatically disposed as just time goes by.
2009-06-12 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : make sure to close service host,
within rational TimeSpan.
2009-06-09 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : add ServiceThrottle test, and comments.
2009-05-13 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : make sure ctor args are nullable.
2009-04-27 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs : added a couple of EndpointDispatcher
state tests.
2009-02-24 Atsushi Enomoto <atsushi@ximian.com>
* ChannelDispatcherTest.cs:
Ignore all failing-under-dotnet tests
2009-01-21 Atsushi Enomoto <atsushi@ximian.com>
* DispatchRuntimeTest.cs : disable failing test.
2008-05-22 Roei Erez <roeie@mainsoft.com>
* fix ContractDescription.GetContract implementation
* Refactor Request processing
* Add support for message inspectors
* Add support for InstanceContextProvider & InstanceProvider, including lifecycles events
like: ReleaseServiceInstance, Open, Close...
* Add relevant test cases.
2008-04-08 Roei Erez <roeie@mainsoft.com>
* Add tests ChannelDispatcherTest, EndpointDispatcherTest
2008-04-06 Roei Erez <roeie@mainsoft.com>
* EndpointDiaptcher: Added new tests (MessageFilter, ContractFilter)
2008-02-20 Atsushi Enomoto <atsushi@ximian.com>
* ExceptionHandlerTest.cs : disabled a test that is not in effect.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* PrefixEndpointAddressMessageFilterTest.cs : new test (not working).
2006-10-18 Ankit Jain <jankit@novell.com>
* EndpointAddressMessageFilterTest.cs (Match): Add more tests.
2006-10-05 Atsushi Enomoto <atsushi@ximian.com>
* EndpointAddressMessageFilterTest.cs : new test.
* EndpointDispatcherTest.cs : test type of the filter as well.
2006-08-10 Duncan Mak <duncan@novell.com>
* ExceptionHandlerTest.cs: New test.
2006-05-29 Atsushi Enomoto <atsushi@ximian.com>
* InvalidBodyAccessExceptionTest.cs, DispatchOperationTest.cs :
fix tests for beta2. Reduced evil English-only tests.
2006-04-05 Atsushi Enomoto <atsushi@ximian.com>
* ContractDescriptionTest.cs : added test to make sure to return
ContractDescription for the contract interface, not the actual type.
2006-03-16 Atsushi Enomoto <atsushi@ximian.com>
* DispatchOperationTest.cs DispatchRuntimeTest.cs : new tests.

View File

@@ -0,0 +1,477 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using NUnit.Framework;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class ChannelDispatcherTest
{
Uri CreateAvailableUri (string uriString)
{
var uri = new Uri (uriString);
try {
var t = new TcpListener (uri.Port);
t.Start ();
t.Stop ();
} catch (Exception ex) {
Assert.Fail (String.Format ("Port {0} is not open. It is likely previous tests have failed and the port is kept opened", uri.Port));
}
return uri;
}
[Test]
public void ConstructorNullBindingName ()
{
new ChannelDispatcher (new MyChannelListener (new Uri ("urn:foo")), null);
new ChannelDispatcher (new MyChannelListener (new Uri ("urn:foo")), null, null);
}
[Test]
public void ServiceThrottle ()
{
var cd = new ChannelDispatcher (new MyChannelListener<IReplyChannel> (new Uri ("urn:foo")));
var st = cd.ServiceThrottle;
Assert.IsNull (st, "#0");
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
h.AddServiceEndpoint (typeof (TestContract).FullName, new BasicHttpBinding (), "address");
h.ChannelDispatchers.Add (cd);
Assert.IsNull (st, "#1");
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
Assert.IsNull (ed.ChannelDispatcher, "#1-2");
ed.DispatchRuntime.Type = typeof (TestContract);
cd.Endpoints.Add (ed);
Assert.AreEqual (cd, ed.ChannelDispatcher, "#1-3");
cd.MessageVersion = MessageVersion.Default;
{
cd.Open (TimeSpan.FromSeconds (10));
try {
Assert.IsNull (st, "#2");
// so, can't really test actual slot values as it is null.
} finally {
cd.Close (TimeSpan.FromSeconds (10));
}
return;
}
}
[Test]
public void Collection_Add_Remove () {
Console.WriteLine ("STart test Collection_Add_Remove");
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
h.AddServiceEndpoint (typeof (TestContract).FullName, new BasicHttpBinding (), "address");
MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener (uri));
h.ChannelDispatchers.Add (d);
Assert.IsTrue (d.Attached, "#1");
h.ChannelDispatchers.Remove (d);
Assert.IsFalse (d.Attached, "#2");
h.ChannelDispatchers.Insert (0, d);
Assert.IsTrue (d.Attached, "#3");
h.ChannelDispatchers.Add (new MyChannelDispatcher (new MyChannelListener (uri)));
h.ChannelDispatchers.Clear ();
Assert.IsFalse (d.Attached, "#4");
}
[Test]
public void EndpointDispatcherAddTest ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener (uri));
d.Endpoints.Add (new EndpointDispatcher (new EndpointAddress (uri), "", ""));
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void EndpointDispatcherAddTest2 () {
var uri = CreateAvailableUri ("http://localhost:37564");
MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener (uri));
d.Endpoints.Add (new EndpointDispatcher (new EndpointAddress (uri), "", ""));
d.Open (); // the dispatcher must be attached.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void EndpointDispatcherAddTest3 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
MyChannelDispatcher d = new MyChannelDispatcher (new MyChannelListener (uri));
d.Endpoints.Add (new EndpointDispatcher (new EndpointAddress (uri), "", ""));
h.ChannelDispatchers.Add (d);
d.Open (); // missing MessageVersion
}
[Test]
[ExpectedException (typeof (InvalidOperationException))] // i.e. it is thrown synchronously in current thread.
public void EndpointDispatcherAddTest4 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
var listener = new MyChannelListener (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
Assert.IsNotNull (ed.DispatchRuntime, "#1");
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#2");
Assert.IsNull (ed.DispatchRuntime.InstanceContextProvider, "#3");
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#3.2");
Assert.IsNull (ed.DispatchRuntime.SingletonInstanceContext, "#4");
d.Endpoints.Add (ed);
d.MessageVersion = MessageVersion.Default;
h.ChannelDispatchers.Add (d);
// it misses DispatchRuntime.Type, which seems set
// automatically when the dispatcher is created in
// ordinal process but need to be set manually in this case.
try {
d.Open ();
try {
// should not reach here, but in case it didn't, it must be closed.
d.Close (TimeSpan.FromSeconds (10));
} catch {
}
} finally {
Assert.AreEqual (CommunicationState.Opened, listener.State, "#5");
}
}
[Test]
[ExpectedException (typeof (InvalidOperationException))] // i.e. it is thrown synchronously in current thread.
public void EndpointDispatcherAddTest5 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
var binding = new BasicHttpBinding ();
var listener = new MyChannelListener (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
d.Endpoints.Add (ed);
ed.DispatchRuntime.Type = typeof (TestContract); // different from Test4
d.MessageVersion = MessageVersion.Default;
h.ChannelDispatchers.Add (d);
// It rejects "unrecognized type" of the channel listener.
// Test6 uses IChannelListener<IReplyChannel> and works.
d.Open ();
// should not reach here, but in case it didn't, it must be closed.
d.Close (TimeSpan.FromSeconds (10));
}
[Test]
public void EndpointDispatcherAddTest6 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
var binding = new BasicHttpBinding ();
var listener = new MyChannelListener<IReplyChannel> (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
d.Endpoints.Add (ed);
Assert.IsFalse (d.Attached, "#x1");
ed.DispatchRuntime.Type = typeof (TestContract);
d.MessageVersion = MessageVersion.Default;
h.ChannelDispatchers.Add (d);
Assert.IsTrue (d.Attached, "#x2");
d.Open (); // At this state, it does *not* call AcceptChannel() yet.
Assert.IsFalse (listener.AcceptChannelTried, "#1");
Assert.IsFalse (listener.WaitForChannelTried, "#2");
Assert.IsNotNull (ed.DispatchRuntime, "#3");
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#4");
Assert.IsNull (ed.DispatchRuntime.InstanceContextProvider, "#5"); // it is not still set after ChannelDispatcher.Open().
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#5.2");
Assert.IsNull (ed.DispatchRuntime.SingletonInstanceContext, "#6");
d.Close (); // we don't have to even close it.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void EndpointDispatcherAddTest7 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
var binding = new BasicHttpBinding ();
var listener = new MyChannelListener<IReplyChannel> (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
d.Endpoints.Add (ed);
ed.DispatchRuntime.Type = typeof (TestContract);
d.MessageVersion = MessageVersion.Default;
// add service endpoint to open the host (unlike all tests above).
h.AddServiceEndpoint (typeof (TestContract),
new BasicHttpBinding (), uri.ToString ());
h.ChannelDispatchers.Clear ();
h.ChannelDispatchers.Add (d);
d.Open (); // At this state, it does *not* call AcceptChannel() yet.
// This rejects already-opened ChannelDispatcher.
h.Open (TimeSpan.FromSeconds (10));
// should not reach here, but in case it didn't, it must be closed.
h.Close (TimeSpan.FromSeconds (10));
}
[Test]
[Category ("NotWorking")]
// Validating duplicate listen URI causes this regression.
// Since it is niche, I rather fixed ServiceHostBase to introduce validation.
// It is probably because this code doesn't use ServiceEndpoint to build IChannelListener i.e. built without Binding.
// We can add an extra field to ChannelDispatcher to indicate that it is from ServiceEndpoint (i.e. with Binding),
// but it makes little sense especially for checking duplicate listen URIs. Duplicate listen URIs should be rejected anyways.
public void EndpointDispatcherAddTest8 ()
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (typeof (TestContract), uri);
var listener = new MyChannelListener<IReplyChannel> (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
d.Endpoints.Add (ed);
ed.DispatchRuntime.Type = typeof (TestContract);
d.MessageVersion = MessageVersion.Default;
// add service endpoint to open the host (unlike all tests above).
h.AddServiceEndpoint (typeof (TestContract),
new BasicHttpBinding (), uri.ToString ());
h.ChannelDispatchers.Clear ();
h.ChannelDispatchers.Add (d);
Assert.AreEqual (h, d.Host, "#0");
try {
h.Open (TimeSpan.FromSeconds (10));
Assert.AreEqual (3, h.ChannelDispatchers.Count, "#0"); // TestContract, d, mex
Assert.IsTrue (listener.BeginAcceptChannelTried, "#1"); // while it throws NIE ...
Assert.IsFalse (listener.WaitForChannelTried, "#2");
Assert.IsNotNull (ed.DispatchRuntime, "#3");
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#4");
Assert.IsNotNull (ed.DispatchRuntime.InstanceContextProvider, "#5"); // it was set after ServiceHost.Open().
Assert.IsNull (ed.DispatchRuntime.SingletonInstanceContext, "#6");
/*
var l = new HttpListener ();
l.Prefixes.Add (uri.ToString ());
l.Start ();
l.Stop ();
*/
} finally {
h.Close (TimeSpan.FromSeconds (10));
h.Abort ();
}
}
// FIXME: this test itself indeed passes, but some weird conflict that blocks correspoding port happens between this and somewhere (probably above)
// [Test]
public void EndpointDispatcherAddTest9 () // test singleton service
{
var uri = CreateAvailableUri ("http://localhost:37564");
ServiceHost h = new ServiceHost (new TestContract (), uri);
h.Description.Behaviors.Find<ServiceBehaviorAttribute> ().InstanceContextMode = InstanceContextMode.Single;
var listener = new MyChannelListener<IReplyChannel> (uri);
MyChannelDispatcher d = new MyChannelDispatcher (listener);
var ed = new EndpointDispatcher (new EndpointAddress (uri), "", "");
d.Endpoints.Add (ed);
ed.DispatchRuntime.Type = typeof (TestContract);
d.MessageVersion = MessageVersion.Default;
h.AddServiceEndpoint (typeof (TestContract), new BasicHttpBinding (), uri.ToString ());
h.ChannelDispatchers.Clear ();
Assert.IsNull (ed.DispatchRuntime.SingletonInstanceContext, "#1");
h.ChannelDispatchers.Add (d);
Assert.IsNull (ed.DispatchRuntime.SingletonInstanceContext, "#2");
try {
h.Open (TimeSpan.FromSeconds (10));
Assert.IsNull (ed.DispatchRuntime.InstanceProvider, "#4");
Assert.IsNotNull (ed.DispatchRuntime.InstanceContextProvider, "#5"); // it was set after ServiceHost.Open().
Assert.IsNotNull (ed.DispatchRuntime.SingletonInstanceContext, "#6");
} finally {
h.Close (TimeSpan.FromSeconds (10));
h.Abort ();
}
}
[ServiceContract]
public class TestContract
{
[OperationContract]
public void Process (string input) {
}
}
class MyChannelDispatcher : ChannelDispatcher
{
public bool Attached = false;
public MyChannelDispatcher (IChannelListener l) : base (l) { }
protected override void Attach (ServiceHostBase host) {
base.Attach (host);
Attached = true;
}
protected override void Detach (ServiceHostBase host) {
base.Detach (host);
Attached = false;
}
}
class MyChannelListener<TChannel> : MyChannelListener, IChannelListener<TChannel> where TChannel : class, IChannel
{
public MyChannelListener (Uri uri)
: base (uri)
{
}
public bool AcceptChannelTried { get; set; }
public bool BeginAcceptChannelTried { get; set; }
public TChannel AcceptChannel ()
{
AcceptChannelTried = true;
throw new NotImplementedException ();
}
public TChannel AcceptChannel (TimeSpan timeout)
{
AcceptChannelTried = true;
throw new NotImplementedException ();
}
public IAsyncResult BeginAcceptChannel (AsyncCallback callback, object state)
{
BeginAcceptChannelTried = true;
throw new NotImplementedException ();
}
public IAsyncResult BeginAcceptChannel (TimeSpan timeout, AsyncCallback callback, object state)
{
BeginAcceptChannelTried = true;
throw new NotImplementedException ();
}
public TChannel EndAcceptChannel (IAsyncResult result)
{
throw new NotImplementedException ();
}
}
class MyChannelListener : IChannelListener
{
public MyChannelListener (Uri uri)
{
Uri = uri;
}
public bool WaitForChannelTried { get; set; }
public CommunicationState State { get; set; }
#region IChannelListener Members
public IAsyncResult BeginWaitForChannel (TimeSpan timeout, AsyncCallback callback, object state)
{
WaitForChannelTried = true;
throw new NotImplementedException ();
}
public bool EndWaitForChannel (IAsyncResult result)
{
throw new NotImplementedException ();
}
public T GetProperty<T> () where T : class
{
throw new NotImplementedException ();
}
public Uri Uri { get; set; }
public bool WaitForChannel (TimeSpan timeout)
{
WaitForChannelTried = true;
throw new NotImplementedException ();
}
#endregion
#region ICommunicationObject Members
public void Abort ()
{
State = CommunicationState.Closed;
}
public IAsyncResult BeginClose (TimeSpan timeout, AsyncCallback callback, object state) {
throw new NotImplementedException ();
}
public IAsyncResult BeginClose (AsyncCallback callback, object state) {
throw new NotImplementedException ();
}
public IAsyncResult BeginOpen (TimeSpan timeout, AsyncCallback callback, object state) {
throw new NotImplementedException ();
}
public IAsyncResult BeginOpen (AsyncCallback callback, object state) {
throw new NotImplementedException ();
}
public void Close (TimeSpan timeout)
{
State = CommunicationState.Closed;
}
public void Close ()
{
State = CommunicationState.Closed;
}
public event EventHandler Closed;
public event EventHandler Closing;
public void EndClose (IAsyncResult result) {
throw new NotImplementedException ();
}
public void EndOpen (IAsyncResult result) {
throw new NotImplementedException ();
}
public event EventHandler Faulted;
public void Open (TimeSpan timeout)
{
State = CommunicationState.Opened;
}
public void Open ()
{
State = CommunicationState.Opened;
}
public event EventHandler Opened;
public event EventHandler Opening;
#endregion
}
}
}

View File

@@ -0,0 +1,181 @@
//
// DispatchOperationTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 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.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Security;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class DispatchOperationTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void TestConstructorNullName ()
{
new DispatchOperation (CreateRuntime (), null, null);
}
[Test]
public void TestConstructorNullAction ()
{
DispatchRuntime r = CreateRuntime ();
// null Action is allowed.
new DispatchOperation (r, String.Empty, null);
// null ReplyAction as well.
new DispatchOperation (r, String.Empty, null, null);
}
[Test]
public void TestConstructor ()
{
DispatchOperation o = new DispatchOperation (
CreateRuntime (), String.Empty, null, null);
Assert.IsTrue (o.DeserializeRequest, "#1");
Assert.IsTrue (o.SerializeReply, "#2");
Assert.IsNull (o.Formatter, "#3");
Assert.AreEqual (0, o.FaultContractInfos.Count, "#4");
Assert.IsNull (o.Invoker, "#5");
Assert.IsFalse (o.IsOneWay, "#6");
Assert.IsFalse (o.IsTerminating, "#7");
Assert.IsFalse (o.ReleaseInstanceBeforeCall, "#8");
Assert.IsFalse (o.ReleaseInstanceAfterCall, "#9");
Assert.IsFalse (o.TransactionAutoComplete, "#10");
Assert.IsFalse (o.TransactionRequired, "#11");
Assert.AreEqual (0, o.ParameterInspectors.Count, "#12");
}
DispatchRuntime CreateRuntime ()
{
return new EndpointDispatcher (
new EndpointAddress ("http://localhost:8080"), "IFoo", "urn:foo").DispatchRuntime;
}
[Test]
public void FaultContractInfos ()
{
var host = new ServiceHost (typeof (TestFaultContract));
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 ();
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 ();
}
}
[ServiceContract]
public interface ITestFaultContract
{
[OperationContract]
[FaultContract (typeof (PrivateAffairError), Action = "urn:myfault")]
string Run (string input);
}
class TestFaultContract : ITestFaultContract
{
public string Run (string input)
{
Assert.AreEqual (1, ContractDescription.GetContract (typeof (TestFaultContract)).Operations [0].Faults.Count, "s#0");
var dr = OperationContext.Current.EndpointDispatcher.DispatchRuntime;
Assert.AreEqual (1, dr.Operations.Count);
var dop = dr.Operations [0];
Assert.AreEqual ("Run", dop.Name, "s#1");
Assert.AreEqual (1, dop.FaultContractInfos.Count, "s#2");
var fci = dop.FaultContractInfos [0];
Assert.AreEqual (typeof (PrivateAffairError), fci.Detail, "s#3");
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");
}
}
[DataContract]
class PrivateAffairError
{
[DataMember]
public int ErrorCode { get; set; }
[DataMember]
public string Text { get; set; }
}
[DataContract]
class DerivedPrivateAffairError : PrivateAffairError
{
}
class DerivedFaultException : FaultException<PrivateAffairError>
{
public DerivedFaultException (PrivateAffairError error)
: base (error)
{ }
}
}
}

View File

@@ -0,0 +1,405 @@
//
// DispatchRuntimeTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 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.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Security;
using System.Xml;
using NUnit.Framework;
using System.Collections.ObjectModel;
using SMMessage = System.ServiceModel.Channels.Message;
using System.Threading;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class DispatchRuntimeTest
{
[Test]
public void TestConstructor ()
{
// This test is rather to just detect implementation
// differences than digging in-depth meanings, so feel
// free to change if MS implementation does not make
// sense.
DispatchRuntime r = new EndpointDispatcher (
new EndpointAddress ("http://localhost:8080"), "IFoo", "urn:foo").DispatchRuntime;
Assert.AreEqual (AuditLogLocation.Default,
r.SecurityAuditLogLocation, "#1");
Assert.IsTrue (r.AutomaticInputSessionShutdown, "#2");
Assert.IsNotNull (r.CallbackClientRuntime, "#3");
Assert.IsNull (r.ExternalAuthorizationPolicies, "#4");
Assert.IsFalse (r.IgnoreTransactionMessageProperty, "#5");
Assert.IsFalse (r.ImpersonateCallerForAllOperations, "#6");
Assert.AreEqual (0, r.InputSessionShutdownHandlers.Count, "#7");
Assert.AreEqual (0, r.InstanceContextInitializers.Count, "#8");
//Assert.AreEqual (0, r.InstanceContextLifetimes.Count, "#9");
Assert.IsNull (r.InstanceProvider, "#10");
Assert.IsNull (r.InstanceContextProvider, "#10-2");
Assert.AreEqual (AuditLevel.None,
r.MessageAuthenticationAuditLevel, "#11");
Assert.AreEqual (0, r.MessageInspectors.Count, "#12");
Assert.AreEqual (0, r.Operations.Count, "#13");
Assert.IsNull (r.OperationSelector, "#14");
// This is silly, but anyways there will be similar
// functionality that just represents unix "Groups".
Assert.AreEqual (PrincipalPermissionMode.UseWindowsGroups,
r.PrincipalPermissionMode, "#15");
Assert.IsFalse (r.ReleaseServiceInstanceOnTransactionComplete, "#16");
Assert.IsNull (r.RoleProvider, "#17");
Assert.AreEqual (AuditLevel.None, r.ServiceAuthorizationAuditLevel, "#18");
Assert.IsNull (r.ServiceAuthorizationManager, "#19");
Assert.IsTrue (r.SuppressAuditFailure, "#20");
Assert.IsNull (r.SynchronizationContext, "#21");
Assert.IsFalse (r.TransactionAutoCompleteOnSessionClose, "#22");
Assert.IsNull (r.Type, "#23");
Assert.IsNotNull (r.UnhandledDispatchOperation, "#24");
DispatchOperation udo = r.UnhandledDispatchOperation;
Assert.AreEqual ("*", udo.Name, "#24-2");
Assert.AreEqual ("*", udo.Action, "#24-3");
Assert.AreEqual ("*", udo.ReplyAction, "#24-4");
Assert.IsFalse (udo.IsOneWay, "#24-5");
}
[Test]
public void TestInstanceBehavior1 ()
{
Result res = new Result ();
MessageInspectBehavior b = new MessageInspectBehavior ();
b.instanceCtxInitializer = new MyInstanceContextInitializer (res);
b.instanceCtxProvider = new MyInstanceContextProvider (null, res);
//b.instanceProvider = new MyInstanceProvider (null, res);
b.msgInspect = new MyMessageInspector (res);
string expected = "GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , IsIdle , OperationContext , InstanceContext = Opened , NotifyIdle , OperationContext , InstanceContext = Opened , ";
TestInstanceBehavior (b, expected, res, 1);
Assert.IsTrue (res.Done, "done");
}
[Test]
public void TestInstanceBehavior2 ()
{
Result res = new Result ();
MessageInspectBehavior b = new MessageInspectBehavior ();
b.instanceCtxInitializer = new MyInstanceContextInitializer (res);
b.instanceCtxProvider = new MyInstanceContextProvider (null, res);
b.instanceProvider = new MyInstanceProvider (new AllActions (res), res);
b.msgInspect = new MyMessageInspector (res);
string expected = "GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , GetInstance1 , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , ReleaseInstance , OperationContext , InstanceContext = Opened , IsIdle , OperationContext , InstanceContext = Opened , NotifyIdle , OperationContext , InstanceContext = Opened , ";
TestInstanceBehavior (b, expected, res, 1);
Assert.IsTrue (res.Done, "done");
}
[Test]
public void TestInstanceBehavior3 ()
{
Result res = new Result ();
MessageInspectBehavior b = new MessageInspectBehavior ();
b.instanceCtxInitializer = new MyInstanceContextInitializer (res);
InstanceContext c = new InstanceContext (new AllActions (res));
b.instanceCtxProvider = new MyInstanceContextProvider (c, res);
b.instanceProvider = new MyInstanceProvider (new AllActions (res), res);
b.msgInspect = new MyMessageInspector (res);
string expected = "GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , ";
TestInstanceBehavior (b, expected, res, 1); Assert.IsTrue (res.Done, "done");
}
[Test]
public void TestInstanceBehavior4 ()
{
Result res = new Result ();
MessageInspectBehavior b = new MessageInspectBehavior ();
b.instanceCtxInitializer = new MyInstanceContextInitializer (res);
b.instanceCtxProvider = new MyInstanceContextProvider (null, res);
b.instanceProvider = new MyInstanceProvider (new AllActions (res), res);
b.msgInspect = new MyMessageInspector (res);
string expected = "GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , GetInstance1 , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , ReleaseInstance , OperationContext , InstanceContext = Opened , IsIdle , OperationContext , InstanceContext = Opened , NotifyIdle , OperationContext , InstanceContext = Opened , GetExistingInstanceContext , InitializeInstanceContext , OperationContext , InstanceContext = Opening , Initialize , OperationContext , InstanceContext = Opening , AfterReceiveRequest , OperationContext , InstanceContext = Opened , GetInstance1 , OperationContext , InstanceContext = Opened , BeforeSendReply , OperationContext , InstanceContext = Opened , ReleaseInstance , OperationContext , InstanceContext = Opened , IsIdle , OperationContext , InstanceContext = Opened , NotifyIdle , OperationContext , InstanceContext = Opened , ";
TestInstanceBehavior (b, expected, res, 2); Assert.IsTrue (res.Done, "done");
}
void TestInstanceBehavior (MessageInspectBehavior b, string expected, Result actual, int invocations)
{
ServiceHost h = new ServiceHost (typeof (AllActions), new Uri ("http://localhost:8080"));
try {
h.AddServiceEndpoint (typeof (IAllActions).FullName, new BasicHttpBinding (), "AllActions");
h.Description.Behaviors.Add (b);
ServiceDebugBehavior db = h.Description.Behaviors.Find<ServiceDebugBehavior> ();
db.IncludeExceptionDetailInFaults = true;
h.Open ();
foreach (ChannelDispatcher cd in h.ChannelDispatchers) {
foreach (var ed in cd.Endpoints) {
if (ed.ContractName == "IHttpGetHelpPageAndMetadataContract")
continue;
Assert.AreEqual (typeof (AllActions), ed.DispatchRuntime.Type, "Type property: " + ed.ContractName);
}
}
AllActionsProxy p = new AllActionsProxy (new BasicHttpBinding () { SendTimeout = TimeSpan.FromSeconds (5), ReceiveTimeout = TimeSpan.FromSeconds (5) }, new EndpointAddress ("http://localhost:8080/AllActions"));
for (int i = 0; i < invocations; ++i)
p.Get (10);
p.Close ();
//let ther server finish his work
Thread.Sleep (100);
Assert.AreEqual (expected, actual.string_res);
actual.Done = true;
}
finally {
h.Close ();
}
}
}
#region helpers
#region message inspectors
public class MessageInspectBehavior : IServiceBehavior
{
public MyMessageInspector msgInspect;
public MyInstanceContextProvider instanceCtxProvider;
public MyInstanceProvider instanceProvider;
public MyInstanceContextInitializer instanceCtxInitializer;
public void AddBindingParameters (ServiceDescription serviceDescription, ServiceHostBase serviceHostBase, Collection<ServiceEndpoint> endpoints, BindingParameterCollection bindingParameters) {
}
public void ApplyDispatchBehavior (ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {
ChannelDispatcher d = serviceHostBase.ChannelDispatchers [0] as ChannelDispatcher;
d.Endpoints [0].DispatchRuntime.MessageInspectors.Add (msgInspect);
d.Endpoints [0].DispatchRuntime.InstanceContextProvider = instanceCtxProvider;
d.Endpoints [0].DispatchRuntime.InstanceProvider = instanceProvider;
d.Endpoints [0].DispatchRuntime.InstanceContextInitializers.Add (instanceCtxInitializer);
}
public void Validate (ServiceDescription serviceDescription, ServiceHostBase serviceHostBase) {
}
}
public class MyMessageInspector : IDispatchMessageInspector
{
Result res;
public MyMessageInspector (Result result) {
res = result;
}
#region IDispatchMessageInspector Members
public object AfterReceiveRequest (ref Message request, IClientChannel channel, InstanceContext instanceContext) {
res.string_res += "AfterReceiveRequest , ";
res.AddCurrentOperationContextInfo ();
return null;
}
public void BeforeSendReply (ref Message reply, object correlationState) {
res.string_res += "BeforeSendReply , ";
res.AddCurrentOperationContextInfo ();
}
#endregion
}
#endregion
#region InstanceProvider
public class MyInstanceProvider : IInstanceProvider
{
object instance;
Result res;
public MyInstanceProvider (object obj, Result result) {
instance = obj;
res = result;
}
#region IInstanceProvider Members
public object GetInstance (InstanceContext instanceContext, Message message) {
res.string_res += "GetInstance1 , ";
res.AddCurrentOperationContextInfo ();
return instance;
}
public object GetInstance (InstanceContext instanceContext) {
res.string_res += "GetInstance2 , ";
res.AddCurrentOperationContextInfo ();
return instance;
}
public void ReleaseInstance (InstanceContext instanceContext, object instance) {
res.string_res += "ReleaseInstance , ";
res.AddCurrentOperationContextInfo ();
}
#endregion
}
#endregion
#region InstanceContextProvider
public class MyInstanceContextProvider : IInstanceContextProvider
{
InstanceContext existing;
Result res;
public MyInstanceContextProvider (InstanceContext exist, Result result) {
existing = exist;
res = result;
}
#region IInstanceContextProvider Members
public InstanceContext GetExistingInstanceContext (Message message, IContextChannel channel) {
res.string_res += "GetExistingInstanceContext , ";
res.AddCurrentOperationContextInfo ();
return existing;
}
public void InitializeInstanceContext (InstanceContext instanceContext, Message message, IContextChannel channel) {
res.string_res += "InitializeInstanceContext , ";
res.AddCurrentOperationContextInfo ();
}
public bool IsIdle (InstanceContext instanceContext) {
res.string_res += "IsIdle , ";
res.AddCurrentOperationContextInfo ();
return false;
}
public void NotifyIdle (InstanceContextIdleCallback callback, InstanceContext instanceContext) {
res.string_res += "NotifyIdle , ";
res.AddCurrentOperationContextInfo ();
}
#endregion
}
#endregion
#region InstanceContextInitializer
public class MyInstanceContextInitializer : IInstanceContextInitializer
{
Result res;
public MyInstanceContextInitializer (Result result) {
res = result;
}
public void Initialize (InstanceContext instanceContext, Message message) {
res.string_res += "Initialize , ";
res.AddCurrentOperationContextInfo ();
}
}
#endregion
#region Helpers
public class Result
{
public bool Done;
public string string_res = "";
public void AddCurrentOperationContextInfo()
{
if (OperationContext.Current != null) {
string_res += "OperationContext , ";
if (OperationContext.Current.InstanceContext != null) {
string_res += ("InstanceContext = " + OperationContext.Current.InstanceContext.State + " , ");
//if (OperationContext.Current.InstanceContext != null)
// string_res += ("Instance = " + OperationContext.Current.InstanceContext.GetServiceInstance () + " , ");
}
}
}
}
class AllActions : IAllActions, IDisposable
{
Result res;
public AllActions () { }
public AllActions (Result result) {
res = result;
}
[OperationBehavior (ReleaseInstanceMode = ReleaseInstanceMode.BeforeAndAfterCall)]
public int Get(int i)
{
return i;
}
public void Dispose () {
if (res != null)
res.string_res += "Disposed , ";
}
}
[ServiceContract (Namespace = "http://MonoTests.System.ServiceModel.Dispatcher")]
public interface IAllActions
{
[OperationContract]
int Get(int i);
}
#endregion
#region ClientProxy
public class AllActionsProxy : ClientBase<IAllActions>, IAllActions
{
public AllActionsProxy (Binding binding, EndpointAddress remoteAddress) :
base (binding, remoteAddress)
{
}
public int Get (int i) {
return base.Channel.Get (i);
}
}
#endregion
#endregion
}

View File

@@ -0,0 +1,88 @@
//
// EndpointAddressMessageFilterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2006 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class EndpointAddressMessageFilterTest
{
const string anonymous_uri = "http://www.w3.org/2005/08/addressing/anonymous";
static Message CreateMessageWithTo (string to)
{
return CreateMessageWithTo (new Uri (to));
}
static Message CreateMessageWithTo (Uri to)
{
Message msg = Message.CreateMessage (MessageVersion.Default, "urn:myaction");
msg.Headers.Add (MessageHeader.CreateHeader ("To", "http://www.w3.org/2005/08/addressing", to));
return msg;
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void CtorNoAddress ()
{
new EndpointAddressMessageFilter (null, false);
}
[Test]
public void Match ()
{
EndpointAddressMessageFilter f =
new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080"));
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080")), "#1");
Assert.IsTrue (f.Match (CreateMessageWithTo (new Uri ("http://localhost:8080"))), "#1-2");
Assert.IsFalse (f.Match (CreateMessageWithTo (anonymous_uri)), "#2");
Assert.IsFalse (f.Match (CreateMessageWithTo (EndpointAddress.AnonymousUri)), "#3");
Assert.IsFalse (f.Match (CreateMessageWithTo (EndpointAddress.NoneUri)), "#4");
// no To header
Assert.IsFalse (f.Match (Message.CreateMessage (MessageVersion.Default, "urn:myaction")), "#5");
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://10.1.1.1:8080")), "#6");
Assert.IsFalse (f.Match (CreateMessageWithTo ("http://10.1.1.1:8081")), "#7");
f = new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc"), true);
Assert.IsFalse (f.Match (CreateMessageWithTo ("http://127.0.0.2:8080/abc")), "#8");
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#9");
f = new EndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc?foo"), true);
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#10");
}
}
}

View File

@@ -0,0 +1,111 @@
//
// EndpointDispatcherTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2005-2006 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.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using NUnit.Framework;
using SMMessage = System.ServiceModel.Channels.Message;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class EndpointDispatcherTest
{
[Test]
public void Ctor ()
{
EndpointDispatcher d = new EndpointDispatcher (
new EndpointAddress ("localhost:8080"),
"test", "urn:foo");
// properties at the Created state.
Assert.IsTrue (d.AddressFilter is EndpointAddressMessageFilter, "#1");
Assert.IsNull (d.ChannelDispatcher, "#2");
Assert.IsNotNull (d.ContractFilter, "#3");
Assert.AreEqual ("test", d.ContractName, "#4");
Assert.AreEqual ("urn:foo", d.ContractNamespace, "#5");
Assert.IsNotNull (d.DispatchRuntime, "#6");
Assert.AreEqual (
new EndpointAddress ("localhost:8080"),
d.EndpointAddress, "#7");
Assert.AreEqual (0, d.FilterPriority, "#8");
Assert.IsNull (d.DispatchRuntime.OperationSelector, "#2-1");
Assert.AreEqual (0, d.DispatchRuntime.Operations.Count, "#2-2");
}
[Test]
public void MatchTest () {
EndpointDispatcher d = new EndpointDispatcher (
new EndpointAddress ("http://localhost:8000"), "test", "http://MonoTests.Tests");
Message mess = Message.CreateMessage (MessageVersion.Default, "action1", (object)null);
mess.Headers.To = new Uri ("http://localhost:8000");
Assert.IsTrue (d.AddressFilter.Match (mess), "#1");
mess.Headers.To = new Uri ("http://localhost:8001");
Assert.IsFalse (d.AddressFilter.Match (mess), "#2");
mess.Headers.Action = "Fail";
//MatchAllMessageFilter
Assert.IsTrue (d.ContractFilter.Match (mess), "#3");
d.ContractFilter = new ActionMessageFilter ("action1");
Assert.IsFalse (d.ContractFilter.Match (mess), "#4");
mess.Headers.Action = "action1";
Assert.IsTrue (d.ContractFilter.Match (mess), "#5");
}
[Test]
public void ActionMessageFilterTest () {
ServiceHost h = new ServiceHost (typeof (SpecificAction), new Uri ("http://localhost:8000"));
EndpointDispatcher ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:8000/address"),
typeof (SpecificAction).FullName,
typeof (SpecificAction).Namespace);
Assert.IsTrue (ed.ContractFilter is MatchAllMessageFilter, "#1");
}
[Test]
public void DispatchRuntimeProperty () {
ServiceHost h = new ServiceHost (typeof (SpecificAction), new Uri ("http://localhost:8000"));
EndpointDispatcher ed = new EndpointDispatcher (new EndpointAddress ("http://localhost:8000/address"),
typeof (SpecificAction).FullName,
typeof (SpecificAction).Namespace);
Assert.IsNotNull (ed.DispatchRuntime, "#1");
}
[ServiceContract]
class SpecificAction
{
[OperationContract (Action = "Specific", ReplyAction = "*")]
public SMMessage Get (SMMessage req) {
return null;
}
}
}
}

View File

@@ -0,0 +1,64 @@
//
// ExceptionHandlerTest.cs
//
// Author: Duncan Mak (duncan@novell.com)
//
// Copyright (C) 2006 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.Reflection;
using System.Runtime.ConstrainedExecution;
using System.ServiceModel.Dispatcher;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher {
[TestFixture]
public class ExceptionHandlerTest
{
[Test]
public void Ctor ()
{
Assert.IsTrue (ExceptionHandler.AlwaysHandle.HandleException (new Exception ()),
"AlwaysHandle");
Assert.IsNull (ExceptionHandler.AsynchronousThreadExceptionHandler,
"AsynchronousThreadExceptionHandler");
Assert.IsTrue (ExceptionHandler.TransportExceptionHandler.HandleException (new Exception ()),
"TransportExceptionHandler");
}
[Test]
[Ignore ("Wrong. Also, we don't have CER")]
public void AsynchronousThreadExceptionHandler ()
{
PropertyInfo p = typeof (ExceptionHandler).GetProperty ("AsynchronousThreadExceptionHandler");
object [] attrs = p.GetGetMethod ().GetCustomAttributes (false);
ReliabilityContractAttribute attr = attrs [0] as ReliabilityContractAttribute;
Assert.AreEqual (1, attrs.Length, "Contains only 1 attribute");
Assert.AreEqual (Cer.Success, attr.Cer, "attribute value #1");
Assert.AreEqual (Consistency.WillNotCorruptState,
attr.ConsistencyGuarantee, "attribute value #2");
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class MessageFilterTableTest
{
[Test]
public void TestGetPriority ()
{
MessageFilterTable<int> table = new MessageFilterTable<int> ();
MessageFilter f = new XPathMessageFilter ();
table.Add (f, 0);
Console.WriteLine (table.GetPriority (f));
}
[Test]
public void TestAdd ()
{
Console.WriteLine ();
}
}
}

View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel.Dispatcher;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class InvalidBodyAccessExceptionTest
{
[Test]
public void TestConstructor ()
{
FilterInvalidBodyAccessException e = new FilterInvalidBodyAccessException ();
NavigatorInvalidBodyAccessException f = new NavigatorInvalidBodyAccessException ();
// Don't expect Engligh.
// Assert.AreEqual ("Not allowed to navigate to body.", e.Message);
Assert.AreEqual (e.Message, f.Message);
}
}
}

View File

@@ -0,0 +1,82 @@
//
// PrefixEndpointAddressMessageFilterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc. http://www.novell.com
// Copyright 2011 Xamarin Inc (http://www.xamarin.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.Collections.Generic;
using System.Collections.ObjectModel;
using System.ServiceModel.Channels;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class PrefixEndpointAddressMessageFilterTest
{
const string anonymous_uri = "http://www.w3.org/2005/08/addressing/anonymous";
static Message CreateMessageWithTo (string to)
{
return CreateMessageWithTo (new Uri (to));
}
static Message CreateMessageWithTo (Uri to)
{
Message msg = Message.CreateMessage (MessageVersion.Default, "urn:myaction");
msg.Headers.Add (MessageHeader.CreateHeader ("To", "http://www.w3.org/2005/08/addressing", to));
return msg;
}
[Test]
public void Match ()
{
PrefixEndpointAddressMessageFilter f =
new PrefixEndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080"));
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080")), "#1");
Assert.IsTrue (f.Match (CreateMessageWithTo (new Uri ("http://localhost:8080"))), "#1-2");
Assert.IsTrue (f.Match (CreateMessageWithTo (anonymous_uri)), "#2");
Assert.IsTrue (f.Match (CreateMessageWithTo (EndpointAddress.AnonymousUri)), "#3");
Assert.IsTrue (f.Match (CreateMessageWithTo (EndpointAddress.NoneUri)), "#4");
// no To header
Assert.IsFalse (f.Match (Message.CreateMessage (MessageVersion.Default, "urn:myaction")), "#5");
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://10.1.1.1:8080")), "#6");
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://10.1.1.1:8081")), "#7");
f = new PrefixEndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc"), true);
Assert.IsFalse (f.Match (CreateMessageWithTo ("http://127.0.0.2:8080/abc")), "#8");
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#9");
f = new PrefixEndpointAddressMessageFilter (new EndpointAddress ("http://localhost:8080/abc?foo"), true);
Assert.IsTrue (f.Match (CreateMessageWithTo ("http://localhost:8080/abc?wsdl")), "#10");
}
}
}

View File

@@ -0,0 +1,58 @@
//
// XPathMessageContextTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2010 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.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Dispatcher;
using System.Xml;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Dispatcher
{
[TestFixture]
public class XPathMessageContextTest
{
XPathMessageContext ctx = new XPathMessageContext ();
[Test]
public void PredefinedNamespaces ()
{
Assert.AreEqual (Constants.Soap11, ctx.LookupNamespace ("s11"), "#1");
Assert.AreEqual (Constants.Soap12, ctx.LookupNamespace ("s12"), "#2");
// ... only them?
foreach (char c in "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
Assert.IsNull (ctx.LookupNamespace (c + ""), "char:" + c);
Assert.IsNull (ctx.LookupNamespace ("wsa"), "#3");
Assert.IsNull (ctx.LookupNamespace ("wsu"), "#4");
}
}
}