PageRenderTime 8ms CodeModel.GetById 2ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/Test/Mono.Cecil.Tests/AssemblyTests.cs

http://github.com/jbevain/cecil
C# | 109 lines | 88 code | 20 blank | 1 comment | 2 complexity | be512f5d7ab8a361c4651d8603d204a5 MD5 | raw file
  1using System;
  2
  3using Mono.Cecil;
  4using Mono.Cecil.Cil;
  5
  6using NUnit.Framework;
  7
  8namespace Mono.Cecil.Tests {
  9
 10	[TestFixture]
 11	public class AssemblyTests : BaseTestFixture {
 12
 13		[Test]
 14		public void Name ()
 15		{
 16			TestModule ("hello.exe", module => {
 17				var name = module.Assembly.Name;
 18
 19				Assert.IsNotNull (name);
 20
 21				Assert.AreEqual ("hello", name.Name);
 22				Assert.AreEqual ("", name.Culture);
 23				Assert.AreEqual (new Version (0, 0, 0, 0), name.Version);
 24				Assert.AreEqual (AssemblyHashAlgorithm.SHA1, name.HashAlgorithm);
 25			});
 26		}
 27
 28		[Test]
 29		public void ParseLowerCaseNameParts ()
 30		{
 31			var name = AssemblyNameReference.Parse ("Foo, version=2.0.0.0, culture=fr-FR");
 32			Assert.AreEqual ("Foo", name.Name);
 33			Assert.AreEqual (2, name.Version.Major);
 34			Assert.AreEqual (0, name.Version.Minor);
 35			Assert.AreEqual ("fr-FR", name.Culture);
 36		}
 37
 38		[Test]
 39		public void ZeroVersion ()
 40		{
 41			var name = new AssemblyNameReference ("Foo", null);
 42			Assert.AreEqual ("0.0.0.0", name.Version.ToString (fieldCount: 4));
 43			Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
 44
 45			name = new AssemblyNameReference ("Foo", new Version (0, 0, 0, 0));
 46			Assert.AreEqual ("0.0.0.0", name.Version.ToString (fieldCount: 4));
 47			Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
 48		}
 49
 50		[Test]
 51		public void NoBuildOrMajor ()
 52		{
 53			var name = new AssemblyNameReference ("Foo", new Version (0, 0));
 54			Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
 55
 56			name = new AssemblyNameReference ("Foo", new Version (0, 0, 0));
 57			Assert.AreEqual ("Foo, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", name.FullName);
 58		}
 59
 60		[Test]
 61		public void Retargetable ()
 62		{
 63			if (Platform.OnCoreClr)
 64				return;
 65
 66			TestModule ("RetargetableExample.dll", module => {
 67				var type = module.Types [1];
 68				var property = type.Properties [0];
 69				var attribute = property.CustomAttributes [0];
 70
 71				var argumentType = ((CustomAttributeArgument) attribute.ConstructorArguments [0].Value).Type;
 72				var reference = (AssemblyNameReference) argumentType.Scope;
 73
 74				Assert.AreEqual (
 75					"System.Data, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac, Retargetable=Yes",
 76					reference.FullName);
 77			}, verify: !Platform.OnMono);
 78		}
 79
 80		[Test]
 81		public void SystemRuntime ()
 82		{
 83			if (Platform.OnCoreClr)
 84				return;
 85
 86			TestModule ("System.Runtime.dll", module => {
 87				Assert.AreEqual ("System.Runtime", module.Assembly.Name.Name);
 88				Assert.AreEqual (1, module.AssemblyReferences.Count);
 89				Assert.AreNotEqual (module, module.TypeSystem.CoreLibrary);
 90				Assert.AreEqual (module.AssemblyReferences [0], module.TypeSystem.CoreLibrary);
 91			}, verify: !Platform.OnMono);
 92		}
 93
 94		[Test]
 95		public void MismatchedLibraryAndSymbols ()
 96		{
 97			// SQLite-net.dll (from nuget) shiped with mismatched symbol files, but throwIfNoSymbol did not prevent it from throwing
 98			var parameters = new ReaderParameters {
 99				ReadSymbols = true,
100				SymbolReaderProvider = new DefaultSymbolReaderProvider (throwIfNoSymbol: false),
101				ThrowIfSymbolsAreNotMatching = false,
102			};
103
104			using (var module = GetResourceModule ("SQLite-net.dll", parameters)) {
105				Assert.Null (module.SymbolReader);
106			}
107		}
108	}
109}