1 // 2 // HttpExceptionCas.cs - CAS unit tests for System.Web.HttpException 3 // 4 // Author: 5 // Sebastien Pouliot <sebastien@ximian.com> 6 // 7 // Copyright (C) 2005 Novell, Inc (http://www.novell.com) 8 // 9 // Permission is hereby granted, free of charge, to any person obtaining 10 // a copy of this software and associated documentation files (the 11 // "Software"), to deal in the Software without restriction, including 12 // without limitation the rights to use, copy, modify, merge, publish, 13 // distribute, sublicense, and/or sell copies of the Software, and to 14 // permit persons to whom the Software is furnished to do so, subject to 15 // the following conditions: 16 // 17 // The above copyright notice and this permission notice shall be 18 // included in all copies or substantial portions of the Software. 19 // 20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 // 28 29 using NUnit.Framework; 30 31 using System; 32 using System.Runtime.Serialization; 33 using System.Security; 34 using System.Security.Permissions; 35 using System.Web; 36 37 namespace MonoCasTests.System.Web { 38 39 [TestFixture] 40 [Category ("CAS")] 41 public class HttpExceptionCas : AspNetHostingMinimal { 42 43 private HttpException he; 44 45 [TestFixtureSetUp] FixtureSetUp()46 public void FixtureSetUp () 47 { 48 he = new HttpException (); 49 } 50 51 [Test] 52 [PermissionSet (SecurityAction.Deny, Unrestricted = true)] CreateFromLastError()53 public void CreateFromLastError () 54 { 55 Assert.IsNotNull (HttpException.CreateFromLastError ("mono")); 56 } 57 58 [Test] 59 [PermissionSet (SecurityAction.Deny, Unrestricted = true)] Constructor0_Deny_Unrestricted()60 public void Constructor0_Deny_Unrestricted () 61 { 62 HttpException e = new HttpException (); 63 e.GetHtmlErrorMessage (); // null for ms, non-null for mono 64 Assert.AreEqual (500, e.GetHttpCode (), "HttpCode"); 65 } 66 67 [Test] 68 [PermissionSet (SecurityAction.Deny, Unrestricted = true)] Constructor1_Deny_Unrestricted()69 public void Constructor1_Deny_Unrestricted () 70 { 71 HttpException e = new HttpException ("message"); 72 e.GetHtmlErrorMessage (); // null for ms, non-null for mono 73 Assert.AreEqual (500, e.GetHttpCode (), "HttpCode"); 74 } 75 76 [Test] 77 [PermissionSet (SecurityAction.Deny, Unrestricted = true)] Constructor2a_Deny_Unrestricted()78 public void Constructor2a_Deny_Unrestricted () 79 { 80 HttpException e = new HttpException (501, "message"); 81 e.GetHtmlErrorMessage (); // null for ms, non-null for mono 82 Assert.AreEqual (501, e.GetHttpCode (), "HttpCode"); 83 } 84 85 [Test] 86 [PermissionSet (SecurityAction.Deny, Unrestricted = true)] Constructor2b_Deny_Unrestricted()87 public void Constructor2b_Deny_Unrestricted () 88 { 89 HttpException e = new HttpException ("message", new Exception ()); 90 e.GetHtmlErrorMessage (); // null for ms, non-null for mono 91 Assert.AreEqual (500, e.GetHttpCode (), "HttpCode"); 92 } 93 [Test] 94 [SecurityPermission (SecurityAction.Deny, SerializationFormatter = true)] 95 [ExpectedException (typeof (SecurityException))] GetObjectData_Deny_SerializationFormatter()96 public void GetObjectData_Deny_SerializationFormatter () 97 { 98 he.GetObjectData (null, new StreamingContext ()); 99 } 100 101 [Test] 102 [SecurityPermission (SecurityAction.PermitOnly, SerializationFormatter = true)] 103 [ExpectedException (typeof (ArgumentNullException))] GetObjectData_PermitOnly_SerializationFormatter()104 public void GetObjectData_PermitOnly_SerializationFormatter () 105 { 106 he.GetObjectData (null, new StreamingContext ()); 107 } 108 // LinkDemand 109 110 public override Type Type { 111 get { return typeof (HttpException); } 112 } 113 } 114 } 115