diff options
Diffstat (limited to 'src/DotNetOpenAuth.Test')
-rw-r--r-- | src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj | 5 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs | 26 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/HostingTests.cs | 33 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/HttpHost.cs | 21 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs | 3 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/TestSupport.cs | 5 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs | 27 |
7 files changed, 80 insertions, 40 deletions
diff --git a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj index 19b3a70..bb2346c 100644 --- a/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj +++ b/src/DotNetOpenAuth.Test/DotNetOpenAuth.Test.csproj @@ -62,6 +62,7 @@ <Compile Include="Configuration\SectionTests.cs" /> <Compile Include="CoordinatorBase.cs" /> <Compile Include="Hosting\AspNetHost.cs" /> + <Compile Include="Hosting\HostingTests.cs" /> <Compile Include="Hosting\HttpHost.cs" /> <Compile Include="Hosting\TestingWorkerRequest.cs" /> <Compile Include="Messaging\CollectionAssert.cs" /> @@ -154,7 +155,6 @@ <Compile Include="OpenId\RelyingParty\RelyingPartySecuritySettingsTests.cs" /> <Compile Include="OpenId\RelyingParty\ServiceEndpointTests.cs" /> <Compile Include="OpenId\TestSupport.cs" /> - <Compile Include="OpenId\UI\UITestSupport.cs" /> <Compile Include="OpenId\UriIdentifierTests.cs" /> <Compile Include="OpenId\XriIdentifierTests.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> @@ -208,6 +208,9 @@ <ItemGroup> <None Include="App.config" /> </ItemGroup> + <ItemGroup> + <Folder Include="OpenId\UI\" /> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="..\..\tools\DotNetOpenAuth.Versioning.targets" /> </Project>
\ No newline at end of file diff --git a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs index 94bf480..a61c0cf 100644 --- a/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs +++ b/src/DotNetOpenAuth.Test/Hosting/AspNetHost.cs @@ -15,12 +15,17 @@ namespace DotNetOpenAuth.Test.Hosting { using DotNetOpenAuth.Test.OpenId; /// <summary> - /// Hosts a 'portable' version of the OpenIdProvider for testing itself and the - /// RelyingParty against it. + /// 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 { + internal class AspNetHost : MarshalByRefObject, IDisposable { private HttpHost httpHost; + /// <summary> + /// DO NOT CALL DIRECTLY. This is only here for ASP.NET to call. + /// Call the static <see cref="AspNetHost.CreateHost"/> method instead. + /// </summary> + [Obsolete("Use the CreateHost static method instead.")] public AspNetHost() { this.httpHost = HttpHost.CreateHost(this); ////if (!UntrustedWebRequestHandler.WhitelistHosts.Contains("localhost")) @@ -63,5 +68,20 @@ namespace DotNetOpenAuth.Test.Hosting { 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) { + CloseHttp(); + } + } + + #endregion } } diff --git a/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs b/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs new file mode 100644 index 0000000..a9146ee --- /dev/null +++ b/src/DotNetOpenAuth.Test/Hosting/HostingTests.cs @@ -0,0 +1,33 @@ +//----------------------------------------------------------------------- +// <copyright file="HostingTests.cs" company="Andrew Arnott"> +// Copyright (c) Andrew Arnott. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.Test.Hosting { + using System; + using System.Collections.Generic; + using System.Linq; + using System.Text; + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Net; + using System.IO; + using DotNetOpenAuth.Test.OpenId; + + [TestClass] + public class HostingTests { + [TestMethod] + public void AspHostBasicTest() { + using (AspNetHost host = AspNetHost.CreateHost(TestSupport.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(content, "Test home page"); + } + } + } + } + } +} diff --git a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs index 3ccd8bc..dee1ea3 100644 --- a/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs +++ b/src/DotNetOpenAuth.Test/Hosting/HttpHost.cs @@ -12,7 +12,7 @@ namespace DotNetOpenAuth.Test.Hosting { using System.Threading; internal class HttpHost : IDisposable { - private HttpListener listener; + private readonly HttpListener listener; private Thread listenerThread; private AspNetHost aspNetHost; @@ -60,13 +60,15 @@ namespace DotNetOpenAuth.Test.Hosting { if (body != null) { request.Method = "POST"; request.ContentLength = body.Length; - using (StreamWriter sw = new StreamWriter(request.GetRequestStream())) + using (StreamWriter sw = new StreamWriter(request.GetRequestStream())) { sw.Write(body); + } } try { using (WebResponse response = request.GetResponse()) { - using (StreamReader sr = new StreamReader(response.GetResponseStream())) + using (StreamReader sr = new StreamReader(response.GetResponseStream())) { return sr.ReadToEnd(); + } } } catch (WebException ex) { Logger.Error("Exception in HttpHost", ex); @@ -81,9 +83,16 @@ namespace DotNetOpenAuth.Test.Hosting { #region IDisposable Members public void Dispose() { - this.listener.Close(); - this.listenerThread.Join(1000); - this.listenerThread.Abort(); + 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 diff --git a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs index d059c36..acafc4e 100644 --- a/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs +++ b/src/DotNetOpenAuth.Test/Hosting/TestingWorkerRequest.cs @@ -10,6 +10,9 @@ namespace DotNetOpenAuth.Test.Hosting { using System.Net; using System.Web.Hosting; + /// <summary> + /// Processes individual incoming ASP.NET requests. + /// </summary> internal class TestingWorkerRequest : SimpleWorkerRequest { private Stream entityStream; diff --git a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs index 58f7229..5223c12 100644 --- a/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs +++ b/src/DotNetOpenAuth.Test/OpenId/TestSupport.cs @@ -9,7 +9,6 @@ namespace DotNetOpenAuth.Test.OpenId { using System.Collections.Generic; using System.IO; using System.Reflection; - using DotNetOAuth.Test.OpenId.UI; using DotNetOpenAuth.Messaging; using DotNetOpenAuth.OpenId; using DotNetOpenAuth.OpenId.Provider; @@ -33,7 +32,7 @@ namespace DotNetOpenAuth.Test.OpenId { public static readonly ILog Logger = LogManager.GetLogger("DotNetOpenId.Test"); - public static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\src\DotNetOpenId.TestWeb")); + public static readonly string TestWebDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\src\DotNetOpenAuth.TestWeb")); private const string IdentityPage = "IdentityEndpoint.aspx"; @@ -91,7 +90,7 @@ namespace DotNetOpenAuth.Test.OpenId { public static Uri GetFullUrl(string url, IDictionary<string, string> args, bool useSsl) { Uri defaultUriBase = new Uri(useSsl ? "https://localhost/" : "http://localhost/"); - Uri baseUri = UITestSupport.Host != null ? UITestSupport.Host.BaseUri : defaultUriBase; + Uri baseUri =/* UITestSupport.Host != null ? UITestSupport.Host.BaseUri : */defaultUriBase; UriBuilder builder = new UriBuilder(new Uri(baseUri, url)); MessagingUtilities.AppendQueryArgs(builder, args); return builder.Uri; diff --git a/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs b/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs deleted file mode 100644 index 92008ad..0000000 --- a/src/DotNetOpenAuth.Test/OpenId/UI/UITestSupport.cs +++ /dev/null @@ -1,27 +0,0 @@ -//----------------------------------------------------------------------- -// <copyright file="UITestSupport.cs" company="Andrew Arnott"> -// Copyright (c) Andrew Arnott. All rights reserved. -// </copyright> -//----------------------------------------------------------------------- - -namespace DotNetOAuth.Test.OpenId.UI { - using DotNetOpenAuth.Test.Hosting; - - ////[SetUpFixture] - public class UITestSupport { - internal static AspNetHost Host { get; private set; } - - ////[SetUp] - ////public void SetUp() { - //// Host = AspNetHost.CreateHost(TestSupport.TestWebDirectory); - ////} - - ////[TearDown] - ////public void TearDown() { - //// if (Host != null) { - //// Host.CloseHttp(); - //// Host = null; - //// } - ////} - } -} |