Files
mono/mcs/class/System.ServiceModel.Web/Test/System.ServiceModel.Activation/WebScriptServiceHostFactoryTest.cs
T
Alexander Köplinger 77cf4cc4f8 [tests] Remove MONOMAC ifdef from BCL tests (#13694)
It was set by xamarin-macios when they were still taking the raw .cs source files
but since we switched to prebuilt binaries we need to replace it with
some define we're actually setting in Mono.

Most cases can be replaced by just XAMMAC_4_5 since MOBILE is defined on the xammac profile.
2019-03-27 20:21:48 +01:00

98 lines
2.2 KiB
C#

#if !MOBILE && !XAMMAC_4_5
using System;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Channels;
using System.ServiceModel.Web;
using NUnit.Framework;
using MonoTests.Helpers;
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 port = NetworkHelpers.FindFreePort ();
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestService), new Uri [] {new Uri ($"http://localhost:{port}")});
Assert.IsFalse (host is WebServiceHost, "#1");
host.Open ();
host.Close ();
}
[Test]
[ExpectedException (typeof (NotSupportedException))]
public void ResponseWrappedIsInvalid ()
{
var port = NetworkHelpers.FindFreePort ();
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestService2), new Uri [] {new Uri ($"http://localhost:{port}")});
host.Open (); // should raise an error here.
}
[Test]
[ExpectedException (typeof (InvalidOperationException))]
public void MultipleContract ()
{
var port = NetworkHelpers.FindFreePort ();
var f = new MyHostFactory ();
var host = f.DoCreateServiceHost (typeof (TestServiceMultiple), new Uri [] {new Uri ($"http://localhost:{port}")});
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