diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2008-03-01 17:01:14 +0000 |
---|---|---|
committer | Andrew <andrewarnott@gmail.com> | 2008-03-01 17:01:14 +0000 |
commit | 765ee1edb948b707dfc0d1b0f11aa557a48a550a (patch) | |
tree | 614d4b1c2f43fb00e8c94031e62612acbe7155a6 | |
parent | fc807aaebfdf8a81489e94f1a297c2b9bf495bc1 (diff) | |
download | DotNetOpenAuth-765ee1edb948b707dfc0d1b0f11aa557a48a550a.zip DotNetOpenAuth-765ee1edb948b707dfc0d1b0f11aa557a48a550a.tar.gz DotNetOpenAuth-765ee1edb948b707dfc0d1b0f11aa557a48a550a.tar.bz2 |
Added an ASP.NET hosting service to our test library.
Now we can write tests that depend on ASP.NET pages.
git-svn-id: https://dotnetopenid.googlecode.com/svn/trunk@255 01efa1a6-402a-0410-b0ae-47b76eba00f0
-rw-r--r-- | src/DotNetOpenId.Test/DotNetOpenId.Test.csproj | 3 | ||||
-rw-r--r-- | src/DotNetOpenId.Test/Hosting/ProviderHost.cs | 28 | ||||
-rw-r--r-- | src/DotNetOpenId.Test/Hosting/TestingWorkerRequest.cs | 21 | ||||
-rw-r--r-- | src/DotNetOpenId.Test/Provider/OpenIdProviderTest.cs | 24 | ||||
-rw-r--r-- | src/DotNetOpenId.TestWeb/HostTest.aspx | 14 | ||||
-rw-r--r-- | src/DotNetOpenId.TestWeb/HostTest.aspx.cs | 18 | ||||
-rw-r--r-- | src/DotNetOpenId.TestWeb/web.config | 8 | ||||
-rw-r--r-- | src/DotNetOpenId.sln | 34 |
8 files changed, 149 insertions, 1 deletions
diff --git a/src/DotNetOpenId.Test/DotNetOpenId.Test.csproj b/src/DotNetOpenId.Test/DotNetOpenId.Test.csproj index 103b43a..0e8d3e1 100644 --- a/src/DotNetOpenId.Test/DotNetOpenId.Test.csproj +++ b/src/DotNetOpenId.Test/DotNetOpenId.Test.csproj @@ -34,14 +34,17 @@ </Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
+ <Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssociationsTest.cs" />
<Compile Include="AssociationTestSuite.cs" />
<Compile Include="Consumer\OpenIdConsumerTest.cs" />
+ <Compile Include="Hosting\ProviderHost.cs" />
<Compile Include="DictionarySerializerTestSuite.cs" />
<Compile Include="DiffieHellmanTestSuite.cs" />
+ <Compile Include="Hosting\TestingWorkerRequest.cs" />
<Compile Include="ProfileFieldValuesTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Provider\OpenIdProviderTest.cs" />
diff --git a/src/DotNetOpenId.Test/Hosting/ProviderHost.cs b/src/DotNetOpenId.Test/Hosting/ProviderHost.cs new file mode 100644 index 0000000..a1e97ad --- /dev/null +++ b/src/DotNetOpenId.Test/Hosting/ProviderHost.cs @@ -0,0 +1,28 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Web;
+using System.Web.Hosting;
+using System.IO;
+
+namespace DotNetOpenId.Test.Hosting {
+ /// <summary>
+ /// Hosts a 'portable' version of the OpenIdProvider for testing itself and the
+ /// Consumer against it.
+ /// </summary>
+ class Host : MarshalByRefObject {
+ public static Host CreateHost(string webDirectory) {
+ Host host = (Host)System.Web.Hosting.ApplicationHost.
+ CreateApplicationHost(typeof(Host), "/", webDirectory);
+ return host;
+ }
+
+ public void ProcessRequest(string page, string query, string body, TextWriter responseWriter) {
+ ProcessRequest(new TestingWorkerRequest(page, query, body, responseWriter));
+ }
+
+ public void ProcessRequest(HttpWorkerRequest wr) {
+ System.Web.HttpRuntime.ProcessRequest(wr);
+ }
+ }
+}
diff --git a/src/DotNetOpenId.Test/Hosting/TestingWorkerRequest.cs b/src/DotNetOpenId.Test/Hosting/TestingWorkerRequest.cs new file mode 100644 index 0000000..55d7532 --- /dev/null +++ b/src/DotNetOpenId.Test/Hosting/TestingWorkerRequest.cs @@ -0,0 +1,21 @@ +using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Web.Hosting;
+using System.IO;
+
+namespace DotNetOpenId.Test.Hosting {
+ class TestingWorkerRequest : SimpleWorkerRequest {
+ public TestingWorkerRequest(string page, string query, string body, TextWriter output)
+ : base(page, query, output) {
+ this.body = body;
+ }
+ string body;
+ public override bool IsEntireEntityBodyIsPreloaded() {
+ return true;
+ }
+ public override byte[] GetPreloadedEntityBody() {
+ return Encoding.ASCII.GetBytes(body);
+ }
+ }
+}
diff --git a/src/DotNetOpenId.Test/Provider/OpenIdProviderTest.cs b/src/DotNetOpenId.Test/Provider/OpenIdProviderTest.cs index 2d38b35..15a3cfe 100644 --- a/src/DotNetOpenId.Test/Provider/OpenIdProviderTest.cs +++ b/src/DotNetOpenId.Test/Provider/OpenIdProviderTest.cs @@ -2,9 +2,33 @@ using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
+using System.IO;
+using System.Diagnostics;
+using DotNetOpenId.Test.Hosting;
+using System.Text.RegularExpressions;
namespace DotNetOpenId.Test.Provider {
[TestFixture]
public class OpenIdProviderTest {
+ static readonly string webDirectory = Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\src\DotNetOpenId.TestWeb"));
+ Host host;
+
+ [SetUp]
+ public void SetUpHost() {
+ host = Host.CreateHost(webDirectory);
+ }
+
+ [Test]
+ public void TestHost() {
+ StringWriter sw = new StringWriter();
+ string query = "a=b&c=d";
+ string body = "aa=bb&cc=dd";
+ host.ProcessRequest("hosttest.aspx",query, body, sw);
+ string resultHtml = sw.ToString();
+ Assert.IsFalse(string.IsNullOrEmpty(resultHtml));
+ Debug.WriteLine(resultHtml);
+ Assert.IsTrue(Regex.IsMatch(resultHtml, @"Query.*" + Regex.Escape(query)));
+ Assert.IsTrue(Regex.IsMatch(resultHtml, @"Body.*" + Regex.Escape(body)));
+ }
}
}
diff --git a/src/DotNetOpenId.TestWeb/HostTest.aspx b/src/DotNetOpenId.TestWeb/HostTest.aspx new file mode 100644 index 0000000..2ce3fd1 --- /dev/null +++ b/src/DotNetOpenId.TestWeb/HostTest.aspx @@ -0,0 +1,14 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="HostTest.aspx.cs" Inherits="HostTest" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title>Test Page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ Query: <asp:Label ID="queryLabel" runat="server" />
+ Body: <asp:Label ID="bodyLabel" runat="server" />
+ </form>
+</body>
+</html>
diff --git a/src/DotNetOpenId.TestWeb/HostTest.aspx.cs b/src/DotNetOpenId.TestWeb/HostTest.aspx.cs new file mode 100644 index 0000000..87bc857 --- /dev/null +++ b/src/DotNetOpenId.TestWeb/HostTest.aspx.cs @@ -0,0 +1,18 @@ +using System;
+using System.Configuration;
+using System.Data;
+using System.Web;
+using System.Web.Security;
+using System.Web.UI;
+using System.Web.UI.HtmlControls;
+using System.Web.UI.WebControls;
+using System.Web.UI.WebControls.WebParts;
+using System.IO;
+
+public partial class HostTest : System.Web.UI.Page {
+ protected void Page_Load(object sender, EventArgs e) {
+ queryLabel.Text = Request.Url.Query;
+ using (StreamReader sr = new StreamReader(Request.InputStream))
+ bodyLabel.Text = sr.ReadToEnd();
+ }
+}
diff --git a/src/DotNetOpenId.TestWeb/web.config b/src/DotNetOpenId.TestWeb/web.config new file mode 100644 index 0000000..47684a1 --- /dev/null +++ b/src/DotNetOpenId.TestWeb/web.config @@ -0,0 +1,8 @@ +<?xml version="1.0"?>
+<configuration>
+ <system.web>
+ <compilation debug="true"/>
+ <authentication mode="Windows" />
+ <customErrors mode="Off" />
+ </system.web>
+</configuration>
diff --git a/src/DotNetOpenId.sln b/src/DotNetOpenId.sln index ccf7d67..5dae11f 100644 --- a/src/DotNetOpenId.sln +++ b/src/DotNetOpenId.sln @@ -16,6 +16,28 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProviderPortal", "..\sample EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Samples", "Samples", "{48A90678-A754-4E6E-98E2-7C519607C85F}"
EndProject
+Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "DotNetOpenId.TestWeb", "DotNetOpenId.TestWeb", "{C733BE07-37B5-4328-8C1A-81F129670E6E}"
+ ProjectSection(WebsiteProperties) = preProject
+ TargetFramework = "2.0"
+ ProjectReferences = "{CDEE655B-3902-420E-ADED-F4B6F666FB03}|DotNetOpenId.Test.dll;{5D6EDC86-F5B2-4786-8376-4E7C24C63D39}|DotNetOpenId.dll;"
+ Debug.AspNetCompiler.VirtualPath = "/DotNetOpenId.TestWeb"
+ Debug.AspNetCompiler.PhysicalPath = "DotNetOpenId.TestWeb\"
+ Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\DotNetOpenId.TestWeb\"
+ Debug.AspNetCompiler.Updateable = "true"
+ Debug.AspNetCompiler.ForceOverwrite = "true"
+ Debug.AspNetCompiler.FixedNames = "false"
+ Debug.AspNetCompiler.Debug = "True"
+ Release.AspNetCompiler.VirtualPath = "/DotNetOpenId.TestWeb"
+ Release.AspNetCompiler.PhysicalPath = "DotNetOpenId.TestWeb\"
+ Release.AspNetCompiler.TargetPath = "PrecompiledWeb\DotNetOpenId.TestWeb\"
+ Release.AspNetCompiler.Updateable = "true"
+ Release.AspNetCompiler.ForceOverwrite = "true"
+ Release.AspNetCompiler.FixedNames = "false"
+ Release.AspNetCompiler.Debug = "False"
+ VWDPort = "22205"
+ DefaultWebSiteLanguage = "Visual C#"
+ EndProjectSection
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|.NET = Debug|.NET
@@ -66,12 +88,22 @@ Global {2A59DE0A-B76A-4B42-9A33-04D34548353D}.Release|Any CPU.Build.0 = Release|Any CPU
{2A59DE0A-B76A-4B42-9A33-04D34548353D}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2A59DE0A-B76A-4B42-9A33-04D34548353D}.Release|Mixed Platforms.Build.0 = Release|Any CPU
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Debug|.NET.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Debug|.NET.Build.0 = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Debug|Any CPU.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Debug|Mixed Platforms.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Debug|Mixed Platforms.Build.0 = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Release|.NET.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Release|.NET.Build.0 = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Release|Any CPU.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Release|Mixed Platforms.ActiveCfg = Debug|.NET
+ {C733BE07-37B5-4328-8C1A-81F129670E6E}.Release|Mixed Platforms.Build.0 = Debug|.NET
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
- {51BCD5E9-E17A-4FB2-BAC8-C156DD7A1CA4} = {48A90678-A754-4E6E-98E2-7C519607C85F}
{2A59DE0A-B76A-4B42-9A33-04D34548353D} = {48A90678-A754-4E6E-98E2-7C519607C85F}
+ {51BCD5E9-E17A-4FB2-BAC8-C156DD7A1CA4} = {48A90678-A754-4E6E-98E2-7C519607C85F}
EndGlobalSection
EndGlobal
|