Xamarin Public Jenkins (auto-signing) e79aa3c0ed Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
2016-08-03 10:59:49 +00:00

96 lines
2.1 KiB
C#

//
// CodeAccessPermissionTest.cs - NUnit Test Cases for CodeAccessPermission
//
// Author:
// Sebastien Pouliot (spouliot@motus.com)
//
// (C) 2004 Motus Technologies Inc. (http://www.motus.com)
//
#if FEATURE_MONO_CAS
using NUnit.Framework;
using System;
using System.Security;
using System.Security.Permissions;
using System.Text;
namespace MonoTests.System.Security {
// Almost minimal CAS class for unit tests
[Serializable]
public class NonAbstractCodeAccessPermission : CodeAccessPermission {
private string _tag;
private string _text;
public NonAbstractCodeAccessPermission (string tag, string text)
{
_tag = tag;
_text = text;
}
public override IPermission Copy ()
{
return new NonAbstractCodeAccessPermission (_tag, _text);
}
public override void FromXml (SecurityElement elem) {}
public override IPermission Intersect (IPermission target)
{
return null;
}
public override bool IsSubsetOf (IPermission target)
{
return true;
}
public override SecurityElement ToXml ()
{
if (_tag == null)
return null;
return new SecurityElement (_tag, _text);
}
}
[TestFixture]
[Category ("CAS")]
public class CodeAccessPermissionTest {
[Test]
public void CustomCAS ()
{
// test for http://bugzilla.ximian.com/show_bug.cgi?id=52626
NonAbstractCodeAccessPermission p = new NonAbstractCodeAccessPermission ("custom", null);
p.Demand ();
}
[Test]
public void Union ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission (null, null);
IPermission p = cap.Union (null);
}
[Test]
[ExpectedException (typeof (NullReferenceException))]
public void To_String_Exception ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission (null, null);
string s = cap.ToString ();
}
[Test]
public void To_String ()
{
NonAbstractCodeAccessPermission cap = new NonAbstractCodeAccessPermission ("CodeAccessPermission", "NonAbstract");
string s = cap.ToString ();
Assert.AreEqual ("<CodeAccessPermission>NonAbstract</CodeAccessPermission>" + Environment.NewLine, s, "ToString");
}
}
}
#endif