Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
//
// AppDomainFactoryCas.cs
// - CAS unit tests for System.Web.Hosting.AppDomainFactory
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;
namespace MonoCasTests.System.Web.Hosting {
[TestFixture]
[Category ("CAS")]
public class AppDomainFactoryCas : AspNetHostingMinimal {
private AppDomainFactory adf;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// we're at full trust here
adf = new AppDomainFactory ();
}
// test ctor
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor_Deny_UnmanagedCode ()
{
new AppDomainFactory ();
}
[Test]
[AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
#if NET_2_0
[ExpectedException (typeof (SecurityException))]
#endif
public void Constructor_Deny_AspNetHostingPermission ()
{
new AppDomainFactory ();
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
[AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
public void Constructor_PermitOnly_UnmanagedCode ()
{
new AppDomainFactory ();
}
// Create isn't protected (so the Demands aren't on the class)
private void Create ()
{
try {
adf.Create (null, null, null, null, null, 0);
}
catch (NullReferenceException) {
// MS
}
catch (NotImplementedException) {
// Mono
}
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
public void Create_Deny_UnmanagedCode ()
{
Create ();
}
[Test]
[AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
public void Create_Deny_AspNetHostingPermission ()
{
Create ();
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Create_Deny_Unrestricted ()
{
Create ();
}
// test for LinkDemand on class
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
// don't let UnmanagedCode mess up the results
return base.CreateControl (action, level);
}
public override Type Type {
get { return typeof (AppDomainFactory); }
}
}
}

View File

@@ -0,0 +1,103 @@
//
// ApplicationHostCas.cs
// - CAS unit tests for System.Web.Hosting.ApplicationHost
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;
namespace MonoCasTests.System.Web.Hosting {
[TestFixture]
[Category ("CAS")]
public class ApplicationHostCas : AspNetHostingMinimal {
private void CreateApplicationHost ()
{
try {
ApplicationHost.CreateApplicationHost (null, null, null);
}
catch (NullReferenceException) {
// MS
}
catch (NotImplementedException) {
// Mono
}
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void CreateApplicationHost_Deny_UnmanagedCode ()
{
CreateApplicationHost ();
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
public void CreateApplicationHost_PermitOnly_UnmanagedCode ()
{
CreateApplicationHost ();
}
// test for LinkDemand on class
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
// in this case testing with a (private) ctor isn't very conveniant
// and the LinkDemand promotion (to Demand) will still occurs on other stuff
// and (finally) we know that the CreateApplicationHost method is only
// protected for unmanaged code (which we can assert)
try {
MethodInfo mi = this.Type.GetMethod ("CreateApplicationHost");
Assert.IsNotNull (mi, "method");
return mi.Invoke (null, new object[3] { null, null, null });
}
catch (TargetInvocationException e) {
// so we hit the same exception as we did for the ctor
if (e.InnerException is NullReferenceException)
return String.Empty; // MS
else if (e.InnerException is NotImplementedException)
return String.Empty; // Mono
else
return null;
}
}
public override Type Type {
get { return typeof (ApplicationHost); }
}
}
}

View File

@@ -0,0 +1,192 @@
//
// System.Web.Hosting.ApplicationHost.cs
//
// Author:
// Miguel de Icaza (miguel@novell.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using System;
using System.Runtime.Serialization;
using System.IO;
using System.Web.Hosting;
using NUnit.Framework;
using System.Web;
namespace MonoTests.System.Web.Hosting {
public class MBR : MarshalByRefObject {
public string GetDomainName ()
{
return AppDomain.CurrentDomain.FriendlyName;
}
public AppDomain GetDomain ()
{
return AppDomain.CurrentDomain;
}
}
[Serializable]
public class MySerializable {
public string GetDomainName ()
{
return AppDomain.CurrentDomain.FriendlyName;
}
}
[TestFixture]
public class ApplicationHostTest {
[SetUp]
public void Setup ()
{
try {
//
// Only needed in Windows, where we need to have a bin/ASSEMBLY.DLL
//
string p = typeof (ApplicationHostTest).Assembly.Location;
try {
Directory.Delete ("bin", true);
} catch {}
try {
Directory.CreateDirectory ("bin");
} catch {}
string fn = Path.GetFileName (p);
File.Copy (p, Path.Combine ("bin", fn));
} catch {}
}
[TearDown] public void Shutdown ()
{
try {
Directory.Delete ("bin", true);
} catch {}
}
[Test][ExpectedException (typeof (NullReferenceException))]
public void ConstructorTestNull ()
{
ApplicationHost.CreateApplicationHost (null, null, null);
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void ConstructorTestNull2 ()
{
ApplicationHost.CreateApplicationHost (null, "/app", ".");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ConstructorTestNull3 ()
{
ApplicationHost.CreateApplicationHost (typeof (MBR), null, ".");
}
[Test][ExpectedException (typeof (NullReferenceException))]
public void ConstructorTestNull4 ()
{
ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", null);
}
[Test]
[ExpectedException(typeof(SerializationException))]
#if TARGET_JVM //System.Security.Policy.Evidence not implemented
[Category ("NotWorking")]
#endif
public void Constructor_PlainType ()
{
ApplicationHost.CreateApplicationHost (typeof (ApplicationHostTest), "/app", Environment.CurrentDirectory);
}
[Test]
public void Constructor_SerializableType ()
{
object o = ApplicationHost.CreateApplicationHost (typeof (MySerializable), "/app", Environment.CurrentDirectory);
Assert.AreEqual (typeof (MySerializable), o.GetType (), "C2");
MySerializable m = (MySerializable) o;
Assert.AreEqual (m.GetDomainName (), AppDomain.CurrentDomain.FriendlyName, "C4");
}
static void p (string s, object x)
{
Console.WriteLine ("{0} {1}", s, x);
}
[Test]
[Category ("NotDotNet")] // D2 and D3 asserts will fail in windows on because file system environment
public void ConstructorTest ()
{
object o = ApplicationHost.CreateApplicationHost (typeof (MBR), "/app", Environment.CurrentDirectory);
Assert.AreEqual (typeof (MBR), o.GetType (), "C5");
MBR m = (MBR) o;
Assert.AreEqual (true, m.GetDomainName () != AppDomain.CurrentDomain.FriendlyName);
AppDomain other = m.GetDomain ();
AppDomainSetup setup = other.SetupInformation;
string tb = Environment.CurrentDirectory;
if (tb[tb.Length - 1] == Path.DirectorySeparatorChar)
tb = tb.Substring (0, tb.Length - 1);
// Need to fix an issue in AppDomainSetup
// Assert.AreEqual (tb + "/", setup.ApplicationBase, "D1");
p ("AppDomain's Applicationname is: ", setup.ApplicationName);
// IGNORE this test. We are setting CachePath to DynamicBase by now.
// Assert.AreEqual (null, setup.CachePath, "D2");
Assert.AreEqual (0, String.Compare (tb + Path.DirectorySeparatorChar + "Web.Config", setup.ConfigurationFile, StringComparison.OrdinalIgnoreCase), "D3");
Assert.AreEqual (false, setup.DisallowBindingRedirects, "D4");
Assert.AreEqual (true, setup.DisallowCodeDownload, "D5");
Assert.AreEqual (false, setup.DisallowPublisherPolicy, "D6");
// Disabling D7 test, as we set it there to avoid locking in sys.web.compilation
// Assert.AreEqual (null, setup.DynamicBase, "D7");
Assert.AreEqual (null, setup.LicenseFile, "D8");
//Assert.AreEqual (LoaderOptimization.NotSpecified, setup.LoaderOptimization);
p ("LoaderOptimization is: ", setup.LoaderOptimization);
Assert.AreEqual (0, string.Compare (
#if NET_2_0
String.Format ("{0}{1}bin", tb, Path.DirectorySeparatorChar),
#else
"bin",
#endif
setup.PrivateBinPath, true), "D9"
);
Assert.AreEqual (setup.PrivateBinPathProbe, "*", "D10");
p ("ShadowCopyDirs: ", setup.ShadowCopyDirectories);
Assert.AreEqual (true, setup.ShadowCopyDirectories.EndsWith ("bin") || setup.ShadowCopyDirectories.EndsWith ("Bin"), "D11");
Assert.AreEqual (false, setup.ShadowCopyDirectories.StartsWith ("file:"), "D12");
Assert.AreEqual ("true", setup.ShadowCopyFiles, "D13");
p ("ApsInstal", HttpRuntime.AspInstallDirectory);
}
}
}

View File

@@ -0,0 +1,121 @@
2010-02-18 Marek Habersack <mhabersack@novell.com>
* HostingEnvironmentTest.cs: added a test for HostEnvironment
property values both in hosted and non-hosted environments. Patch
contributed by Tiaan Geldenhuys <tagdev@gmail.com>, thanks!
2009-01-07 Geoff Norton <gnorton@novell.com>
* ApplicationHostTest.cs: Fix a few case-sensitiviy issues.
2008-10-31 Gonzalo Paniagua Javier <gonzalo@novell.com>
* ApplicationHostTest.cs: ignore the CachePath test. We are settig it
to DynamicBase to make all the temporary and shadow-copied files go
into the same directory.
2008-03-13 Marek Habersack <mhabersack@novell.com>
* ApplicationHostTest.cs: adjust test for the PrivateBinPath
change in ApplicationHost.
2007-11-03 Marek Habersack <mhabersack@novell.com>
* ApplicationHostTest.cs: adjust ConstructorTest for
AppDomainSetup.PrivateBinPath changes.
2007-08-24 Marek Habersack <mhabersack@novell.com>
* ApplicationHostTest.cs: use ; as the separator in the
PrivateBinPath test.
2007-08-21 Marek Habersack <mhabersack@novell.com>
* ApplicationHostTest.cs: adjust the test for the PrivateBinPath
changes.
2006-03-23 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SimpleWorkerRequestTest.cs: new tests for PathInfo and disabled a test
that throws a nullref under MS.
* ApplicationHostTest.cs: fixed 2 assertions to expect what MS does.
2006-02-02 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HostingEnvironmentTest.cs: tests for MapPath.
2006-02-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* VirtualPathProviderTest.cs: tests for GetFileHash.
2006-02-01 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* HostingEnvironmentTest.cs: new tests.
2006-01-25 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* VirtualPathProviderTest.cs: new tests.
2005-11-23 Robert Jordan <robertj@gmx.net>
* SimpleWorkerRequestTest.cs: added a test case for #76794.
2005-09-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* ApplicationHostTest.cs: disabled a test.
2005-09-21 Sebastien Pouliot <sebastien@ximian.com>
* SimpleWorkerRequestTest.cs: When in doubt write more tests...
2005-09-18 Sebastien Pouliot <sebastien@ximian.com>
* SimpleWorkerRequestTest.cs: Ensure a trailing / in the expected path
as GetAppPathTranslated must have one (while most directory methods
don't append one).
2005-09-13 Sebastien Pouliot <sebastien@ximian.com>
* SimpleWorkerRequestTest.cs: Added a test case (GetUriPath) that was
failing in the CAS tests (but wasn't CAS related).
* SimpleWorkerRequestCas.cs: Ignore the ctor(string,string,TextWriter)
test as I don't have a working test case. Simplify GetUriPath check
so it doesn't fail.
2005-09-10 Sebastien Pouliot <sebastien@ximian.com>
* AppDomainFactoryCas.cs: New. CAS unit tests for AppDomainFactory.
* ApplicationHostCas.cs: New. CAS unit tests for ApplicationHost.
* ISAPIRuntimeCas.cs: New. CAS unit tests for ISAPIRuntime.
* SimpleWorkerRequestCas.cs: New. CAS unit tests for
SimpleWorkerRequest.
* SimpleWorkerRequestTest.cs: Added a few (unworking) test cases for
GetPathInfo method.
2005-08-22 Chris Toshok <toshok@ximian.com>
* SimpleWorkerRequestTest.cs (Host): make cwd =
"Environment.CurrentDirectory + Path.DirectorySeparatorChar" so we
pass on MS.
2005-08-20 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* SimpleWorkerRequestTest.cs: add 2 more assertions.
* ApplicationHostTest.cs: fix test for the path of web.config.
2005-07-27 Miguel de Icaza <miguel@novell.com>
* SimpleWorkerRequestTest.cs: Do not use the "/tmp" directory as
that makes the tests fail if we create a hosted
SimpleWorkerRequest.
Instead use the current directory, and before starting up, create
a bin directory and copy the assembly there to allow us to create
a host.
Also, replicate the tests for when we are hosted in a new
appdomain, as "MapPath" does work in this case. When running
SimpleWorkerRequest on the main domain MapPath always returns
null.

View File

@@ -0,0 +1,111 @@
//
// System.Web.Hosting.HostingEnvironmentTest
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@novell.com)
//
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Web.Hosting;
using NUnit.Framework;
using System.Web;
using System.Web.UI;
using MonoTests.SystemWeb.Framework;
namespace MonoTests.System.Web.Hosting {
[TestFixture]
public class HostingEnvironmentTest {
[Test]
public void StaticDefaultValues ()
{
StaticDefaultValues (string.Empty);
}
private void StaticDefaultValues (string errorPrefix)
{
Assert.IsNull (HostingEnvironment.InitializationException, errorPrefix + "InitializationException");
Assert.IsFalse (HostingEnvironment.IsHosted, errorPrefix + "IsHosted");
Assert.IsNull (HostingEnvironment.ApplicationID, errorPrefix + "ApplicationID");
Assert.IsNull (HostingEnvironment.ApplicationPhysicalPath, errorPrefix + "ApplicationPhysicalPath");
Assert.IsNull (HostingEnvironment.ApplicationVirtualPath, errorPrefix + "ApplicationVirtualPath");
Assert.IsNull (HostingEnvironment.SiteName, errorPrefix + "SiteName");
Assert.IsNotNull (HostingEnvironment.Cache, errorPrefix + "Cache");
Assert.AreEqual (ApplicationShutdownReason.None, HostingEnvironment.ShutdownReason, errorPrefix + "None");
Assert.IsNull (HostingEnvironment.VirtualPathProvider, errorPrefix + "VirtualPathProvider");
}
[Test]
[Category ("NunitWeb")]
public void HostedDefaultValues ()
{
StaticDefaultValues ("Before:");
WebTest t = new WebTest (PageInvoker.CreateOnLoad (HostedDefaultValues_OnLoad));
t.Run ();
Assert.AreEqual (global::System.Net.HttpStatusCode.OK, t.Response.StatusCode, "HttpStatusCode");
StaticDefaultValues ("After:");
}
public static void HostedDefaultValues_OnLoad(Page p)
{
Assert.IsNull (HostingEnvironment.InitializationException, "During:InitializationException");
Assert.IsTrue (HostingEnvironment.IsHosted, "During:IsHosted");
Assert.IsNotNull (HostingEnvironment.ApplicationID, "During:ApplicationID:Null");
Assert.IsNotEmpty (HostingEnvironment.ApplicationID, "During:ApplicationID:Empty");
Assert.IsNotNull (HostingEnvironment.ApplicationPhysicalPath, "During:ApplicationPhysicalPath:Null");
Assert.IsNotEmpty (HostingEnvironment.ApplicationPhysicalPath, "During:ApplicationPhysicalPath:Empty");
Assert.IsNotNull (HostingEnvironment.ApplicationVirtualPath, "During:ApplicationVirtualPath:Null");
Assert.IsNotEmpty (HostingEnvironment.ApplicationVirtualPath, "During:ApplicationVirtualPath:Empty");
Assert.IsNotNull (HostingEnvironment.SiteName, "During:SiteName:Null");
Assert.IsNotEmpty (HostingEnvironment.SiteName, "During:SiteName:Empty");
Assert.IsNotNull (HostingEnvironment.Cache, "During:Cache");
Assert.AreEqual (ApplicationShutdownReason.None, HostingEnvironment.ShutdownReason, "During:ShutdownReason");
Assert.IsNotNull (HostingEnvironment.VirtualPathProvider, "During:VirtualPathProvider");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MapPath1 ()
{
HostingEnvironment.MapPath (null);
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void MapPath2 ()
{
HostingEnvironment.MapPath ("");
}
[Test]
public void MapPath3 ()
{
Assert.IsNull (HostingEnvironment.MapPath ("hola"));
}
}
}
#endif

View File

@@ -0,0 +1,182 @@
//
// ISAPIRuntimeCas.cs - CAS unit tests for System.Web.Hosting.ISAPIRuntime
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;
namespace MonoCasTests.System.Web.Hosting {
[TestFixture]
[Category ("CAS")]
public class ISAPIRuntimeCas : AspNetHostingMinimal {
private ISAPIRuntime isapi;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// we're at full trust here
isapi = new ISAPIRuntime ();
}
// test ctor (those tests aren't affected by a LinkDemand)
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor_Deny_UnmanagedCode ()
{
new ISAPIRuntime ();
}
[Test]
[AspNetHostingPermission (SecurityAction.Deny, Level = AspNetHostingPermissionLevel.Minimal)]
#if NET_2_0
[ExpectedException (typeof (SecurityException))]
#endif
public void Constructor_Deny_AspNetHostingPermission ()
{
new ISAPIRuntime ();
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
[AspNetHostingPermission (SecurityAction.PermitOnly, Level = AspNetHostingPermissionLevel.Minimal)]
public void Constructor_PermitOnly_UnmanagedCode ()
{
new ISAPIRuntime ();
}
// only StopProcessing requires some permissions (UnmanagedCode)
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Members_Deny_Unrestricted ()
{
try {
isapi.DoGCCollect ();
}
catch (NotImplementedException) {
// mono
}
try {
isapi.ProcessRequest (IntPtr.Zero, 0);
}
#if NET_2_0
catch (AccessViolationException) {
// fx2.0
}
#else
catch (NullReferenceException) {
// fx1.x
}
#endif
catch (NotImplementedException) {
// mono
}
try {
isapi.StartProcessing ();
}
catch (NotImplementedException) {
// mono
}
#if NET_2_0
try {
isapi.InitializeLifetimeService ();
}
catch (NotImplementedException) {
// mono
}
#endif
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
#if NET_2_0
[ExpectedException (typeof (SecurityException))]
#endif
public void StopProcessing_Deny_UnmanagedCode ()
{
try {
isapi.StopProcessing ();
}
#if ONLY_1_1
catch (TypeInitializationException) {
// fx 1.x
}
catch (NotImplementedException) {
// mono
}
#endif
finally {
}
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
public void StopProcessing_PermitOnly_UnmanagedCode ()
{
try {
isapi.StopProcessing ();
}
#if ONLY_1_1
catch (TypeInitializationException) {
// fx 1.x
}
#endif
catch (NotImplementedException) {
// mono
}
}
// test for LinkDemand on class
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
// in this case testing the ctor isn't very conveniant
// because it has a Demand similar to the LinkDemand.
try {
return base.CreateControl (action, level);
}
catch (TargetInvocationException tie) {
throw tie.InnerException;
}
}
public override Type Type {
get { return typeof (ISAPIRuntime); }
}
}
}

View File

@@ -0,0 +1,181 @@
//
// SimpleWorkerRequestCas.cs
// - CAS unit tests for System.Web.Hosting.SimpleWorkerRequest
//
// Author:
// Sebastien Pouliot <sebastien@ximian.com>
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Reflection;
using System.Security;
using System.Security.Permissions;
using System.Web;
using System.Web.Hosting;
namespace MonoCasTests.System.Web.Hosting {
[TestFixture]
[Category ("CAS")]
public class SimpleWorkerRequestCas : AspNetHostingMinimal {
private StringWriter sw;
private string cwd;
private SimpleWorkerRequest swr;
[TestFixtureSetUp]
public void FixtureSetUp ()
{
// we're at full trust here
sw = new StringWriter ();
cwd = Environment.CurrentDirectory;
swr = new SimpleWorkerRequest ("/", cwd, String.Empty, String.Empty, sw);
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor3_Deny_UnmanagedCode ()
{
new SimpleWorkerRequest (null, null, null);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
[Ignore ("I don't have a 'real' working case, inside NUnit, for this .ctor")]
public void Constructor3_PermitOnly_UnmanagedCode ()
{
try {
new SimpleWorkerRequest ("/", String.Empty, sw);
}
catch (NullReferenceException) {
// we always seems to get a NRE from MS here (both 1.x and 2.0)
}
// note: on Mono a FileIOPermission is triggered later
// in a call to HttpRuntime
}
[Test]
[SecurityPermission (SecurityAction.Deny, UnmanagedCode = true)]
[ExpectedException (typeof (SecurityException))]
public void Constructor5_Deny_UnmanagedCode ()
{
new SimpleWorkerRequest (null, null, null, null, null);
}
[Test]
[SecurityPermission (SecurityAction.PermitOnly, UnmanagedCode = true)]
public void Constructor5_PermitOnly_UnmanagedCode ()
{
new SimpleWorkerRequest (null, cwd, "/", String.Empty, sw);
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Properties_Deny_Unrestricted ()
{
Assert.IsNull (swr.MachineConfigPath, "MachineConfigPath");
Assert.IsNull (swr.MachineInstallDirectory, "MachineInstallDirectory");
Assert.AreEqual ("/", swr.GetAppPath (), "GetAppPath");
Assert.AreEqual ("/", swr.GetFilePath (), "GetFilePath");
Assert.AreEqual ("GET", swr.GetHttpVerbName (), "GetHttpVerbName");
Assert.AreEqual ("HTTP/1.0", swr.GetHttpVersion (), "GetHttpVersion");
Assert.AreEqual ("127.0.0.1", swr.GetLocalAddress (), "GetLocalAddress");
Assert.AreEqual (80, swr.GetLocalPort (), "GetLocalPort");
Assert.AreEqual (String.Empty, swr.GetPathInfo (), "GetPathInfo");
Assert.AreEqual (String.Empty, swr.GetQueryString (), "GetQueryString");
Assert.AreEqual ("/", swr.GetRawUrl (), "GetRawUrl");
Assert.AreEqual ("127.0.0.1", swr.GetRemoteAddress (), "GetRemoteAddress");
Assert.AreEqual (0, swr.GetRemotePort (), "GetRemotePort");
Assert.AreEqual (String.Empty, swr.GetServerVariable ("mono"), "GetServerVariable");
Assert.IsNotNull (swr.GetUriPath (), "GetUriPath");
Assert.AreEqual (IntPtr.Zero, swr.GetUserToken (), "GetUserToken");
Assert.IsNull (swr.MapPath ("/"), "MapPath");
}
[Test]
[PermissionSet (SecurityAction.Deny, Unrestricted = true)]
public void Methods_Deny_Unrestricted ()
{
swr.EndOfRequest ();
swr.FlushResponse (true);
swr.SendKnownResponseHeader (0, String.Empty);
swr.SendResponseFromFile (IntPtr.Zero, 0, 0);
swr.SendResponseFromFile (String.Empty, 0, 0);
swr.SendResponseFromMemory (new byte[0], 0);
swr.SendStatus (0, "hello?");
swr.SendUnknownResponseHeader ("mono", "monkey");
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void GetAppPathTranslated_Deny_FileIOPermission ()
{
// path discovery
swr.GetAppPathTranslated ();
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void GetAppPathTranslated_PermitOnly_FileIOPermission ()
{
Assert.IsNotNull (swr.GetAppPathTranslated (), "GetAppPathTranslated");
}
[Test]
[FileIOPermission (SecurityAction.Deny, Unrestricted = true)]
[ExpectedException (typeof (SecurityException))]
public void GetFilePathTranslated_Deny_FileIOPermission ()
{
// path discovery
swr.GetFilePathTranslated ();
}
[Test]
[FileIOPermission (SecurityAction.PermitOnly, Unrestricted = true)]
public void GetFilePathTranslated_PermitOnly_FileIOPermission ()
{
Assert.IsNotNull (swr.GetFilePathTranslated (), "GetFilePathTranslated");
}
// LinkDemand
[SecurityPermission (SecurityAction.Assert, UnmanagedCode = true)]
public override object CreateControl (SecurityAction action, AspNetHostingPermissionLevel level)
{
ConstructorInfo ci = this.Type.GetConstructor (new Type[5] { typeof (string), typeof (string), typeof (string), typeof (string), typeof (TextWriter) });
Assert.IsNotNull (ci, ".ctor(string,string,TextWriter)");
return ci.Invoke (new object[5] { null, cwd, "/", String.Empty, sw });
}
public override Type Type {
get { return typeof (SimpleWorkerRequest); }
}
}
}

View File

@@ -0,0 +1,333 @@
//
// Tests for System.Web.Hosting.SimpleWorkerRequest.cs
//
// Author:
// Miguel de Icaza (miguel@novell.com)
//
//
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
using NUnit.Framework;
using System;
using System.IO;
using System.Globalization;
using System.Web;
using System.Web.Hosting;
namespace MonoTests.System.Web.Hosting {
[TestFixture]
public class SimpleWorkerRequestTest {
string cwd, bindir;
string assembly;
[SetUp] public void startup ()
{
cwd = Environment.CurrentDirectory;
bindir = Path.Combine (cwd, "bin");
Uri u = new Uri (typeof (SimpleWorkerRequestTest).Assembly.CodeBase);
assembly = u.LocalPath;
if (!Directory.Exists (bindir))
Directory.CreateDirectory (bindir);
File.Copy (assembly, Path.Combine (bindir, Path.GetFileName (assembly)), true);
}
//
// This tests the constructor when the user code creates an HttpContext
//
[Test] public void ConstructorTests ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr;
swr = new SimpleWorkerRequest ("/appVirtualDir", cwd, "pageVirtualPath", "querystring", sw);
Assert.AreEqual ("/appVirtualDir", swr.GetAppPath (), "S1");
Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetFilePath (), "S2");
Assert.AreEqual ("GET", swr.GetHttpVerbName (), "S3");
Assert.AreEqual ("HTTP/1.0", swr.GetHttpVersion (), "S4");
Assert.AreEqual ("127.0.0.1", swr.GetLocalAddress (), "S5");
Assert.AreEqual (80, swr.GetLocalPort (), "S6");
Assert.AreEqual ("querystring", swr.GetQueryString (), "S7");
Assert.AreEqual ("127.0.0.1", swr.GetRemoteAddress (), "S8");
Assert.AreEqual (0, swr.GetRemotePort (), "S9");
Assert.AreEqual ("/appVirtualDir/pageVirtualPath?querystring", swr.GetRawUrl (), "S10");
Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetUriPath (), "S11");
Assert.AreEqual ("0", swr.GetUserToken ().ToString (), "S12");
Assert.AreEqual (null, swr.MapPath ("x"), "S13");
Assert.AreEqual (null, swr.MachineConfigPath, "S14");
Assert.AreEqual (null, swr.MachineInstallDirectory, "S15");
Assert.AreEqual (Path.Combine (cwd, "pageVirtualPath"), swr.GetFilePathTranslated (), "S16");
Assert.AreEqual ("", swr.GetServerVariable ("AUTH_TYPE"), "S18");
Assert.AreEqual ("", swr.GetServerVariable ("AUTH_USER"), "S19");
Assert.AreEqual ("", swr.GetServerVariable ("REMOTE_USER"), "S20");
Assert.AreEqual ("", swr.GetServerVariable ("SERVER_SOFTWARE"), "S21");
Assert.AreEqual ("/appVirtualDir/pageVirtualPath", swr.GetUriPath (), "S22");
//
// MapPath
//
Assert.AreEqual (null, swr.MapPath ("file.aspx"), "MP1");
Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath"), "MP2");
Assert.AreEqual (null, swr.MapPath ("appVirtualDir/pageVirtualPath"), "MP3");
Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath/page.aspx"), "MP4");
Assert.AreEqual (null, swr.MapPath ("/appVirtualDir/pageVirtualPath/Subdir"), "MP5");
swr = new SimpleWorkerRequest ("/appDir", cwd, "/Something/page.aspx", "querystring", sw);
//Assert.AreEqual ("c:\\tmp\\page.aspx", swr.GetFilePathTranslated (), "S17");
//
// GetUriPath tests, veredict: MS implementation is a bit fragile on this interface
//
swr = new SimpleWorkerRequest ("/appDir", cwd, "/page.aspx", null, sw);
Assert.AreEqual ("/appDir//page.aspx", swr.GetUriPath (), "S23");
swr = new SimpleWorkerRequest ("/appDir/", cwd, "/page.aspx", null, sw);
Assert.AreEqual ("/appDir///page.aspx", swr.GetUriPath (), "S24");
swr = new SimpleWorkerRequest ("/appDir/", cwd, "page.aspx", null, sw);
Assert.AreEqual ("/appDir//page.aspx", swr.GetUriPath (), "S25");
swr = new SimpleWorkerRequest ("/appDir", cwd, "page.aspx", null, sw);
Assert.AreEqual ("/appDir/page.aspx", swr.GetUriPath (), "S26");
}
[Test]
public void GetPathInfo ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest ("appVirtualDir", cwd, "/pageVirtualPath", "querystring", sw);
Assert.AreEqual ("/pageVirtualPath", swr.GetPathInfo (), "GetPathInfo-1");
swr = new SimpleWorkerRequest ("appVirtualDir", cwd, "/", "querystring", sw);
Assert.AreEqual ("/", swr.GetPathInfo (), "GetPathInfo-2");
swr = new SimpleWorkerRequest ("appVirtualDir", cwd, "pageVirtualPath", "querystring", sw);
Assert.AreEqual (String.Empty, swr.GetPathInfo (), "GetPathInfo-3");
}
[Test]
public void GetUriPath ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest ("/", cwd, String.Empty, String.Empty, sw);
Assert.AreEqual ("/", swr.GetUriPath (), "GetUriPath");
swr = new SimpleWorkerRequest (String.Empty, cwd, String.Empty, String.Empty, sw);
Assert.AreEqual ("/", swr.GetUriPath (), "GetUriPath-2");
swr = new SimpleWorkerRequest (String.Empty, cwd, "/", String.Empty, sw);
Assert.AreEqual ("//", swr.GetUriPath (), "GetUriPath-3");
swr = new SimpleWorkerRequest ("/", cwd, "/", String.Empty, sw);
Assert.AreEqual ("//", swr.GetUriPath (), "GetUriPath-4");
swr = new SimpleWorkerRequest ("virtual", cwd, "/", String.Empty, sw);
Assert.AreEqual ("virtual//", swr.GetUriPath (), "GetUriPath-5");
swr = new SimpleWorkerRequest ("/virtual", cwd, "/", String.Empty, sw);
Assert.AreEqual ("/virtual//", swr.GetUriPath (), "GetUriPath-6");
swr = new SimpleWorkerRequest ("/virtual/", cwd, "/", String.Empty, sw);
Assert.AreEqual ("/virtual///", swr.GetUriPath (), "GetUriPath-7");
swr = new SimpleWorkerRequest ("virtual", cwd, "page", String.Empty, sw);
Assert.AreEqual ("virtual/page", swr.GetUriPath (), "GetUriPath-8");
swr = new SimpleWorkerRequest ("/virtual", cwd, "page", String.Empty, sw);
Assert.AreEqual ("/virtual/page", swr.GetUriPath (), "GetUriPath-9");
swr = new SimpleWorkerRequest ("/virtual/", cwd, "page", String.Empty, sw);
Assert.AreEqual ("/virtual//page", swr.GetUriPath (), "GetUriPath-a");
}
public class Host : MarshalByRefObject {
string cwd = Environment.CurrentDirectory;
public void Demo ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);
Assert.AreEqual ("/appVirtualDir", swr.GetAppPath (), "T1");
Assert.AreEqual (cwd + Path.DirectorySeparatorChar, swr.GetAppPathTranslated (), "TRANS1");
Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetFilePath (), "T2");
Assert.AreEqual ("GET", swr.GetHttpVerbName (), "T3");
Assert.AreEqual ("HTTP/1.0", swr.GetHttpVersion (), "T4");
Assert.AreEqual ("127.0.0.1", swr.GetLocalAddress (), "T5");
Assert.AreEqual (80, swr.GetLocalPort (), "T6");
Assert.AreEqual ("querystring", swr.GetQueryString (), "T7");
Assert.AreEqual ("127.0.0.1", swr.GetRemoteAddress (), "T8");
Assert.AreEqual (0, swr.GetRemotePort (), "T9");
Assert.AreEqual ("/appVirtualDir/file.aspx?querystring", swr.GetRawUrl (), "T10");
Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetUriPath (), "T11");
Assert.AreEqual ("0", swr.GetUserToken ().ToString (), "T12");
Assert.AreEqual ("", swr.GetPathInfo (), "TRANS2");
//
// On windows:
// \windows\microsoft.net\framework\v1.1.4322\Config\machine.config
//
Assert.AreEqual (true, swr.MachineConfigPath != null, "T14");
//
// On windows:
// \windows\microsoft.net\framework\v1.1.4322
//
Assert.AreEqual (true, swr.MachineInstallDirectory != null, "T15");
// Disabled T16. It throws a nullref on MS
// Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.GetFilePathTranslated (), "T16");
//
Assert.AreEqual ("", swr.GetServerVariable ("AUTH_TYPE"), "T18");
Assert.AreEqual ("", swr.GetServerVariable ("AUTH_USER"), "T19");
Assert.AreEqual ("", swr.GetServerVariable ("REMOTE_USER"), "T20");
Assert.AreEqual ("", swr.GetServerVariable ("TERVER_SOFTWARE"), "T21");
Assert.AreEqual ("/appVirtualDir/file.aspx", swr.GetUriPath (), "T22");
//
// MapPath
//
Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.MapPath ("/appVirtualDir/file.aspx"), "TP2");
Assert.AreEqual (Path.Combine (cwd, "file.aspx"), swr.MapPath ("/appVirtualDir/file.aspx"), "TP4");
Assert.AreEqual (Path.Combine (cwd, Path.Combine ("Subdir", "file.aspx")), swr.MapPath ("/appVirtualDir/Subdir/file.aspx"), "TP5");
}
public void Exception1 ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);
swr.MapPath ("x");
}
public void Exception2 ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);
swr.MapPath ("file.aspx");
}
public void Exception3 ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);
swr.MapPath ("appVirtualDir/file.aspx");
}
public void MapPathOnEmptyVirtualDir ()
{
StringWriter sw = new StringWriter ();
SimpleWorkerRequest swr = new SimpleWorkerRequest("file.aspx", "querystring", sw);
swr.MapPath ("/");
}
}
Host MakeHost (string virtualDir)
{
return (Host) ApplicationHost.CreateApplicationHost (typeof (Host), virtualDir, cwd);
}
Host MakeHost ()
{
return MakeHost ("/appVirtualDir");
}
[Test] public void AppDomainTests ()
{
Host h = MakeHost ();
h.Demo ();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AppDomain_MapPath1 ()
{
Host h = MakeHost ();
h.Exception1 ();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AppDomain_MapPath2 ()
{
Host h = MakeHost ();
h.Exception2 ();
}
[Test]
[ExpectedException(typeof(ArgumentNullException))]
public void AppDomain_MapPath3 ()
{
Host h = MakeHost ();
h.Exception3 ();
}
[Test]
public void AppDomain_MapPath4 ()
{
Host h = MakeHost ("/");
h.MapPathOnEmptyVirtualDir ();
}
//
// This tests the constructor when the target application domain is created with
// CreateApplicationHost
//
[Test]
public void ConstructorTest_CreateApplicationHost ()
{
// Does not work without a NRE, need to call CreateApplicationHost.
// = new SimpleWorkerRequest ("pageVirtualPath", "querystring", sw);
// Assert.AreEqual ("querystring", swr.GetQueryString ());
}
[Test]
public void PathInfos ()
{
SimpleWorkerRequest wr = new SimpleWorkerRequest ("/appDir", "", "page.aspx/pathinfo", "", null);
HttpContext c = new HttpContext (wr);
Assert.AreEqual ("http://127.0.0.1/appDir/page.aspx/pathinfo", c.Request.Url.AbsoluteUri);
Assert.AreEqual ("/appDir/page.aspx", c.Request.FilePath);
Assert.AreEqual ("/appDir/page.aspx/pathinfo", c.Request.Path);
Assert.AreEqual ("/pathinfo", c.Request.PathInfo);
}
}
}

View File

@@ -0,0 +1,184 @@
//
// System.Web.Hosting.VirtualPathProviderTest
//
// Author:
// Gonzalo Paniagua Javier (gonzalo@ximian.com)
//
//
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
#if NET_2_0
using System;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Caching;
using System.Web.Hosting;
using NUnit.Framework;
namespace MonoTests.System.Web.Hosting {
class DummyVPP : VirtualPathProvider {
public override bool FileExists (string virtualPath)
{
bool de = base.FileExists (virtualPath);
return de;
}
public override bool DirectoryExists (string virtualDir)
{
bool de = base.DirectoryExists (virtualDir);
return de;
}
public override VirtualFile GetFile (string virtualPath)
{
VirtualFile vf = base.GetFile (virtualPath);
return vf;
}
public override string GetFileHash (string virtualPath, IEnumerable dependencies)
{
return base.GetFileHash (virtualPath, dependencies);
}
public override VirtualDirectory GetDirectory (string virtualDir)
{
VirtualDirectory vd = base.GetDirectory (virtualDir);
return vd;
}
public override CacheDependency GetCacheDependency (string virtualPath,
IEnumerable virtualPathDependencies, DateTime utcStart)
{
CacheDependency cd = base.GetCacheDependency (virtualPath, virtualPathDependencies, utcStart);
return cd;
}
}
[TestFixture]
public class VirtualPathProviderTest {
// Unhosted tests: not running inside an ASP.NET appdomain.
// Some tests may yield different results when hosted. I'll add those later.
[Test]
public void FileExists1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsFalse (dummy.FileExists ("hola.aspx"));
}
[Test]
public void DirectoryExists1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsFalse (dummy.DirectoryExists ("hola"));
}
[Test]
public void GetFile1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetFile ("index.aspx"));
}
[Test]
public void GetFileHash1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetFileHash (null, null));
}
[Test]
public void GetFileHash2 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetFileHash ("something", null));
}
[Test]
public void GetDirectory1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetDirectory ("some_directory"));
}
[Test]
public void GetCacheDependency1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetCacheDependency (null, null, DateTime.UtcNow));
}
[Test]
public void GetCacheKey1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.IsNull (dummy.GetCacheKey ("index.aspx"));
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void OpenFile1 ()
{
VirtualPathProvider.OpenFile ("index.aspx");
}
[Test]
public void CombineVirtualPaths1 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.AreEqual ("/otherroot", dummy.CombineVirtualPaths ("/root", "/otherroot"));
}
[Test]
public void CombineVirtualPaths2 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.AreEqual ("/otherleaf", dummy.CombineVirtualPaths ("/root", "otherleaf"));
}
[Test]
public void CombineVirtualPaths3 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "otherleaf/index.aspx"));
}
[Test]
[Category ("NotWorking")]
public void CombineVirtualPaths4 ()
{
DummyVPP dummy = new DummyVPP ();
Assert.AreEqual ("/otherleaf/index.aspx", dummy.CombineVirtualPaths ("/root", "./otherleaf/index.aspx"));
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CombineVirtualPaths5 ()
{
DummyVPP dummy = new DummyVPP ();
dummy.CombineVirtualPaths ("root", "./otherleaf/index.aspx");
}
}
}
#endif