diff options
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r-- | src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj | 4 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs | 87 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/HostingTests.cs | 46 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/HttpHost.cs | 111 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs | 123 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs | 19 |
6 files changed, 0 insertions, 390 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index ab90935..1ab1d20 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -106,10 +106,6 @@ <ItemGroup> <Compile Include="AutoRedirectHandler.cs" /> <Compile Include="Configuration\SectionTests.cs" /> - <Compile Include="Hosting\AspNetHost.cs" /> - <Compile Include="Hosting\HostingTests.cs" /> - <Compile Include="Hosting\HttpHost.cs" /> - <Compile Include="Hosting\TestingWorkerRequest.cs" /> <Compile Include="LocalizationTests.cs" /> <Compile Include="Messaging\CollectionAssert.cs" /> <Compile Include="Messaging\EnumerableCacheTests.cs" /> diff --git a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs deleted file mode 100644 index 5c9ed41..0000000 --- a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs +++ /dev/null @@ -1,87 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="AspNetHost.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Hosting { - using System; - using System.IO; - using System.Net; - using System.Threading; - using System.Web; - using System.Web.Hosting; - using DotNetOpenAuth.Messaging; - using DotNetOpenAuth.Test.OpenId; - - /// <summary> - /// Hosts an ASP.NET web site for placing ASP.NET controls and services on - /// for more complete end-to-end testing. - /// </summary> - internal class AspNetHost : MarshalByRefObject, IDisposable { - private HttpHost httpHost; - - /// <summary> - /// Initializes a new instance of the <see cref="AspNetHost"/> class. - /// </summary> - /// <remarks> - /// DO NOT CALL DIRECTLY. This is only here for ASP.NET to call. - /// Call the static <see cref="AspNetHost.CreateHost"/> method instead. - /// </remarks> - [Obsolete("Use the CreateHost static method instead.")] - public AspNetHost() { - this.httpHost = HttpHost.CreateHost(this); - } - - public Uri BaseUri { - get { return this.httpHost.BaseUri; } - } - - public static AspNetHost CreateHost(string webDirectory) { - AspNetHost host = (AspNetHost)ApplicationHost.CreateApplicationHost(typeof(AspNetHost), "/", webDirectory); - return host; - } - - public string ProcessRequest(string url) { - return this.httpHost.ProcessRequest(url); - } - - public string ProcessRequest(string url, string body) { - return this.httpHost.ProcessRequest(url, body); - } - - public void BeginProcessRequest(HttpListenerContext context) { - ThreadPool.QueueUserWorkItem(state => { ProcessRequest(context); }); - } - - public void ProcessRequest(HttpListenerContext context) { - try { - using (TextWriter tw = new StreamWriter(context.Response.OutputStream)) { - HttpRuntime.ProcessRequest(new TestingWorkerRequest(context, tw)); - } - } catch (Exception ex) { - Logger.Http.Error("Exception in AspNetHost", ex); - throw; - } - } - - public void CloseHttp() { - this.httpHost.Dispose(); - } - - #region IDisposable Members - - public void Dispose() { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected void Dispose(bool disposing) { - if (disposing) { - this.CloseHttp(); - } - } - - #endregion - } -} diff --git a/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs b/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs deleted file mode 100644 index 0f3f6e9..0000000 --- a/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs +++ /dev/null @@ -1,46 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="HostingTests.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Hosting { - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Net; - using System.Text; - using DotNetOpenAuth.Test.OpenId; - using NUnit.Framework; - - [TestFixture, Category("HostASPNET")] - public class HostingTests : TestBase { - [Test] - public void AspHostBasicTest() { - try { - using (AspNetHost host = AspNetHost.CreateHost(TestWebDirectory)) { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(host.BaseUri); - using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { - Assert.AreEqual(HttpStatusCode.OK, response.StatusCode); - using (StreamReader sr = new StreamReader(response.GetResponseStream())) { - string content = sr.ReadToEnd(); - StringAssert.Contains("Test home page", content); - } - } - } - } catch (FileNotFoundException ex) { - Assert.Inconclusive( - "Unable to execute hosted ASP.NET tests because {0} could not be found. {1}", ex.FileName, ex.FusionLog); - } catch (WebException ex) { - if (ex.Response != null) { - using (var responseStream = new StreamReader(ex.Response.GetResponseStream())) { - Console.WriteLine(responseStream.ReadToEnd()); - } - } - - throw; - } - } - } -} diff --git a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs deleted file mode 100644 index ee3cb6c..0000000 --- a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs +++ /dev/null @@ -1,111 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="HttpHost.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Hosting { - using System; - using System.Globalization; - using System.IO; - using System.Net; - using System.Threading; - - internal class HttpHost : IDisposable { - private readonly HttpListener listener; - private Thread listenerThread; - private AspNetHost aspNetHost; - - private HttpHost(AspNetHost aspNetHost) { - this.aspNetHost = aspNetHost; - - this.Port = 59687; - Random r = new Random(); - tryAgain: - try { - this.listener = new HttpListener(); - this.listener.Prefixes.Add(string.Format(CultureInfo.InvariantCulture, "http://localhost:{0}/", this.Port)); - this.listener.Start(); - } catch (HttpListenerException ex) { - if (ex.Message.Contains("conflicts")) { - this.Port += r.Next(1, 20); - goto tryAgain; - } - throw; - } - this.listenerThread = new Thread(this.ProcessRequests); - this.listenerThread.Start(); - } - - public int Port { get; private set; } - - public Uri BaseUri { - get { return new Uri("http://localhost:" + this.Port.ToString() + "/"); } - } - - public static HttpHost CreateHost(AspNetHost aspNetHost) { - return new HttpHost(aspNetHost); - } - - public static HttpHost CreateHost(string webDirectory) { - return new HttpHost(AspNetHost.CreateHost(webDirectory)); - } - - public string ProcessRequest(string url) { - return this.ProcessRequest(url, null); - } - - public string ProcessRequest(string url, string body) { - WebRequest request = WebRequest.Create(new Uri(this.BaseUri, url)); - if (body != null) { - request.Method = "POST"; - request.ContentLength = body.Length; - using (StreamWriter sw = new StreamWriter(request.GetRequestStream())) { - sw.Write(body); - } - } - try { - using (WebResponse response = request.GetResponse()) { - using (StreamReader sr = new StreamReader(response.GetResponseStream())) { - return sr.ReadToEnd(); - } - } - } catch (WebException ex) { - Logger.Http.Error("Exception in HttpHost", ex); - using (StreamReader sr = new StreamReader(ex.Response.GetResponseStream())) { - string streamContent = sr.ReadToEnd(); - Logger.Http.ErrorFormat("Error content stream follows: {0}", streamContent); - } - throw; - } - } - - #region IDisposable Members - - public void Dispose() { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) { - if (disposing) { - this.listener.Close(); - this.listenerThread.Join(1000); - this.listenerThread.Abort(); - } - } - - #endregion - - private void ProcessRequests() { - try { - while (true) { - var context = this.listener.GetContext(); - this.aspNetHost.BeginProcessRequest(context); - } - } catch (HttpListenerException) { - // the listener is probably being shut down - } - } - } -} diff --git a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs deleted file mode 100644 index f6c54e6..0000000 --- a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs +++ /dev/null @@ -1,123 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="TestingWorkerRequest.cs" company="Outercurve Foundation"> -// Copyright (c) Outercurve Foundation. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOpenAuth.Test.Hosting { - using System; - using System.IO; - using System.Net; - using System.Web.Hosting; - - /// <summary> - /// Processes individual incoming ASP.NET requests. - /// </summary> - internal class TestingWorkerRequest : SimpleWorkerRequest { - private Stream entityStream; - - private HttpListenerContext context; - - private TextWriter writer; - - public TestingWorkerRequest(string page, string query, Stream entityStream, TextWriter writer) - : base(page, query, writer) { - this.entityStream = entityStream; - this.writer = writer; - } - - public TestingWorkerRequest(HttpListenerContext context, TextWriter output) - : base(context.Request.Url.LocalPath.TrimStart('/'), context.Request.Url.Query, output) { - this.entityStream = context.Request.InputStream; - this.context = context; - this.writer = output; - } - - public override string GetFilePath() { - string filePath = this.context.Request.Url.LocalPath.Replace("/", "\\"); - if (filePath.EndsWith("\\", StringComparison.Ordinal)) { - filePath += "default.aspx"; - } - return filePath; - } - - public override int GetLocalPort() { - return this.context.Request.Url.Port; - } - - public override string GetServerName() { - return this.context.Request.Url.Host; - } - - public override string GetQueryString() { - return this.context.Request.Url.Query.TrimStart('?'); - } - - public override string GetHttpVerbName() { - return this.context.Request.HttpMethod; - } - - public override string GetLocalAddress() { - return this.context.Request.LocalEndPoint.Address.ToString(); - } - - public override string GetHttpVersion() { - return "HTTP/1.1"; - } - - public override string GetProtocol() { - return this.context.Request.Url.Scheme; - } - - public override string GetRawUrl() { - return this.context.Request.RawUrl; - } - - public override int GetTotalEntityBodyLength() { - return (int)this.context.Request.ContentLength64; - } - - public override string GetKnownRequestHeader(int index) { - return this.context.Request.Headers[GetKnownRequestHeaderName(index)]; - } - - public override string GetUnknownRequestHeader(string name) { - return this.context.Request.Headers[name]; - } - - public override bool IsEntireEntityBodyIsPreloaded() { - return false; - } - - public override int ReadEntityBody(byte[] buffer, int size) { - return this.entityStream.Read(buffer, 0, size); - } - - public override int ReadEntityBody(byte[] buffer, int offset, int size) { - return this.entityStream.Read(buffer, offset, size); - } - - public override void SendCalculatedContentLength(int contentLength) { - this.context.Response.ContentLength64 = contentLength; - } - - public override void SendStatus(int statusCode, string statusDescription) { - if (this.context != null) { - this.context.Response.StatusCode = statusCode; - this.context.Response.StatusDescription = statusDescription; - } - } - - public override void SendKnownResponseHeader(int index, string value) { - if (this.context != null) { - this.context.Response.Headers[(HttpResponseHeader)index] = value; - } - } - - public override void SendUnknownResponseHeader(string name, string value) { - if (this.context != null) { - this.context.Response.Headers[name] = value; - } - } - } -} diff --git a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs index 4780e37..ae07d71 100644 --- a/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs +++ b/src/DotNetOpenAuth.Test/OpenId/Provider/OpenIdProviderTests.cs @@ -17,7 +17,6 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { using DotNetOpenAuth.OpenId.Messages; using DotNetOpenAuth.OpenId.Provider; using DotNetOpenAuth.OpenId.RelyingParty; - using DotNetOpenAuth.Test.Hosting; using NUnit.Framework; [TestFixture] @@ -123,23 +122,5 @@ namespace DotNetOpenAuth.Test.OpenId.Provider { Assert.IsNotNull(response.ErrorMessage); Assert.AreEqual(Protocol.Default.Version, response.Version); } - - [Test, Category("HostASPNET")] - public async Task BadRequestsGenerateValidErrorResponsesHosted() { - try { - using (AspNetHost host = AspNetHost.CreateHost(TestWebDirectory)) { - Uri opEndpoint = new Uri(host.BaseUri, "/OpenIdProviderEndpoint.ashx"); - var rp = new OpenIdRelyingParty(null); - var nonOpenIdMessage = new Mocks.TestDirectedMessage(); - nonOpenIdMessage.Recipient = opEndpoint; - nonOpenIdMessage.HttpMethods = HttpDeliveryMethods.PostRequest; - MessagingTestBase.GetStandardTestMessage(MessagingTestBase.FieldFill.AllRequired, nonOpenIdMessage); - var response = await rp.Channel.RequestAsync<DirectErrorResponse>(nonOpenIdMessage, CancellationToken.None); - Assert.IsNotNull(response.ErrorMessage); - } - } catch (FileNotFoundException ex) { - Assert.Inconclusive("Unable to execute hosted ASP.NET tests because {0} could not be found. {1}", ex.FileName, ex.FusionLog); - } - } } } |