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,125 @@
2010-07-06 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : add test for bug #615800.
2010-07-06 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : add test for bug #615801.
2010-04-05 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : don't use ToUniversalTime()
which makes test results timezone dependent.
2010-03-10 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : oops, the test was careless.
Use fixed date.
2010-03-09 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : add test for bug #586169.
* JsonWriterTest.cs : add standalone write case for "\/".
2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs :
enable TypeIsNotPartsOfKnownTypes(), and add more related tests.
2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : make some tests narrow down
possible cause of errors to detect expected errors more precisely.
2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : null-string case is working.
2010-01-27 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : invalidate previous non-working
tests.
2010-01-25 Sebastien Pouliot <sebastien@ximian.com>
* DataContractJsonSerializerTest.cs: Add non-working test cases
for null-string, known types and handling floating point special
values
2009-12-11 Chris Toshok <toshok@ximian.com>
* DataContractJsonSerializerTest.cs: add a test case for
non-public properties.
2009-12-11 Atsushi Enomoto <atsushi@ximian.com>
* JsonReaderTest.cs : another number parse case.
2009-11-20 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : added ignored test case that
verifies 2.1 behavior (with another case that justifies removal
of the previous hack).
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : added test for
alwaysEmitTypeInformation argument.
2009-09-07 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : fix non-datacontract
serialization test. It depended on IPAddress field internals
(runtime serialization incompatibility).
2009-03-13 Andreia Gaita <avidigal@novell.com>
* JsonReaderTest.cs: test for skip and depth (if depth fails, skip is affected)
2009-02-02 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : fixed some tests to match
.NET RTM behavior. Added read-only collection case, (but [Ignore]d).
2009-02-02 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : added test for contract-less
serialization.
2008-02-18 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : added couple of DBNull tests.
2008-01-30 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : added deserialization tests
for typed object with "__type".
2008-01-30 Atsushi Enomoto <atsushi@ximian.com>
* JsonReaderTest.cs : test GetAttribute() for "__type".
2008-01-30 Atsushi Enomoto <atsushi@ximian.com>
* JsonReaderTest.cs : added tests for "__type" attributes (some of
them are not working yet).
2008-01-24 Atsushi Enomoto <atsushi@ximian.com>
* JsonReaderTest.cs : test "type" attribute in several nodes.
2008-01-24 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs : some more deserialization tests.
2008-01-22 Atsushi Enomoto <atsushi@ximian.com>
* JsonWriterTest.cs : added test for writing __type attribute.
* DataContractJsonSerializerTest.cs : added more random-ish tests.
2007-12-05 Atsushi Enomoto <atsushi@ximian.com>
* DataContractJsonSerializerTest.cs :
moved from Test/System.Runtime.Serialization and fixed some.
* JsonReaderTest.cs, JsonWriterTest.cs : moved from Test/System.Xml.

View File

@@ -0,0 +1,8 @@
2009-10-07 Atsushi Enomoto <atsushi@ximian.com>
* WebScriptServiceHostFactoryTest.cs : add tests for contract and
wrapped validity.
2009-10-02 Atsushi Enomoto <atsushi@ximian.com>
* WebScriptServiceHostFactoryTest.cs : new test.

View File

@@ -0,0 +1,93 @@
#if !MOBILE
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Channels;
using System.ServiceModel.Web;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Activation
{
class MyHostFactory : WebScriptServiceHostFactory
{
public ServiceHost DoCreateServiceHost (Type type, params Uri [] baseAddresses)
{
return CreateServiceHost (type, baseAddresses);
}
}
[TestFixture]
public class WebScriptServiceHostFactoryTest
{
[Test]
public void CreateServiceHost ()
{
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ("http://localhost:37564")});
Assert.IsFalse (host is WebServiceHost, "#1");
host.Open ();
host.Close ();
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ResponseWrappedIsInvalid ()
{
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ("http://localhost:37564")});
host.Open (); // should raise an error here.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void MultipleContract ()
{
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ("http://localhost:37564")});
host.Open ();
}
}
[ServiceContract]
public interface ITestService
{
[OperationContract]
string DoWork (string s1, string s2);
}
public class TestService : ITestService
{
public string DoWork (string s1, string s2)
{
return s1 + s2;
}
}
[ServiceContract]
public interface ITestService2
{
[OperationContract]
[WebGet (BodyStyle = WebMessageBodyStyle.WrappedResponse)]
string DoWork (string s1, string s2);
}
public class TestService2 : ITestService2
{
public string DoWork (string s1, string s2)
{
return s1 + s2;
}
}
public class TestServiceMultiple : ITestService, ITestService2
{
public string DoWork (string s1, string s2)
{
return s1 + s2;
}
}
}
#endif

View File

@@ -0,0 +1,29 @@
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs : add test for null
content type for ReadMessage() (allowed),
2010-06-22 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs : add test for
GetProperty<MessageVersion>().
2008-02-08 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs : more MessageEncoder test.
2008-02-08 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs : test
CanBuildChannelFactory() and CanBuildChannelListener().
Small test for BuildChannelFactory().
2008-02-05 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs : added MessageEncoder test.
* WebBodyFormatMessagePropertyTest.cs : fixed ToString() test.
2008-02-05 Atsushi Enomoto <atsushi@ximian.com>
* WebMessageEncodingBindingElementTest.cs,
WebBodyFormatMessagePropertyTest.cs : new test files.

View File

@@ -0,0 +1,21 @@
using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Channels
{
[TestFixture]
public class WebBodyFormatMessagePropertyTest
{
[Test]
public void Members ()
{
WebBodyFormatMessageProperty p = new WebBodyFormatMessageProperty (WebContentFormat.Json);
Assert.AreEqual ("WebBodyFormatMessageProperty", WebBodyFormatMessageProperty.Name, "#1");
Assert.AreEqual (WebContentFormat.Json, p.Format, "#2");
Assert.AreEqual ("WebBodyFormatMessageProperty: WebContentFormat=Json", p.ToString (), "#3");
}
}
}

View File

@@ -0,0 +1,171 @@
#if !MOBILE
using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel
{
[TestFixture]
public class WebMessageEncodingBindingElementTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void Constructor ()
{
new WebMessageEncodingBindingElement (null);
}
[Test]
public void DefaultPropertyValues ()
{
WebMessageEncodingBindingElement be = new WebMessageEncodingBindingElement ();
Assert.AreEqual (Encoding.UTF8, be.WriteEncoding, "#1");
}
MessageEncoder CreateEncoder ()
{
WebMessageEncodingBindingElement m = new WebMessageEncodingBindingElement ();
return m.CreateMessageEncoderFactory ().Encoder;
}
[Test]
public void MessageEncoder ()
{
var e = CreateEncoder ();
Assert.AreEqual ("application/xml", e.MediaType, "#1");
Assert.AreEqual ("application/xml; charset=utf-8", e.ContentType, "#2");
}
[Test]
[ExpectedException (typeof (ProtocolException))]
public void MessageEncoderWriteMessageSoap12 ()
{
var e = CreateEncoder ();
e.WriteMessage (Message.CreateMessage (MessageVersion.Soap12, "urn:foo"), Stream.Null);
}
[Test]
public void MessageEncoderWriteMessageXml ()
{
var e = CreateEncoder ();
MemoryStream ms = new MemoryStream ();
// FIXME: nothing -> "" (right now it outputs <anyType xsi:nil='true' ... />)
//e.WriteMessage (Message.CreateMessage (MessageVersion.None, "urn:foo"), ms);
//Assert.AreEqual ("", Encoding.UTF8.GetString (ms.ToArray ()));
e.WriteMessage (Message.CreateMessage (MessageVersion.None, "urn:foo", 135), ms);
Assert.AreEqual ("<int xmlns=\"http://schemas.microsoft.com/2003/10/Serialization/\">135</int>", Encoding.UTF8.GetString (ms.ToArray ()));
}
BindingContext CreateBindingContext ()
{
return new BindingContext (new CustomBinding (new HttpTransportBindingElement () { AllowCookies = true }), new BindingParameterCollection ());
}
BindingContext CreateBindingContext2 ()
{
return new BindingContext (new CustomBinding (new TcpTransportBindingElement ()), new BindingParameterCollection ());
}
[Test]
public void CanBuildChannelFactory ()
{
// with HttpTransport
var m = new WebMessageEncodingBindingElement ();
Assert.IsTrue (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#1");
Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#2");
Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#3");
Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#4");
// actually they are from transport
var h = new HttpTransportBindingElement ();
Assert.IsTrue (h.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext ()), "#5");
Assert.IsFalse (h.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext ()), "#6");
Assert.IsFalse (h.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext ()), "#7");
Assert.IsFalse (h.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext ()), "#8");
// with TcpTransport
Assert.IsFalse (m.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#9");
Assert.IsFalse (m.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#10");
Assert.IsFalse (m.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
Assert.IsFalse (m.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#12");
// ... yes, actually they are from transport
var t = new TcpTransportBindingElement ();
Assert.IsFalse (t.CanBuildChannelFactory<IRequestChannel> (CreateBindingContext2 ()), "#13");
Assert.IsFalse (t.CanBuildChannelFactory<IReplyChannel> (CreateBindingContext2 ()), "#14");
Assert.IsFalse (t.CanBuildChannelFactory<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
Assert.IsFalse (t.CanBuildChannelFactory<IDuplexChannel> (CreateBindingContext2 ()), "#16");
}
[Test]
public void CanBuildChannelListener ()
{
// with HttpTransport
var m = new WebMessageEncodingBindingElement ();
Assert.IsFalse (m.CanBuildChannelListener<IRequestChannel> (CreateBindingContext ()), "#1");
Assert.IsTrue (m.CanBuildChannelListener<IReplyChannel> (CreateBindingContext ()), "#2");
Assert.IsFalse (m.CanBuildChannelListener<IRequestSessionChannel> (CreateBindingContext ()), "#3");
Assert.IsFalse (m.CanBuildChannelListener<IDuplexChannel> (CreateBindingContext ()), "#4");
// actually they are from transport
var h = new HttpTransportBindingElement ();
Assert.IsFalse (h.CanBuildChannelListener<IRequestChannel> (CreateBindingContext ()), "#5");
Assert.IsTrue (h.CanBuildChannelListener<IReplyChannel> (CreateBindingContext ()), "#6");
Assert.IsFalse (h.CanBuildChannelListener<IRequestSessionChannel> (CreateBindingContext ()), "#7");
Assert.IsFalse (h.CanBuildChannelListener<IDuplexChannel> (CreateBindingContext ()), "#8");
// with TcpTransport
Assert.IsFalse (m.CanBuildChannelListener<IRequestChannel> (CreateBindingContext2 ()), "#9");
Assert.IsFalse (m.CanBuildChannelListener<IReplyChannel> (CreateBindingContext2 ()), "#10");
Assert.IsFalse (m.CanBuildChannelListener<IRequestSessionChannel> (CreateBindingContext2 ()), "#11");
Assert.IsFalse (m.CanBuildChannelListener<IDuplexChannel> (CreateBindingContext2 ()), "#12");
// ... yes, actually they are from transport
var t = new TcpTransportBindingElement ();
Assert.IsFalse (t.CanBuildChannelListener<IRequestChannel> (CreateBindingContext2 ()), "#13");
Assert.IsFalse (t.CanBuildChannelListener<IReplyChannel> (CreateBindingContext2 ()), "#14");
Assert.IsFalse (t.CanBuildChannelListener<IRequestSessionChannel> (CreateBindingContext2 ()), "#15");
Assert.IsFalse (t.CanBuildChannelListener<IDuplexChannel> (CreateBindingContext2 ()), "#16");
}
[Test]
public void BuildChannelFactory ()
{
var m = new WebMessageEncodingBindingElement ();
var f = m.BuildChannelFactory<IRequestChannel> (CreateBindingContext ());
Assert.AreEqual (f.GetType (), new HttpTransportBindingElement ().BuildChannelFactory<IRequestChannel> (CreateBindingContext ()).GetType (), "#1");
}
[Test]
public void GetPropertyMessageVersion ()
{
var m = new WebMessageEncodingBindingElement ();
var bc = new BindingContext (new CustomBinding (), new BindingParameterCollection ());
Assert.AreEqual (MessageVersion.None, m.GetProperty<MessageVersion> (bc), "#1");
}
[Test]
public void ReadMessageNullContentType ()
{
var e = CreateEncoder ();
e.ReadMessage (new MemoryStream (), 10, null);
}
[Test]
public void MessageEncoderIsContentTypeSupported ()
{
var enc = new WebMessageEncodingBindingElement ().CreateMessageEncoderFactory ().Encoder;
Assert.IsTrue (enc.IsContentTypeSupported ("application/xml"), "#1");
Assert.IsTrue (enc.IsContentTypeSupported ("text/xml"), "#2");
Assert.IsTrue (enc.IsContentTypeSupported ("application/soap+xml"), "#3");
Assert.IsTrue (enc.IsContentTypeSupported ("application/foobar+xml"), "#4"); // wow.
Assert.IsTrue (enc.IsContentTypeSupported ("application"), "#5"); // wow.
Assert.IsTrue (enc.IsContentTypeSupported (String.Empty), "#6"); // wow.
}
}
}
#endif

View File

@@ -0,0 +1,3 @@
2010-03-01 Sander Rijken <sr@d-90.nl>
* WebHttpBindingElementTest.cs : new test.

View File

@@ -0,0 +1,68 @@
#if !MOBILE
using System;
using System.ServiceModel.Configuration;
using NUnit.Framework;
using System.ServiceModel;
using System.Text;
using System.Configuration;
namespace MonoTests.System.ServiceModel.Configuration
{
[TestFixture]
public class WebHttpBindingElementTest
{
class Poker : WebHttpBindingElement
{
public Type GetBindingElementType ()
{
return BindingElementType;
}
}
[Test]
public void BindingElementType ()
{
Poker poker = new Poker ();
Assert.AreEqual (typeof (WebHttpBinding), poker.GetBindingElementType (), "BindingElementType");
}
[Test]
public void ApplyConfiguration ()
{
WebHttpBinding b = CreateBindingFromConfig ();
Assert.AreEqual (true, b.AllowCookies, "#1");
Assert.AreEqual (true, b.BypassProxyOnLocal, "#2");
Assert.AreEqual (HostNameComparisonMode.Exact, b.HostNameComparisonMode, "#3");
Assert.AreEqual (262144, b.MaxBufferPoolSize, "#4");
Assert.AreEqual (32768, b.MaxBufferSize, "#5");
Assert.AreEqual (16384, b.MaxReceivedMessageSize, "#6");
Assert.AreEqual ("proxy", b.ProxyAddress.ToString (), "#7");
Assert.AreEqual (Encoding.Unicode, b.WriteEncoding, "#8");
Assert.AreEqual (TransferMode.Streamed, b.TransferMode, "#9");
}
[Test]
public void Security ()
{
WebHttpBinding b = CreateBindingFromConfig ();
Assert.AreEqual (WebHttpSecurityMode.TransportCredentialOnly, b.Security.Mode, "#1");
Assert.AreEqual (HttpClientCredentialType.Basic, b.Security.Transport.ClientCredentialType, "#2");
}
private WebHttpBinding CreateBindingFromConfig ()
{
ServiceModelSectionGroup config = (ServiceModelSectionGroup) ConfigurationManager.OpenExeConfiguration ("Test/config/webHttpBinding").GetSectionGroup ("system.serviceModel");
WebHttpBindingCollectionElement collectionElement = (WebHttpBindingCollectionElement) config.Bindings ["webHttpBinding"];
WebHttpBindingElement el = collectionElement.Bindings ["WebHttpBinding1_Service"];
WebHttpBinding b = new WebHttpBinding ();
el.ApplyConfiguration (b);
return b;
}
}
}
#endif

View File

@@ -0,0 +1,34 @@
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : add test for deserializing Raw request
message too.
2010-07-14 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : add test for bug #619542 (not sure if it
works on mono; run-test is broken in trunk. Verified under .NET).
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* WebScriptEnablingBehaviorTest.cs : new test.
2009-09-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : enable working test.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : some message formatters tests.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : test that ApplyDispatchBehavior() sets
address filter.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : test ApplyDispatchBehavior().
2008-02-12 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpBehaviorTest.cs : new test.

View File

@@ -0,0 +1,324 @@
using System;
using System.IO;
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 NUnit.Framework;
namespace MonoTests.System.ServiceModel.Description
{
public class WebHttpBehaviorExt : WebHttpBehavior
{
public IClientMessageFormatter DoGetReplyClientFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
{
return GetReplyClientFormatter (operationDescription, endpoint);
}
public IClientMessageFormatter DoGetRequestClientFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
{
return GetRequestClientFormatter (operationDescription, endpoint);
}
#if !MOBILE
public IDispatchMessageFormatter DoGetReplyDispatchFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
{
return GetReplyDispatchFormatter (operationDescription, endpoint);
}
public IDispatchMessageFormatter DoGetRequestDispatchFormatter (OperationDescription operationDescription, ServiceEndpoint endpoint)
{
return GetRequestDispatchFormatter (operationDescription, endpoint);
}
#endif
public event Action<ServiceEndpoint, ClientRuntime> ApplyClientBehaviorInvoked;
public override void ApplyClientBehavior (ServiceEndpoint endpoint, ClientRuntime client)
{
base.ApplyClientBehavior (endpoint, client);
if (ApplyClientBehaviorInvoked != null)
ApplyClientBehaviorInvoked (endpoint, client);
}
}
[TestFixture]
public class WebHttpBehaviorTest
{
ServiceEndpoint CreateEndpoint ()
{
return new ServiceEndpoint (ContractDescription.GetContract (typeof (IMyService)), new WebHttpBinding (),
new EndpointAddress ("http://localhost:37564"));
}
[Test]
public void DefaultValues ()
{
var b = new WebHttpBehavior ();
Assert.AreEqual (WebMessageBodyStyle.Bare, b.DefaultBodyStyle, "#1");
Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingRequestFormat, "#2");
Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingResponseFormat, "#3");
#if NET_4_0
Assert.IsFalse (b.AutomaticFormatSelectionEnabled, "#11");
Assert.IsFalse (b.FaultExceptionEnabled, "#12");
Assert.IsFalse (b.HelpEnabled, "#13");
#endif
}
[Test]
public void AddBiningParameters ()
{
var se = CreateEndpoint ();
var b = new WebHttpBehavior ();
var pl = new BindingParameterCollection ();
b.AddBindingParameters (se, pl);
Assert.AreEqual (0, pl.Count, "#1");
}
#if !MOBILE
[Test]
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");
Assert.IsTrue (ed.AddressFilter is EndpointAddressMessageFilter, "#1-4");
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.IsTrue (ed.AddressFilter is PrefixEndpointAddressMessageFilter, "#3-4");
Assert.AreEqual (0, ed.DispatchRuntime.Operations.Count, "#4-0"); // hmm... really?
}
#endif
[Test]
public void GetMessageFormatters ()
{
var se = CreateEndpoint ();
var od = se.Contract.Operations [0];
var b = new WebHttpBehaviorExt ();
Assert.IsNotNull (b.DoGetRequestClientFormatter (od, se), "#1");
Assert.IsNotNull (b.DoGetReplyClientFormatter (od, se), "#2");
#if !MOBILE
Assert.IsNotNull (b.DoGetRequestDispatchFormatter (od, se), "#3");
Assert.IsNotNull (b.DoGetReplyDispatchFormatter (od, se), "#4");
#endif
}
[Test]
public void RequestClientFormatter ()
{
var se = CreateEndpoint ();
var od = se.Contract.Operations [0];
var b = new WebHttpBehaviorExt ();
var rcf = b.DoGetRequestClientFormatter (od, se);
var msg = rcf.SerializeRequest (MessageVersion.None, new object [] {"foo"});
var hp = msg.Properties [HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
Assert.IsNotNull (hp, "#1");
Assert.IsTrue (msg.IsEmpty, "#2");
Assert.AreEqual (String.Empty, hp.QueryString, "#3");
var mb = msg.CreateBufferedCopy (1000);
try {
rcf.DeserializeReply (mb.CreateMessage (), new object [0]);
Assert.Fail ("It should not support reply deserialization");
} catch (NotSupportedException) {
}
}
#if !MOBILE
[Test]
public void RequestClientFormatter2 ()
{
var se = CreateEndpoint ();
var od = se.Contract.Operations [0];
var b = new WebHttpBehaviorExt ();
IClientMessageFormatter rcf = null;
b.ApplyClientBehaviorInvoked += delegate (ServiceEndpoint e, ClientRuntime cr) {
rcf = cr.Operations [0].Formatter;
};
se.Behaviors.Add (b);
var ch = new WebChannelFactory<IMyServiceClient> (se).CreateChannel ();
var msg = rcf.SerializeRequest (MessageVersion.None, new object [] {"foo"});
var hp = msg.Properties [HttpRequestMessageProperty.Name] as HttpRequestMessageProperty;
Assert.IsNotNull (hp, "#1");
Assert.IsTrue (msg.IsEmpty, "#2");
Assert.AreEqual (String.Empty, hp.QueryString, "#3");
//var mb = msg.CreateBufferedCopy (1000);
// TODO: test DeserializeReply too (it is supported unlike above).
}
#endif
[ServiceContract]
public interface IMyService
{
[OperationContract]
[WebGet]
string Echo (string input);
}
public interface IMyServiceClient : IMyService, IClientChannel
{
}
public class MyService: IMyService
{
#if !MOBILE
[OperationBehavior]
#endif
public string Echo (string input)
{
return input;
}
}
[Test]
public void TestWebGetExists()
{
ContractDescription cd = ContractDescription.GetContract (typeof(IMyService), typeof (MyService));
OperationDescription od = cd.Operations[0];
Assert.IsTrue (od.Behaviors.Contains (typeof (WebGetAttribute)), "Operation is recognized as WebGet");
}
#if !MOBILE
[Test]
public void MessageFormatterSupportsRaw ()
{
// serializing reply
var ms = new MemoryStream ();
var bytes = new byte [] {0, 1, 2, 0xFF};
ms.Write (bytes, 0, bytes.Length);
ms.Position = 0;
var cd = ContractDescription.GetContract (typeof (ITestService));
var od = cd.Operations [0];
var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:37564/"));
var formatter = new WebHttpBehaviorExt ().DoGetReplyDispatchFormatter (od, se);
var msg = formatter.SerializeReply (MessageVersion.None, null, ms);
var wp = msg.Properties ["WebBodyFormatMessageProperty"] as WebBodyFormatMessageProperty;
Assert.IsNotNull (wp, "#1");
Assert.AreEqual (WebContentFormat.Raw, wp.Format, "#2");
var wmebe = new WebMessageEncodingBindingElement ();
var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
var ms2 = new MemoryStream ();
wme.WriteMessage (msg, ms2);
Assert.AreEqual (bytes, ms2.ToArray (), "#3");
}
[Test]
public void MessageFormatterSupportsRaw2 ()
{
// deserializing request
var ms = new MemoryStream ();
ms.Write (new byte [] {0, 1, 2, 0xFF}, 0, 4);
ms.Position = 0;
var cd = ContractDescription.GetContract (typeof (ITestService));
var od = cd.Operations [0];
var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
var wmebe = new WebMessageEncodingBindingElement ();
var wme = wmebe.CreateMessageEncoderFactory ().Encoder;
var msg = wme.ReadMessage (ms, 100, null); // "application/xml" causes error.
var formatter = new WebHttpBehaviorExt ().DoGetRequestDispatchFormatter (od, se);
object [] pars = new object [1];
formatter.DeserializeRequest (msg, pars);
Assert.IsTrue (pars [0] is Stream, "ret");
}
#endif
[ServiceContract]
public interface IMultipleParametersGet
{
[OperationContract]
[WebGet (UriTemplate = "get")]
void Get (string p1, string p2);
}
[ServiceContract]
public interface IMultipleParameters
{
[OperationContract]
[WebInvoke (UriTemplate = "posturi?p1={p1}&p2={p2}")]
string PostUri (string p1, string p2);
[OperationContract]
[WebInvoke (UriTemplate = "postone?p1={p1}")]
string PostOne (string p1, string p2);
[OperationContract]
[WebInvoke (UriTemplate = "postwrapped", BodyStyle=WebMessageBodyStyle.WrappedRequest)]
string PostWrapped (string p1, string p2);
[OperationContract]
[WebInvoke (UriTemplate = "out?p1={p1}&p2={p2}", BodyStyle=WebMessageBodyStyle.WrappedResponse)]
void PostOut (string p1, string p2, out string ret);
}
[Test]
public void MultipleParameters ()
{
var behavior = new WebHttpBehaviorExt ();
var cd = ContractDescription.GetContract (typeof (IMultipleParameters));
var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
behavior.Validate (se);
foreach (var od in cd.Operations)
behavior.DoGetRequestClientFormatter (od, se);
}
[Test]
[Category ("NotWorking")]
public void MultipleParameters2 ()
{
var behavior = new WebHttpBehaviorExt ();
var cd = ContractDescription.GetContract (typeof (IMultipleParametersGet));
var se = new ServiceEndpoint (cd, new WebHttpBinding (), new EndpointAddress ("http://localhost:8080/"));
behavior.Validate (se);
try {
foreach (var od in cd.Operations)
behavior.DoGetRequestClientFormatter (od, se);
Assert.Fail ("Should result in invalid operation");
} catch (InvalidOperationException) {
}
}
}
[ServiceContract]
public interface ITestService
{
[OperationContract]
Stream Receive (Stream input);
}
}

View File

@@ -0,0 +1,35 @@
#if NET_4_0 && !MOBILE
using System;
using System.IO;
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 NUnit.Framework;
namespace MonoTests.System.ServiceModel.Description
{
[TestFixture]
public class WebHttpEndpointTest
{
[Test]
public void ReplaceBinding1 ()
{
var se = new WebHttpEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null);
se.Binding = new NetTcpBinding (); // this does not throw exception yet.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void ReplaceBinding2 ()
{
var se = new WebHttpEndpoint (ContractDescription.GetContract (typeof (IMetadataExchange)), null);
se.Binding = new NetTcpBinding ();
se.WriteEncoding = Encoding.UTF8;
}
}
}
#endif

View File

@@ -0,0 +1,115 @@
//
// WebScriptEnablingBehaviorTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2009 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.
//
#if !MOBILE
using System;
using System.Net;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using System.ServiceModel.Web;
using System.Text;
using NUnit.Framework;
namespace MonoTests.System.ServiceModel.Description
{
public class MyHostFactory : WebScriptServiceHostFactory
{
// Calling CreateServiceHost(string,Uri[]) is not valid outside ASP.NET
// so we have to use custom factory...
public ServiceHost CreateServiceHost (Type type)
{
return CreateServiceHost (type, new Uri [0]);
}
}
[TestFixture]
public class WebScriptEnablingBehaviorTest
{
/*
ServiceEndpoint CreateEndpoint ()
{
return new ServiceEndpoint (ContractDescription.GetContract (typeof (IMyService)), new WebHttpBinding (),
new EndpointAddress ("http://localhost:37564"));
}
*/
[Test]
public void ScriptGenerator ()
{
var url = "http://localhost:37564";
var host = new MyHostFactory ().CreateServiceHost (typeof (HogeService));
var binding = new WebHttpBinding ();
host.AddServiceEndpoint (typeof (IHogeService), binding, url);
host.Open ();
try {
var wc = new WebClient ();
var s = wc.DownloadString (url + "/js");
Assert.IsTrue (s.IndexOf ("IHogeService") > 0, "#1");
Assert.IsTrue (s.IndexOf ("Join") > 0, "#2");
s = wc.DownloadString (url + "/jsdebug");
Assert.IsTrue (s.IndexOf ("IHogeService") > 0, "#3");
Assert.IsTrue (s.IndexOf ("Join") > 0, "#4");
s = wc.DownloadString (url + "/Join?s1=foo&s2=bar");
Assert.AreEqual ("{\"d\":\"foobar\"}", s, "#5");
} finally {
host.Close ();
}
}
[ServiceContract]
public interface IHogeService
{
[WebGet]
[OperationContract]
string Echo (string s);
[WebGet]
// error -> [WebGet (BodyStyle = WebMessageBodyStyle.Wrapped)]
[OperationContract]
string Join (string s1, string s2);
}
public class HogeService : IHogeService
{
public string Echo (string s)
{
return "heh, I don't";
}
public string Join (string s1, string s2)
{
Console.WriteLine ("{0} + {1}", s1, s2);
return s1 + s2;
}
}
}
}
#endif

View File

@@ -0,0 +1,35 @@
2010-05-24 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverterTest.cs : add more tests for CanConvert()
and reorganized some classes to make tests rational.
2009-10-08 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverterTest.cs : added some string deserialization
test. It just proved .NET is too lame.
2009-09-02 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverterTest.cs : comment out one cosmetic case
that is not working under .NET.
2008-02-18 Atsushi Enomoto <atsushi@ximian.com>
* JsonQueryStringConverterTest.cs : new test.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelectorTest.cs : added couple more tests
with different contract contract case.
2008-02-15 Atsushi Enomoto <atsushi@ximian.com>
* WebHttpDispatchOperationSelectorTest.cs : new test.
2008-02-13 Atsushi Enomoto <atsushi@ximian.com>
* QueryStringConverterTest.cs : enable null-to-char conversion test.
2008-02-13 Atsushi Enomoto <atsushi@ximian.com>
* QueryStringConverterTest.cs : new test.

View File

@@ -0,0 +1,327 @@
//
// JsonQueryStringConverterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2008 Novell, Inc (http://www.novell.com)
// Copyright 2014 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.ComponentModel;
using System.Globalization;
using System.Runtime.Serialization;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Threading;
using System.Xml;
using NUnit.Framework;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;
namespace MonoTests.System.ServiceModel.Description
{
[TestFixture]
public class JsonQueryStringConverterTest
{
JsonQueryStringConverter c;
[SetUp]
public void Setup ()
{
c = new JsonQueryStringConverter ();
}
[Test]
public void CanConvert ()
{
Assert.IsTrue (c.CanConvert (typeof (bool)), "#1");
Assert.IsTrue (c.CanConvert (typeof (char)), "#2");
Assert.IsTrue (c.CanConvert (typeof (double)), "#3");
Assert.IsTrue (c.CanConvert (typeof (decimal)), "#4");
Assert.IsTrue (c.CanConvert (typeof (float)), "#5");
Assert.IsTrue (c.CanConvert (typeof (string)), "#6");
Assert.IsTrue (c.CanConvert (typeof (int)), "#7");
Assert.IsTrue (c.CanConvert (typeof (byte)), "#8");
Assert.IsTrue (c.CanConvert (typeof (sbyte)), "#9");
Assert.IsTrue (c.CanConvert (typeof (long)), "#10");
Assert.IsTrue (c.CanConvert (typeof (ulong)), "#11");
Assert.IsTrue (c.CanConvert (typeof (DateTime)), "#12");
Assert.IsTrue (c.CanConvert (typeof (DateTimeOffset)), "#13");
Assert.IsTrue (c.CanConvert (typeof (TimeSpan)), "#14");
Assert.IsTrue (c.CanConvert (typeof (Guid)), "#15");
Assert.IsTrue (c.CanConvert (typeof (XmlQualifiedName)), "#16");
Assert.IsTrue (c.CanConvert (typeof (object)), "#17");
Assert.IsTrue (c.CanConvert (typeof (QueryStringConverter)), "#18");
// TypeConverterAttribute does not help it.
Assert.IsFalse (c.CanConvert (typeof (MyConvertible)), "#19");
Assert.IsTrue (c.CanConvert (typeof (MyPublicClass)), "#20");
Assert.IsTrue (c.CanConvert (typeof (MyNestedPublicClass)), "#21");
Assert.IsTrue (c.CanConvert (typeof (MyNestedPrivateClass)), "#22");
Assert.IsTrue (c.CanConvert (typeof (List<int>)), "#23");
Assert.IsTrue (c.CanConvert (typeof (List<MyPublicClass>)), "#24");
// FIXME: enable it
//Assert.IsFalse (c.CanConvert (typeof (List<MyInternalClass>)), "#25");
}
// ConvertValueToString
[Test]
public void ConvertValueToStringValidCast ()
{
Assert.AreEqual ("\"ABC\"", c.ConvertValueToString ("ABC", typeof (char)));
}
[Test]
[Ignore ("huh? .NET converts to 123, not \"123\"")]
public void ConvertValueToStringValidCast2 ()
{
Assert.AreEqual ("\"123\"", c.ConvertValueToString (123, typeof (string)));
}
[Test]
[Ignore ("huh? .NET converts to \"123\", not 123")]
public void ConvertValueToStringValidCast3 ()
{
Assert.AreEqual ("123", c.ConvertValueToString ("123", typeof (int)));
}
[Test]
public void ConvertValueToStringValidCast4 ()
{
Assert.AreEqual ("123.45", c.ConvertValueToString (123.45, typeof (int)));
}
[Test]
public void ConvertValueToStringValidCast4_ptBR ()
{
var ci = CultureInfo.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = new CultureInfo ("pt-BR");
Assert.AreEqual ("123.45", c.ConvertValueToString (123.45, typeof (int)));
}
finally {
Thread.CurrentThread.CurrentCulture = ci;
}
}
[Test]
public void ConvertValueToStringValidCast5 ()
{
Assert.AreEqual ("123", c.ConvertValueToString (123, typeof (double)));
}
[Test]
public void ConvertValueToStringValidCast6 ()
{
// umm... should be out of range
Assert.AreEqual ("12345", c.ConvertValueToString (12345, typeof (byte)));
}
[Test]
public void ConvertValueToStringNullToValueType ()
{
Assert.AreEqual (null, c.ConvertValueToString (null, typeof (char)));
}
[Test]
public void ConvertValueToStringDbNull ()
{
Assert.AreEqual ("{}", c.ConvertValueToString (DBNull.Value, typeof (DBNull)));
}
[Test]
public void ConvertValueToStringDbNull2 ()
{
Assert.AreEqual ("\"\"", c.ConvertValueToString ("", typeof (DBNull)));
}
[Test]
public void ConvertValueToStringDbNull3 ()
{
Assert.AreEqual (null, c.ConvertValueToString (null, typeof (DBNull)));
}
[Test]
public void ConvertValueToStringDbNull4 ()
{
// ... so, DBNull is just converted to String
Assert.AreEqual ("\"ABC\"", c.ConvertValueToString ("ABC", typeof (DBNull)));
}
[Test]
public void ConvertValueToStringQName ()
{
Assert.AreEqual ("\"foo:\"", c.ConvertValueToString (new XmlQualifiedName ("foo"), typeof (XmlQualifiedName)), "#1");
Assert.AreEqual ("\"foo:urn:bar\"", c.ConvertValueToString (new XmlQualifiedName ("foo", "urn:bar"), typeof (XmlQualifiedName)), "#2");
}
[Test]
public void ConvertValueToStringNullToString ()
{
Assert.IsNull (c.ConvertValueToString (null, typeof (string)));
}
[Test]
public void ConvertValueToString ()
{
Assert.AreEqual ("\"A\"", c.ConvertValueToString ('A', typeof (char)), "#1");
Assert.AreEqual ("\"}}}\"", c.ConvertValueToString ("}}}", typeof (string)), "#2");
Assert.AreEqual ("123", c.ConvertValueToString (123.0, typeof (double)), "#3");
}
// ConvertStringToValue
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertStringToValueInvalidCast ()
{
c.ConvertStringToValue ("ABC", typeof (char));
}
[Test]
[ExpectedException (typeof (FormatException))]
[Category ("NotWorking")]
public void ConvertStringToValueInvalidCast2 ()
{
c.ConvertStringToValue ("-123", typeof (uint));
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertStringToValueInvalidCast4 ()
{
c.ConvertStringToValue ("123.45", typeof (int));
}
[Test]
public void ConvertStringToValueString1 ()
{
// hmm ...
Assert.AreEqual ("-123.45", c.ConvertStringToValue ("-123.45", typeof (string)));
}
[Test]
public void ConvertStringToValueString2 ()
{
Assert.AreEqual ("ABC", c.ConvertStringToValue ("\"ABC\"", typeof (string)));
}
[Test]
[ExpectedException (typeof (SerializationException))]
public void ConvertStringToValueString3 ()
{
// missing closing '"'
Assert.AreEqual ("\"ABC", c.ConvertStringToValue ("\"ABC", typeof (string)));
// this test exposes that .NET uses DataContractJsonSerializer internally.
}
[Test]
public void ConvertStringToValueNullToValueType ()
{
// hmm, it passes.
Assert.AreEqual (default (char), c.ConvertStringToValue (null, typeof (char)));
}
[Test]
public void ConvertStringToValueDbNull ()
{
Assert.AreEqual (null, c.ConvertStringToValue (null, typeof (DBNull)));
}
[Test]
[ExpectedException (typeof (SerializationException))]
public void ConvertStringToValueDbNull2 ()
{
c.ConvertStringToValue ("", typeof (DBNull));
}
[Test]
[ExpectedException (typeof (SerializationException))]
public void ConvertStringToValueDbNull3 ()
{
c.ConvertStringToValue ("ABC", typeof (DBNull));
}
[Test]
public void ConvertStringToValueDbNull4 ()
{
Assert.AreEqual (DBNull.Value, c.ConvertStringToValue ("{}", typeof (DBNull)));
}
[Test]
public void ConvertStringToValueNullToString ()
{
Assert.IsNull (c.ConvertStringToValue (null, typeof (string)));
}
[Test]
public void ConvertStringToValue ()
{
Assert.AreEqual ('A', c.ConvertStringToValue ("A", typeof (char)), "#1");
// likely .NET bug: it should fail to deserialize as it is not a valid JSON string.
//Assert.AreEqual ("}}}", c.ConvertStringToValue ("}}}", typeof (string)), "#2");
Assert.AreEqual (123.0, c.ConvertStringToValue ("123.0", typeof (double)), "#3");
Assert.AreEqual (123.0, c.ConvertStringToValue ("123", typeof (double)), "#4");
Assert.AreEqual ("A", c.ConvertStringToValue ("\"A\"", typeof (string)), "#5");
// LAMESPEC: it should either always expect or preserve double-quotes. This behavior is just inconsistent.
Assert.AreEqual ("A", c.ConvertStringToValue ("A", typeof (string)), "#6");
Assert.AreEqual ("A%22B", c.ConvertStringToValue ("A%22B", typeof (string)), "#7"); // it's not either covered by url escaping.
}
// Types
public class MyNestedPublicClass
{
}
public class MyNestedPrivateClass
{
}
}
// non-nested types
public class MyPublicClass
{
}
class MyInternalClass
{
}
[TypeConverter (typeof (MyTypeConverter))]
class MyConvertible
{
}
class MyTypeConverter : TypeConverter
{
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof (string))
return "hogehoge";
throw new Exception ();
}
}
}

View File

@@ -0,0 +1,235 @@
//
// QueryStringConverterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// 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.ComponentModel;
using System.Globalization;
using System.ServiceModel.Dispatcher;
using System.Text;
using System.Xml;
using NUnit.Framework;
using CategoryAttribute = NUnit.Framework.CategoryAttribute;
namespace MonoTests.System.ServiceModel.Description
{
[TestFixture]
public class QueryStringConverterTest
{
QueryStringConverter c;
[SetUp]
public void Setup ()
{
c = new QueryStringConverter ();
}
[Test]
public void CanConvert ()
{
Assert.IsTrue (c.CanConvert (typeof (bool)), "#1");
Assert.IsTrue (c.CanConvert (typeof (char)), "#2");
Assert.IsTrue (c.CanConvert (typeof (double)), "#3");
Assert.IsTrue (c.CanConvert (typeof (decimal)), "#4");
Assert.IsTrue (c.CanConvert (typeof (float)), "#5");
Assert.IsTrue (c.CanConvert (typeof (string)), "#6");
Assert.IsTrue (c.CanConvert (typeof (int)), "#7");
Assert.IsTrue (c.CanConvert (typeof (byte)), "#8");
Assert.IsTrue (c.CanConvert (typeof (sbyte)), "#9");
Assert.IsTrue (c.CanConvert (typeof (long)), "#10");
Assert.IsTrue (c.CanConvert (typeof (ulong)), "#11");
Assert.IsTrue (c.CanConvert (typeof (DateTime)), "#12");
Assert.IsTrue (c.CanConvert (typeof (DateTimeOffset)), "#13");
Assert.IsTrue (c.CanConvert (typeof (TimeSpan)), "#14");
Assert.IsTrue (c.CanConvert (typeof (Guid)), "#15");
Assert.IsFalse (c.CanConvert (typeof (XmlQualifiedName)), "#16");
Assert.IsTrue (c.CanConvert (typeof (object)), "#17");
Assert.IsFalse (c.CanConvert (typeof (QueryStringConverter)), "#18");
// TypeConverterAttribute does not help it.
Assert.IsFalse (c.CanConvert (typeof (MyConvertible)), "#19");
Assert.IsTrue (c.CanConvert (typeof (DemoEnum)), "#20");
}
// ConvertStringToValue
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertValueToStringInvalidCast ()
{
c.ConvertValueToString ("ABC", typeof (char));
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertValueToStringInvalidCast2 ()
{
c.ConvertValueToString (123, typeof (string));
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertValueToStringInvalidCast3 ()
{
c.ConvertValueToString ("123", typeof (int));
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertValueToStringInvalidCast4 ()
{
c.ConvertValueToString (123.45, typeof (int));
}
[Test]
[ExpectedException (typeof (InvalidCastException))]
public void ConvertValueToStringInvalidCast5 ()
{
// umm...
c.ConvertValueToString (123, typeof (double));
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConvertValueToStringNullToValueType ()
{
c.ConvertValueToString (null, typeof (char));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertValueToStringDbNull ()
{
c.ConvertValueToString (DBNull.Value, typeof (DBNull));
}
[Test]
public void ConvertValueToStringNullToString ()
{
Assert.IsNull (c.ConvertValueToString (null, typeof (string)));
}
[Test]
public void ConvertValueToString ()
{
Assert.AreEqual ("A", c.ConvertValueToString ('A', typeof (char)), "#1");
Assert.AreEqual ("}}}", c.ConvertValueToString ("}}}", typeof (string)), "#2");
Assert.AreEqual ("123", c.ConvertValueToString (123.0, typeof (double)), "#3");
}
[Test]
public void ConvertValueToStringEnum ()
{
string stringValue = c.ConvertValueToString (DemoEnum.Value2, typeof (DemoEnum));
Assert.AreEqual ("Value2", stringValue);
}
// ConvertStringToValue
[Test]
public void ConvertStringToValueEnum ()
{
Assert.AreEqual (DemoEnum.Value3, (DemoEnum)c.ConvertStringToValue ("Value3", typeof(DemoEnum)));
Assert.AreEqual (DemoEnum.Value2, (DemoEnum)c.ConvertStringToValue ("value2", typeof(DemoEnum)));
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertStringToValueInvalidCast ()
{
c.ConvertStringToValue ("ABC", typeof (char));
}
[Test]
[ExpectedException (typeof (FormatException))]
[Category ("NotWorking")]
public void ConvertStringToValueInvalidCast2 ()
{
c.ConvertStringToValue ("-123", typeof (uint));
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ConvertStringToValueInvalidCast4 ()
{
c.ConvertStringToValue ("123.45", typeof (int));
}
[Test]
public void ConvertStringToValueNullToValueType ()
{
// hmm, it passes.
Assert.AreEqual (default (char), c.ConvertStringToValue (null, typeof (char)));
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ConvertStringToValueDbNull ()
{
c.ConvertStringToValue (null, typeof (DBNull));
}
[Test]
public void ConvertStringToValueNullToString ()
{
Assert.IsNull (c.ConvertStringToValue (null, typeof (string)));
}
[Test]
public void ConvertStringToValue ()
{
Assert.AreEqual ('A', c.ConvertStringToValue ("A", typeof (char)), "#1");
Assert.AreEqual ("}}}", c.ConvertStringToValue ("}}}", typeof (string)), "#2");
Assert.AreEqual (123.0, c.ConvertStringToValue ("123.0", typeof (double)), "#3");
Assert.AreEqual (123.0, c.ConvertStringToValue ("123", typeof (double)), "#4");
}
// Types
public enum DemoEnum
{
Value1,
Value2,
Value3,
Value4,
}
[TypeConverter (typeof (MyTypeConverter))]
class MyConvertible
{
}
class MyTypeConverter : TypeConverter
{
public override object ConvertTo (ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof (string))
return "hogehoge";
throw new Exception ();
}
}
}
}

View File

@@ -0,0 +1,280 @@
//
// WebHttpDispatchOperationSelectorTest.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.
//
#if !MOBILE
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);
}
#region SelectOperation
[Test]
public void SelectOperation ()
{
SelectOperationCore (Create ());
}
[Test]
public void SelectOperation2 ()
{
SelectOperationCore (Create2 ());
}
[Test]
public void SelectOperation3 ()
{
ContractDescription cd = ContractDescription.GetContract (typeof (MyService2));
Assert.IsNotNull (cd.Operations [0].Behaviors.Find<WebGetAttribute> (), "#1");
cd = ContractDescription.GetContract (typeof (MyService));
Assert.IsNull (cd.Operations [0].Behaviors.Find<WebGetAttribute> (), "#2");
}
void SelectOperationCore (MySelector d)
{
string name;
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 SelectOperationOnlyMessage ()
{
// 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))]
public void SelectOperationCheckExistingProperty ()
{
var d = Create ();
var msg = Message.CreateMessage (MessageVersion.None, "http://temuri.org/MyService/Echo"); // heh, I mistyped it and turned to prove that Action does not matter.
msg.Headers.To = new Uri ("http://localhost:8080/Echo");
// LAMESPEC: .NET does returns String.Empty, while we return the name of the operation (as IOperationSelector.SelectOperation is expected to do!)
// Assert.AreEqual (String.Empty, d.SelectOperation (ref msg), "#1");
d.SelectOperation (ref msg);
// The second invocation should raise the expected exception
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")]
[WebGet] // UriTemplate = "Echo?input={input}"
string Echo (string input);
}
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);
}
MySelector Create2 ()
{
ServiceEndpoint se = new ServiceEndpoint (ContractDescription.GetContract (typeof (MyService2)));
se.Address = new EndpointAddress ("http://localhost:8080");
//se.Contract.Operations [0].Behaviors.Add (new WebGetAttribute ());
return new MySelector (se);
}
#endregion
#region "bug #656020"
[DataContract]
public class User
{
[DataMember]
public string Name { get; set; }
}
[ServiceContract]
interface IHello
{
[WebGet(UriTemplate = "{name}?age={age}&blah={blah}")]
[OperationContract]
string SayHi (string name, int age, string blah);
[WebInvoke(UriTemplate = "blah")]
[OperationContract]
string SayHi2 (User user);
}
class Hello : IHello
{
public string SayHi (string name, int age, string blah)
{
return string.Format ("Hi {0}: {1}, {2}", name, age, blah == null);
}
public string SayHi2 (User user)
{
return string.Format ("Hi {0}.", user.Name);
}
}
[Test]
public void WebMessageFormats ()
{
var host = new WebServiceHost (typeof (Hello));
host.AddServiceEndpoint (typeof (IHello), new WebHttpBinding (), "http://localhost:37564/");
host.Description.Behaviors.Find<ServiceDebugBehavior> ().IncludeExceptionDetailInFaults = true;
host.Open ();
try {
// run client
using (ChannelFactory<IHello> factory = new ChannelFactory<IHello> (new WebHttpBinding (), "http://localhost:37564/"))
{
factory.Endpoint.Behaviors.Add (new WebHttpBehavior ());
IHello h = factory.CreateChannel ();
//Console.WriteLine(h.SayHi("Joe", 42, null));
Assert.AreEqual ("Hi Joe.", h.SayHi2 (new User { Name = "Joe" }), "#1");
}
} finally {
host.Close ();
}
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,389 @@
//
// Atom10FeedFormatterTest.cs
//
// Author:
// Atsushi Enomoto <atsushi@ximian.com>
//
// Copyright (C) 2007 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.
//
#if !MOBILE
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Serialization;
using System.ServiceModel.Syndication;
using NUnit.Framework;
using QName = System.Xml.XmlQualifiedName;
namespace MonoTests.System.ServiceModel.Syndication
{
[TestFixture]
public class Atom10FeedFormatterTest
{
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullFeed ()
{
new Atom10FeedFormatter ((SyndicationFeed) null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorNullType ()
{
new Atom10FeedFormatter ((Type) null);
}
/*
[Test]
public void FeedType ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
Assert.IsNull (f.FeedType, "#1");
f = new Atom10FeedFormatter (new SyndicationFeed ());
Assert.IsNull (f.FeedType, "#2");
}
*/
[Test]
public void Version ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
Assert.AreEqual ("Atom10", f.Version, "#1");
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void DefaultConstructorThenWriteXml ()
{
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter ().WriteTo (w);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void WriteToNull ()
{
SyndicationFeed feed = new SyndicationFeed ();
new Atom10FeedFormatter (feed).WriteTo (null);
}
string DummyId (string s)
{
return Regex.Replace (s, "<id>.+</id>", "<id>XXX</id>");
}
string DummyId2 (string s)
{
return Regex.Replace (s, "<id xmlns=\"http://www.w3.org/2005/Atom\">.+</id>", "<id>XXX</id>");
}
string DummyUpdated (string s)
{
return Regex.Replace (s, "<updated>.+</updated>", "<updated>XXX</updated>");
}
string DummyUpdated2 (string s)
{
return Regex.Replace (s, "<updated xmlns=\"http://www.w3.org/2005/Atom\">.+</updated>", "<updated>XXX</updated>");
}
[Test]
public void WriteTo_EmptyFeed ()
{
// It however automatically fills id (very likely bug in .NET) and DateTimeOffset though.
SyndicationFeed feed = new SyndicationFeed ();
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
Assert.IsNull (feed.Id, "#1"); // automatically generated, but not automatically set.
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
Assert.AreEqual ("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\"></title><id>XXX</id><updated>XXX</updated></feed>", DummyUpdated (DummyId (sw.ToString ())));
}
[Test]
public void WriteTo_TitleOnlyFeed ()
{
// It however automatically fills id (very likely bug in .NET) and DateTimeOffset though.
SyndicationFeed feed = new SyndicationFeed ();
feed.Title = new TextSyndicationContent ("title text");
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
Assert.AreEqual ("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\">title text</title><id>XXX</id><updated>XXX</updated></feed>", DummyUpdated (DummyId (sw.ToString ())));
}
[Test]
public void WriteTo_CategoryAuthorsContributors ()
{
// It however automatically fills ...
SyndicationFeed feed = new SyndicationFeed ();
feed.Categories.Add (new SyndicationCategory ("myname", "myscheme", "mylabel"));
feed.Authors.Add (new SyndicationPerson ("john@doe.com", "John Doe", "http://john.doe.name"));
feed.Contributors.Add (new SyndicationPerson ("jane@doe.com", "Jane Doe", "http://jane.doe.name"));
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
// contributors are serialized as Atom extension
Assert.AreEqual ("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\"></title><id>XXX</id><updated>XXX</updated><category term=\"myname\" label=\"mylabel\" scheme=\"myscheme\" /><author><name>John Doe</name><uri>http://john.doe.name</uri><email>john@doe.com</email></author><contributor><name>Jane Doe</name><uri>http://jane.doe.name</uri><email>jane@doe.com</email></contributor></feed>", DummyUpdated (DummyId (sw.ToString ())));
}
[Test]
public void WriteTo ()
{
SyndicationFeed feed = new SyndicationFeed ();
feed.BaseUri = new Uri ("http://mono-project.com");
feed.Copyright = new TextSyndicationContent ("No rights reserved");
feed.Description = new TextSyndicationContent ("A sample feed for unit testing");
feed.Generator = "mono test generator";
// .NET bug: it ignores this value.
feed.Id = "urn:myid";
feed.ImageUrl = new Uri ("http://mono-project.com/images/mono.png");
feed.LastUpdatedTime = new DateTimeOffset (DateTime.SpecifyKind (new DateTime (2008, 1, 1), DateTimeKind.Utc));
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
Assert.AreEqual ("<feed xml:base=\"http://mono-project.com/\" xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\"></title><id>XXX</id><rights type=\"text\">No rights reserved</rights><updated>2008-01-01T00:00:00Z</updated><subtitle type=\"text\">A sample feed for unit testing</subtitle><logo>http://mono-project.com/images/mono.png</logo><generator>mono test generator</generator></feed>", DummyId (sw.ToString ()));
}
[Test]
public void ISerializableWriteXml ()
{
SyndicationFeed feed = new SyndicationFeed ();
feed.Title = new TextSyndicationContent ("title text");
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw)) {
w.WriteStartElement ("dummy");
((IXmlSerializable) new Atom10FeedFormatter (feed)).WriteXml (w);
w.WriteEndElement ();
}
Assert.AreEqual ("<dummy><title type=\"text\" xmlns=\"http://www.w3.org/2005/Atom\">title text</title><id>XXX</id><updated>XXX</updated></dummy>", DummyUpdated2 (DummyId2 (sw.ToString ())));
}
[Test]
public void WriteTo_IllegalDuplicateAltLinks ()
{
// ... and it passes.
SyndicationFeed feed = new SyndicationFeed ();
feed.Links.Add (new SyndicationLink (new Uri ("http://mono-project.com/Page1"), "alternate", "Page 1", "text/html", 0));
feed.Links.Add (new SyndicationLink (new Uri ("http://mono-project.com/Page2"), "alternate", "Page 2", "text/html", 0));
StringWriter sw = new StringWriter ();
using (XmlWriter w = CreateWriter (sw))
new Atom10FeedFormatter (feed).WriteTo (w);
Assert.AreEqual ("<feed xmlns=\"http://www.w3.org/2005/Atom\"><title type=\"text\"></title><id>XXX</id><updated>XXX</updated><link rel=\"alternate\" type=\"text/html\" title=\"Page 1\" href=\"http://mono-project.com/Page1\" /><link rel=\"alternate\" type=\"text/html\" title=\"Page 2\" href=\"http://mono-project.com/Page2\" /></feed>", DummyUpdated (DummyId (sw.ToString ())));
}
XmlWriter CreateWriter (StringWriter sw)
{
XmlWriterSettings s = new XmlWriterSettings ();
s.OmitXmlDeclaration = true;
return XmlWriter.Create (sw, s);
}
XmlReader CreateReader (string xml)
{
return XmlReader.Create (new StringReader (xml));
}
[Test]
public void CanRead ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
Assert.IsTrue (f.CanRead (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'>")), "#1");
Assert.IsFalse (f.CanRead (CreateReader ("<item xmlns='http://www.w3.org/2005/Atom'>")), "#2");
Assert.IsFalse (f.CanRead (CreateReader ("<feed xmlns='urn:foo'>")), "#3");
Assert.IsFalse (f.CanRead (CreateReader ("<feed>")), "#4");
Assert.IsFalse (f.CanRead (CreateReader ("<hoge>")), "#5");
XmlReader r = CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'></feed>");
r.Read (); // element
r.Read (); // endelement
Assert.IsFalse (f.CanRead (r), "#6");
r = CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><title>test</title></feed>");
r.Read (); // feed
r.Read (); // channel
Assert.IsFalse (f.CanRead (r), "#7");
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadFromInvalid ()
{
new Atom10FeedFormatter ().ReadFrom (CreateReader ("<feed>"));
}
[Test]
public void ReadFrom1 ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
Assert.IsNull (f.Feed, "#1");
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><title>test</title></feed>"));
SyndicationFeed feed1 = f.Feed;
Assert.IsNotNull (f.Feed.Title, "#2");
Assert.AreEqual ("test", f.Feed.Title.Text, "#3");
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><title>test</title></feed>"));
Assert.IsFalse (object.ReferenceEquals (feed1, f.Feed), "#4");
}
[Test]
public void ReadXml_TitleOnly ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
((IXmlSerializable) f).ReadXml (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><title>test</title></feed>"));
Assert.IsNotNull (f.Feed.Title, "#1");
Assert.AreEqual ("test", f.Feed.Title.Text, "#2");
((IXmlSerializable) f).ReadXml (CreateReader ("<dummy xmlns='http://www.w3.org/2005/Atom'><title>test</title></dummy>")); // it is ok
}
[Test]
[ExpectedException (typeof (XmlException))]
public void ReadXmlFromContent ()
{
((IXmlSerializable) new Atom10FeedFormatter ()).ReadXml (CreateReader ("<title xmlns='http://www.w3.org/2005/Atom'>test</title>"));
}
[Test]
public void ReadXml_Extension ()
{
new Atom10FeedFormatter<MySyndicationFeed1> ().ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><foo>test</foo></feed>"));
new Atom10FeedFormatter<MySyndicationFeed2> ().ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><foo>test</foo></feed>"));
try {
new Atom10FeedFormatter<MySyndicationFeed3> ().ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><foo>test</foo></feed>"));
Assert.Fail ("should trigger TryParseElement");
} catch (ApplicationException) {
}
}
class MySyndicationFeed1 : SyndicationFeed
{
protected override bool TryParseElement (XmlReader reader, string version)
{
Assert.AreEqual ("Atom10", version, "#1");
Assert.IsFalse (base.TryParseElement (reader, version), "#2");
return false;
}
}
class MySyndicationFeed2 : SyndicationFeed
{
protected override bool TryParseElement (XmlReader reader, string version)
{
reader.Skip (); // without it, the caller expects that the reader did not proceed.
return true;
}
}
class MySyndicationFeed3 : SyndicationFeed
{
protected override bool TryParseElement (XmlReader reader, string version)
{
throw new ApplicationException ();
}
}
[Test]
[ExpectedException (typeof (XmlException))]
[Category("NotWorking")]
public void ReadFrom_EmptyDate ()
{
// strangely, it is checked while 'entry' is not checked
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><updated /></feed>"));
}
[Test]
[ExpectedException (typeof (XmlException))]
[Category("NotWorking")]
public void ReadFrom_WrongDate ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><updated>2000-01-01T00:00:00</updated></feed>"));
}
[Test]
public void ReadFrom_Extension ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><icon>http://www.mono-project.com/icons/mono.png</icon></feed>"));
Assert.IsNotNull (f.Feed, "#1");
// 'icon' is treated as an extension ...
Assert.AreEqual (1, f.Feed.ElementExtensions.Count, "#2");
}
[Test]
public void ReadFrom_Link ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><link href='urn:foo' rel='enclosure' length='50' type='text/html' wcf='wtf'><extended /></link></feed>"));
Assert.AreEqual (1, f.Feed.Links.Count, "#1");
SyndicationLink link = f.Feed.Links [0];
Assert.AreEqual (50, link.Length, "#2");
Assert.AreEqual ("urn:foo", link.Uri.ToString (), "#3");
Assert.AreEqual ("text/html", link.MediaType, "#4");
Assert.AreEqual ("enclosure", link.RelationshipType, "#5");
Assert.AreEqual (1, link.AttributeExtensions.Count, "#6");
Assert.AreEqual (1, link.ElementExtensions.Count, "#7");
}
[Test]
public void ReadFrom_ImageUrl ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom'><logo>http://mono-project.com/images/mono.png</logo></feed>"));
Assert.IsNotNull (f.Feed.ImageUrl, "#1");
Assert.AreEqual ("http://mono-project.com/images/mono.png", f.Feed.ImageUrl.ToString (), "#2");
}
[Test]
public void ReadFrom_Language ()
{
Atom10FeedFormatter f = new Atom10FeedFormatter ();
f.ReadFrom (CreateReader ("<feed xmlns='http://www.w3.org/2005/Atom' xml:lang='ar-AR'></feed>"));
Assert.AreEqual ("ar-AR", f.Feed.Language, "#1");
}
[Test]
public void GetSchema ()
{
Assert.IsNull (((IXmlSerializable) new Atom10FeedFormatter ()).GetSchema ());
}
[Test]
public void TestToString ()
{
Assert.AreEqual (typeof (Atom10FeedFormatter).FullName + ", SyndicationVersion=Atom10", new Atom10FeedFormatter (new SyndicationFeed ()).ToString ());
}
}
}
#endif

Some files were not shown because too many files have changed in this diff Show More