[TestFixture]
public class HttpListenerTest {
- int port;
-
- [SetUp]
- public void SetUp () {
- port = NetworkHelpers.FindFreePort ();
+ int? _port;
+ int port {
+ get { return _port ?? (_port = NetworkHelpers.FindFreePort ()).Value; }
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void DefaultProperties ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Start1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void Stop1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (InvalidOperationException))]
+#endif
public void GetContext1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (InvalidOperationException))]
+#endif
public void GetContext2 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (InvalidOperationException))]
+#endif
public void BeginGetContext1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void BeginGetContext2 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void DefaultHttpPort ()
{
if (!CanOpenPort (80))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void DefaultHttpsPort ()
{
if (!CanOpenPort (443))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void TwoListeners_SameAddress ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (HttpListenerException))]
+#endif
public void TwoListeners_SameURL ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (HttpListenerException))]
+#endif
public void MultipleSlashes ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (HttpListenerException))]
+#endif
public void PercentSign ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CloseBeforeStart ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CloseTwice ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void StartStopStart ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void StartStopDispose ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void AbortBeforeStart ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void AbortTwice ()
{
if (!CanOpenPort (port))
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void PropertiesWhenClosed1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosed2 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosedSet1 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosedSet2 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosedSet3 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosedSet4 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (ObjectDisposedException))]
+#endif
public void PropertiesWhenClosedSet5 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void PropertiesWhenClosed3 ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void CloseWhileBegin ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void AbortWhileBegin ()
{
HttpListener listener = new HttpListener ();
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (HttpListenerException))]
+#endif
public void CloseWhileGet ()
{
// "System.Net.HttpListener Exception : The I/O operation has been aborted
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#else
[ExpectedException (typeof (HttpListenerException))]
+#endif
public void AbortWhileGet ()
{
// "System.Net.HttpListener Exception : The I/O operation has been aborted
}
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void ConnectionReuse ()
{
var uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
return clientEndPoint;
}
+
+ [Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
+ public void UserHeaderWithDoubleMultiValue ()
+ {
+ string uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";
+
+ var l = new HttpListener ();
+ l.Prefixes.Add (uri);
+ l.Start ();
+ l.BeginGetContext (ar => {
+ var ctx = l.EndGetContext (ar);
+
+ var response = ctx.Response;
+ response.Headers.Add ("X-Custom-Header", "A");
+ response.Headers.Add ("X-Custom-Header", "B");
+
+ response.Close ();
+ }, null);
+
+ HttpWebRequest wr = HttpWebRequest.CreateHttp (uri);
+ var resp = wr.GetResponse ();
+ var vls = resp.Headers.GetValues ("X-Custom-Header");
+
+ Assert.AreEqual (2, vls.Length);
+
+ l.Close ();
+ }
[Test]
+#if FEATURE_NO_BSD_SOCKETS
+ [ExpectedException (typeof (PlatformNotSupportedException))]
+#endif
public void HttpClientIsDisconnectedCheckForWriteException()
{
string uri = "http://localhost:" + NetworkHelpers.FindFreePort () + "/";