diff --git a/lib/Net/1.1/NUnitAspEx.dll b/lib/Net/1.1/NUnitAspEx.dll index 95c1eb4b..030f906e 100644 Binary files a/lib/Net/1.1/NUnitAspEx.dll and b/lib/Net/1.1/NUnitAspEx.dll differ diff --git a/lib/Net/1.1/NUnitAspEx.xml b/lib/Net/1.1/NUnitAspEx.xml new file mode 100644 index 00000000..e6d3470a --- /dev/null +++ b/lib/Net/1.1/NUnitAspEx.xml @@ -0,0 +1,139 @@ + + + + NUnitAspEx + + + + + Encapsulates a request from within a testsuite using the "asptest://" pseudo-protocol. + + + + + Encapsulates the ugly details of deriving from HttpWebRequest. + + + Since various frameworks like NUnitAsp rely on the output of WebRequest.Create() being of type HttpWebRequest + but HttpWebRequest is not customizable the easy way, this class shields further derived classes from the ugly reflection details. + + + + + Creates a new instance for the given uri. + + the to create this request for. + + + + + + + + + + + Override this method in your derived class and call to set the response object. + + + + + Create the stream to be used for uploading content. + + + + + + Encapsulates a response from an . + + + + + Encapsulates the ugly details of deriving from HttpWebResponse. + + + + + Summary description for HttpReflectionUtils. + + + + + Summary description for HttpWebClient. + + + + + An AspFixtureHost lives inside it's own AppDomain with an initialized HttpRuntime. + + + + + Summary description for IAspFixtureHost. + + + + + Creates a new Host instance within a new AppDomain based on the passed in Properties. + + + You must not call this method from within an existing Host's AppDomain. + + + + + Unload the passed Host's AppDomain. + + + + + Return null to avoid timing out of remoting references + + + + + + Initializes the newly created host instance. + + + + + Use this property to gain access to the Host from within the Host's AppDomain + + + This property is set only within the Host's AppDomain. + Outside the AppDomain it will always return null. + + + + + Use to synchronize access to this host instance + + + + + Returns a reference to the AppDomain, that created this Host instance + + + + + Returns the physical assembly reference location this AppDomain has been created from. + + + + + Summary description for AspTestClient. + + + + + Summary description for AspTestContext. + + + + + Summary description for AspTestExecutionModule. + + + + diff --git a/lib/Net/2.0/NUnitAspEx.dll b/lib/Net/2.0/NUnitAspEx.dll index 95c1eb4b..030f906e 100644 Binary files a/lib/Net/2.0/NUnitAspEx.dll and b/lib/Net/2.0/NUnitAspEx.dll differ diff --git a/lib/Net/2.0/NUnitAspEx.xml b/lib/Net/2.0/NUnitAspEx.xml new file mode 100644 index 00000000..e6d3470a --- /dev/null +++ b/lib/Net/2.0/NUnitAspEx.xml @@ -0,0 +1,139 @@ + + + + NUnitAspEx + + + + + Encapsulates a request from within a testsuite using the "asptest://" pseudo-protocol. + + + + + Encapsulates the ugly details of deriving from HttpWebRequest. + + + Since various frameworks like NUnitAsp rely on the output of WebRequest.Create() being of type HttpWebRequest + but HttpWebRequest is not customizable the easy way, this class shields further derived classes from the ugly reflection details. + + + + + Creates a new instance for the given uri. + + the to create this request for. + + + + + + + + + + + Override this method in your derived class and call to set the response object. + + + + + Create the stream to be used for uploading content. + + + + + + Encapsulates a response from an . + + + + + Encapsulates the ugly details of deriving from HttpWebResponse. + + + + + Summary description for HttpReflectionUtils. + + + + + Summary description for HttpWebClient. + + + + + An AspFixtureHost lives inside it's own AppDomain with an initialized HttpRuntime. + + + + + Summary description for IAspFixtureHost. + + + + + Creates a new Host instance within a new AppDomain based on the passed in Properties. + + + You must not call this method from within an existing Host's AppDomain. + + + + + Unload the passed Host's AppDomain. + + + + + Return null to avoid timing out of remoting references + + + + + + Initializes the newly created host instance. + + + + + Use this property to gain access to the Host from within the Host's AppDomain + + + This property is set only within the Host's AppDomain. + Outside the AppDomain it will always return null. + + + + + Use to synchronize access to this host instance + + + + + Returns a reference to the AppDomain, that created this Host instance + + + + + Returns the physical assembly reference location this AppDomain has been created from. + + + + + Summary description for AspTestClient. + + + + + Summary description for AspTestContext. + + + + + Summary description for AspTestExecutionModule. + + + + diff --git a/test/Spring/Spring.Web.Tests/Context/Support/WebApplicationContextTests.cs b/test/Spring/Spring.Web.Tests/Context/Support/WebApplicationContextTests.cs index 3c887c96..83b95c3a 100644 --- a/test/Spring/Spring.Web.Tests/Context/Support/WebApplicationContextTests.cs +++ b/test/Spring/Spring.Web.Tests/Context/Support/WebApplicationContextTests.cs @@ -20,10 +20,6 @@ #region Imports -using System; -using System.Threading; -using System.Web; -using NUnit.Extensions.Asp.AspTester; using NUnit.Framework; using NUnitAspEx; using Spring.Objects.Factory; @@ -38,18 +34,24 @@ namespace Spring.Context.Support /// /// /// Erich Eichinger - [AspTestFixture("/Test", "/Spring/Context/Support/WebApplicationContextTests")] + [TestFixture] public class WebApplicationContextTests : WebFormTestCase { + public WebApplicationContextTests() + : base("/Test", "/Spring/Context/Support/WebApplicationContextTests/") + {} + [Test] public void CanAccessContextFromNonWebThread() + { + Host.Execute(new TestAction(CanAccessContextFromNonWebThreadImpl)); + } + + public static void CanAccessContextFromNonWebThreadImpl() { IApplicationContext ctx; - using (TestWebContext requestContext = new TestWebContext("/Test", "/DoesNotExist.oaspx")) - { - ctx = WebApplicationContext.Current; - } + ctx = WebApplicationContext.GetRootContext(); AsyncTestMethod testMethod = new AsyncTestMethod(1, new AsyncTestMethod.TestMethod(DoBackgroundWork), ctx); testMethod.Start(); diff --git a/test/Spring/Spring.Web.Tests/MyNUnitAddinHelper.cs b/test/Spring/Spring.Web.Tests/MyNUnitAddinHelper.cs deleted file mode 100644 index 1eb3c26d..00000000 --- a/test/Spring/Spring.Web.Tests/MyNUnitAddinHelper.cs +++ /dev/null @@ -1,38 +0,0 @@ -#region License - -/* - * Copyright © 2002-2007 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#endregion - -#region Imports - -using System; -using NUnit.Core.Extensibility; - -#endregion - -namespace Spring -{ - /// - /// Required for auto-registering NUnitAspEx extension with NUnit for this assembly - /// - /// Erich Eichinger - [NUnitAddin] - public class MyNUnitAddinHelper : NUnitAspEx.NUnitAddinHelper - { - } -} \ No newline at end of file diff --git a/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectDefinitionFactoryTests.cs b/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectDefinitionFactoryTests.cs index d8cc8e05..015bf5b4 100644 --- a/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectDefinitionFactoryTests.cs +++ b/test/Spring/Spring.Web.Tests/Objects/Factory/Support/WebObjectDefinitionFactoryTests.cs @@ -23,6 +23,7 @@ using System; using NUnit.Framework; using NUnitAspEx; +using NUnitAspEx.Core; using Spring.TestSupport; #endregion @@ -33,9 +34,13 @@ namespace Spring.Objects.Factory.Support /// Unit tests for the WebObjectDefinitionFactory class. /// /// Erich Eichinger - [AspTestFixture("/Test", "/Spring/Objects/Factory/Support")] - public class WebObjectDefinitionFactoryTests + [TestFixture] + public class WebObjectDefinitionFactoryTests : WebApplicationTests { + public WebObjectDefinitionFactoryTests() + : base("/Test", "/Spring/Objects/Factory/Support") + {} + [Test] public void CreateRootDefinition() { @@ -83,6 +88,11 @@ namespace Spring.Objects.Factory.Support [Test] public void ResolvesToPageRootDefinitionIfEndsWithASPX() + { + Host.Execute(new TestAction(ResolvesToPageRootDefinitionIfEndsWithASPXImpl)); + } + + public static void ResolvesToPageRootDefinitionIfEndsWithASPXImpl() { using (TestWebContext ctx = new TestWebContext("/Test", "testform.aspx")) { @@ -97,6 +107,11 @@ namespace Spring.Objects.Factory.Support [Test] public void ResolvesToPageChildDefinitionIfEndsWithASPX() + { + Host.Execute(new TestAction(ResolvesToPageChildDefinitionIfEndsWithASPXImpl)); + } + + public static void ResolvesToPageChildDefinitionIfEndsWithASPXImpl() { using (TestWebContext ctx = new TestWebContext("/Test", "testform.aspx")) { @@ -112,6 +127,11 @@ namespace Spring.Objects.Factory.Support [Test] [ExpectedException(typeof(ObjectCreationException))] public void ThrowsArgumentExceptionOnNonExistingPath() + { + Host.Execute(new TestAction(ThrowsArgumentExceptionOnNonExistingPathImpl)); + } + + public static void ThrowsArgumentExceptionOnNonExistingPathImpl() { using (TestWebContext ctx = new TestWebContext("/Test", "testform.aspx")) { diff --git a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj index 1f227275..d5434841 100644 --- a/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj +++ b/test/Spring/Spring.Web.Tests/Spring.Web.Tests.2008.csproj @@ -98,7 +98,6 @@ ASPXCodeBehind - @@ -115,6 +114,7 @@ + @@ -161,7 +161,9 @@ - + + ASPXCodeBehind + diff --git a/test/Spring/Spring.Web.Tests/TestSupport/NUnitAdapter.cs b/test/Spring/Spring.Web.Tests/TestSupport/NUnitAdapter.cs index 88ce07c2..2d9eb173 100644 --- a/test/Spring/Spring.Web.Tests/TestSupport/NUnitAdapter.cs +++ b/test/Spring/Spring.Web.Tests/TestSupport/NUnitAdapter.cs @@ -41,11 +41,14 @@ namespace Spring.TestSupport /// Base class for NUnitAsp test fixtures. Extend this class to use NUnitAsp. /// [TestFixture] - public abstract class WebFormTestCase : CompatibilityAdapter + public abstract class WebFormTestCase : WebApplicationTests { private bool setupCalled = false; - /// + protected WebFormTestCase(string virtualPath, string relativePhysicalPath) : base(virtualPath, relativePhysicalPath) + {} + + /// /// Do not call. For use by NUnit only. /// [SetUp] @@ -111,7 +114,7 @@ namespace Spring.TestSupport { if (!setupCalled) { - Fail("A required setup method in WebFormTestCase was not called. This is probably because you used the [SetUp] attribute in a subclass of WebFormTestCase. That is not supported. Override the SetUp() method instead."); + Assert.Fail("A required setup method in WebFormTestCase was not called. This is probably because you used the [SetUp] attribute in a subclass of WebFormTestCase. That is not supported. Override the SetUp() method instead."); } } } diff --git a/test/Spring/Spring.Web.Tests/TestSupport/WebApplicationTests.cs b/test/Spring/Spring.Web.Tests/TestSupport/WebApplicationTests.cs new file mode 100644 index 00000000..3523f4c1 --- /dev/null +++ b/test/Spring/Spring.Web.Tests/TestSupport/WebApplicationTests.cs @@ -0,0 +1,60 @@ +#region License + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#endregion + +using NUnit.Framework; +using NUnitAspEx; +using NUnitAspEx.Core; + +namespace Spring.TestSupport +{ + /// + /// + /// Erich Eichinger + public abstract class WebApplicationTests + { + private readonly string virtualPath; + private readonly string relativePhysicalPath; + private IAspFixtureHost host; + + public IAspFixtureHost Host + { + get { return host; } + } + + protected WebApplicationTests(string virtualPath, string relativePhysicalPath) + { + this.virtualPath = virtualPath; + this.relativePhysicalPath = relativePhysicalPath; + } + + [TestFixtureSetUp] + public virtual void TestFixtureSetup() + { + host = AspFixtureHost.CreateInstance(virtualPath, relativePhysicalPath, this); + } + + [TestFixtureTearDown] + public virtual void TestFixtureTearDown() + { + host = AspFixtureHost.ReleaseInstance(host); + } + + } +} \ No newline at end of file diff --git a/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs index 10e58b0b..682437ff 100644 --- a/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs +++ b/test/Spring/Spring.Web.Tests/Web/Support/LocalResourceManagerTests.cs @@ -18,14 +18,10 @@ #endregion -#region Imports - -using System; using System.Diagnostics; using NUnit.Framework; -using NUnitAspEx; - -#endregion +using NUnitAspEx.Client; +using Spring.TestSupport; #if NET_2_0 @@ -35,13 +31,17 @@ namespace Spring.Web.Support /// /// /// Erich Eichinger - [AspTestFixture("/Test", "/Spring/Web/Support/LocalResourceManagerTests")] - public class LocalResourceManagerTests + [TestFixture] + public class LocalResourceManagerTests : WebApplicationTests { + public LocalResourceManagerTests() + : base("/Test", "/Spring/Web/Support/LocalResourceManagerTests") + {} + [Test] public void ReturnsWithResources() { - AspTestClient client = new AspTestClient(); + HttpWebClient client = Host.CreateWebClient(); string result = client.GetPage("WithResources.aspx"); Trace.Write(result); Assert.AreEqual("FromResource", result); @@ -50,7 +50,7 @@ namespace Spring.Web.Support [Test] public void ReturnsWithoutResources() { - AspTestClient client = new AspTestClient(); + HttpWebClient client = Host.CreateWebClient(); string result = client.GetPage("WithoutResources.aspx"); Assert.AreEqual("OK", result); } diff --git a/test/Spring/Spring.Web.Tests/Web/Support/PageHandlerFactoryTests.cs b/test/Spring/Spring.Web.Tests/Web/Support/PageHandlerFactoryTests.cs index 560537ca..666fec24 100644 --- a/test/Spring/Spring.Web.Tests/Web/Support/PageHandlerFactoryTests.cs +++ b/test/Spring/Spring.Web.Tests/Web/Support/PageHandlerFactoryTests.cs @@ -26,6 +26,7 @@ using System.IO; using NUnit.Extensions.Asp.AspTester; using NUnit.Framework; using NUnitAspEx; +using NUnitAspEx.Client; using Spring.TestSupport; #endregion @@ -36,13 +37,17 @@ namespace Spring.Web.Support /// /// /// Erich Eichinger - [AspTestFixture("/Test", "/Spring/Web/Support/PageHandlerFactoryTests")] + [TestFixture] public class PageHandlerFactoryTests : WebFormTestCase { + public PageHandlerFactoryTests() + : base("/Test", "/Spring/Web/Support/PageHandlerFactoryTests") + {} + [Test] public void DisablesSessions() { - AspTestClient client = new AspTestClient(); + HttpWebClient client = Host.CreateWebClient(); // a session-less page - checks, if session is correctly disabled string result = client.GetPage("DisablesSession.aspx"); Assert.AreEqual("OK", result); @@ -51,7 +56,7 @@ namespace Spring.Web.Support [Test, Explicit] public void UsesReadonlySession() { - AspTestClient client = new AspTestClient(); + HttpWebClient client = Host.CreateWebClient(); string result = client.GetPage("ReadOnlySession.aspx"); Assert.AreEqual("OK", result); } @@ -59,18 +64,26 @@ namespace Spring.Web.Support [Test] public void MaintainsSession() { - AspTestClient client = new AspTestClient(); + HttpWebClient client = Host.CreateWebClient(); string result = client.GetPage("MaintainsSession1.aspx"); Assert.AreEqual("OK", result); - Assert.AreEqual("somevalue", AspTestContext.HttpContext.Session["maintainsSession"]); +// Assert.AreEqual("somevalue", AspTestContext.HttpContext.Session["maintainsSession"]); // checks previously set session variable result = client.GetPage("MaintainsSession2.aspx"); Assert.AreEqual("OK", result); } + /// + /// Tests the behavior of the System.Web.PageHandlerFactory class + /// [Test] public void BCLPageHandlerFactoryBehavior() + { + Host.Execute(new TestAction(BCLPageHandlerFactoryBehaviorImpl)); + } + + public static void BCLPageHandlerFactoryBehaviorImpl() { using (TestWebContext ctx = new TestWebContext("/Test", "DoesNotExist.oaspx")) { @@ -93,8 +106,16 @@ namespace Spring.Web.Support } } + /// + /// Tests the behavior of our PageHandlerFactory class + /// [Test] public void PageHandlerFactoryBehavesLikeSystemPageHandlerFactory() + { + Host.Execute(new TestAction(PageHandlerFactoryBehavesLikeSystemPageHandlerFactoryImpl)); + } + + public static void PageHandlerFactoryBehavesLikeSystemPageHandlerFactoryImpl() { using (TestWebContext ctx = new TestWebContext("/Test", "DoesNotExist.aspx")) {