PageRenderTime 10ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rocks/Test/Mono.Cecil.Tests/SecurityDeclarationRocksTests.cs

http://github.com/jbevain/cecil
C# | 66 lines | 44 code | 22 blank | 0 comment | 0 complexity | fc222cb11021dbbd3a487264443cf703 MD5 | raw file
 1#if !NET_CORE
 2
 3using System.Security.Permissions;
 4
 5using NUnit.Framework;
 6
 7using Mono.Cecil.Rocks;
 8
 9namespace Mono.Cecil.Tests {
10
11	[TestFixture]
12	public class SecurityDeclarationRocksTests : BaseTestFixture {
13
14		[Test]
15		public void ToPermissionSetFromPermissionSetAttribute ()
16		{
17			TestModule ("decsec-xml.dll", module => {
18				var type = module.GetType ("SubLibrary");
19
20				Assert.IsTrue (type.HasSecurityDeclarations);
21				Assert.AreEqual (1, type.SecurityDeclarations.Count);
22
23				var declaration = type.SecurityDeclarations [0];
24
25				var permission_set = declaration.ToPermissionSet ();
26
27				Assert.IsNotNull (permission_set);
28
29				string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
30	+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
31	+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
32
33				permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
34
35				Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
36			});
37		}
38
39		[Test]
40		public void ToPermissionSetFromSecurityAttribute ()
41		{
42			TestModule ("decsec-att.dll", module => {
43				var type = module.GetType ("SubLibrary");
44
45				Assert.IsTrue (type.HasSecurityDeclarations);
46				Assert.AreEqual (1, type.SecurityDeclarations.Count);
47
48				var declaration = type.SecurityDeclarations [0];
49
50				var permission_set = declaration.ToPermissionSet ();
51
52				Assert.IsNotNull (permission_set);
53
54				string permission_set_value = "<PermissionSet class=\"System.Security.PermissionSe"
55	+ "t\"\r\nversion=\"1\">\r\n<IPermission class=\"{0}\"\r\nversion=\"1\"\r\nFla"
56	+ "gs=\"UnmanagedCode\"/>\r\n</PermissionSet>\r\n";
57
58				permission_set_value = string.Format (permission_set_value, typeof (SecurityPermission).AssemblyQualifiedName);
59
60				Assert.AreEqual (Normalize (permission_set_value), Normalize (permission_set.ToXml ().ToString ()));
61			});
62		}
63	}
64}
65
66#endif