AssemblyTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. //
  2. // System.Reflection.Assembly Test Cases
  3. //
  4. // Authors:
  5. // Gonzalo Paniagua Javier ([email protected])
  6. // Philippe Lavoie ([email protected])
  7. // Sebastien Pouliot ([email protected])
  8. //
  9. // (c) 2003 Ximian, Inc. (http://www.ximian.com)
  10. // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
  11. //
  12. // Permission is hereby granted, free of charge, to any person obtaining
  13. // a copy of this software and associated documentation files (the
  14. // "Software"), to deal in the Software without restriction, including
  15. // without limitation the rights to use, copy, modify, merge, publish,
  16. // distribute, sublicense, and/or sell copies of the Software, and to
  17. // permit persons to whom the Software is furnished to do so, subject to
  18. // the following conditions:
  19. //
  20. // The above copyright notice and this permission notice shall be
  21. // included in all copies or substantial portions of the Software.
  22. //
  23. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  27. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  28. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  29. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  30. //
  31. using NUnit.Framework;
  32. using System;
  33. using System.Configuration.Assemblies;
  34. using System.Globalization;
  35. using System.IO;
  36. using System.Reflection;
  37. using System.Reflection.Emit;
  38. using System.Runtime.Serialization;
  39. using System.Security;
  40. namespace MonoTests.System.Reflection
  41. {
  42. [TestFixture]
  43. public class AssemblyTest
  44. {
  45. [Test]
  46. public void CreateInstance()
  47. {
  48. Type type = typeof (AssemblyTest);
  49. Object obj = type.Assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
  50. Assert.IsNotNull (obj, "#01");
  51. Assert.AreEqual (GetType (), obj.GetType (), "#02");
  52. }
  53. [Test]
  54. public void CreateInvalidInstance()
  55. {
  56. Type type = typeof (AssemblyTest);
  57. Object obj = type.Assembly.CreateInstance("NunitTests.ThisTypeDoesNotExist");
  58. Assert.IsNull (obj, "#03");
  59. }
  60. [Test]
  61. #if NET_2_0
  62. [Category ("NotWorking")]
  63. [ExpectedException (typeof (ArgumentException))]
  64. #else
  65. [ExpectedException (typeof (TypeLoadException))]
  66. #endif
  67. public void TestGetType ()
  68. {
  69. // Bug #49114
  70. typeof (int).Assembly.GetType ("&blabla", true, true);
  71. }
  72. [Test]
  73. public void GetEntryAssembly ()
  74. {
  75. // note: only available in default appdomain
  76. // http://weblogs.asp.net/asanto/archive/2003/09/08/26710.aspx
  77. // Not sure we should emulate this behavior.
  78. string fname = AppDomain.CurrentDomain.FriendlyName;
  79. if (fname.EndsWith (".dll")) { // nunit-console
  80. Assert.IsNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
  81. #if NET_2_0
  82. Assert.IsFalse (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
  83. #endif
  84. } else { // gnunit
  85. Assert.IsNotNull (Assembly.GetEntryAssembly (), "GetEntryAssembly");
  86. #if NET_2_0
  87. Assert.IsTrue (AppDomain.CurrentDomain.IsDefaultAppDomain (), "!default appdomain");
  88. #endif
  89. }
  90. }
  91. #if NET_2_0
  92. [Category ("NotWorking")]
  93. #endif
  94. [Test]
  95. public void Corlib ()
  96. {
  97. Assembly corlib = typeof (int).Assembly;
  98. Assert.IsTrue (corlib.CodeBase.EndsWith ("mscorlib.dll"), "CodeBase");
  99. Assert.IsNull (corlib.EntryPoint, "EntryPoint");
  100. Assert.IsTrue (corlib.EscapedCodeBase.EndsWith ("mscorlib.dll"), "EscapedCodeBase");
  101. Assert.IsNotNull (corlib.Evidence, "Evidence");
  102. Assert.IsTrue (corlib.Location.EndsWith ("mscorlib.dll"), "Location");
  103. // corlib doesn't reference anything
  104. Assert.AreEqual (0, corlib.GetReferencedAssemblies ().Length, "GetReferencedAssemblies");
  105. #if NET_2_0
  106. Assert.AreEqual ("mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", corlib.FullName, "FullName");
  107. // not really "true" but it's even more trusted so...
  108. Assert.IsTrue (corlib.GlobalAssemblyCache, "GlobalAssemblyCache");
  109. Assert.AreEqual (0, corlib.HostContext, "HostContext");
  110. Assert.AreEqual ("v2.0.50727", corlib.ImageRuntimeVersion, "ImageRuntimeVersion");
  111. Assert.IsFalse (corlib.ReflectionOnly, "ReflectionOnly");
  112. Assert.AreEqual (0x1, corlib.ManifestModule.MetadataToken);
  113. #elif NET_1_1
  114. Assert.IsFalse (corlib.GlobalAssemblyCache, "GlobalAssemblyCache");
  115. Assert.AreEqual ("mscorlib, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", corlib.FullName, "FullName");
  116. Assert.AreEqual ("v1.1.4322", corlib.ImageRuntimeVersion, "ImageRuntimeVersion");
  117. #endif
  118. }
  119. [Test]
  120. public void Corlib_test ()
  121. {
  122. Assembly corlib_test = Assembly.GetExecutingAssembly ();
  123. Assert.IsNull (corlib_test.EntryPoint, "EntryPoint");
  124. Assert.IsNotNull (corlib_test.Evidence, "Evidence");
  125. Assert.IsFalse (corlib_test.GlobalAssemblyCache, "GlobalAssemblyCache");
  126. Assert.IsTrue (corlib_test.GetReferencedAssemblies ().Length > 0, "GetReferencedAssemblies");
  127. #if NET_2_0
  128. Assert.AreEqual (0, corlib_test.HostContext, "HostContext");
  129. Assert.AreEqual ("v2.0.50727", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
  130. Assert.IsNotNull (corlib_test.ManifestModule, "ManifestModule");
  131. Assert.IsFalse (corlib_test.ReflectionOnly, "ReflectionOnly");
  132. #elif NET_1_1
  133. Assert.AreEqual ("v1.1.4322", corlib_test.ImageRuntimeVersion, "ImageRuntimeVersion");
  134. #endif
  135. }
  136. [Test]
  137. public void GetAssembly ()
  138. {
  139. Assert.IsTrue (Assembly.GetAssembly (typeof (int)).FullName.StartsWith ("mscorlib"), "GetAssembly(int)");
  140. Assert.AreEqual (this.GetType ().Assembly.FullName, Assembly.GetAssembly (this.GetType ()).FullName, "GetAssembly(this)");
  141. }
  142. [Test]
  143. [ExpectedException (typeof (ArgumentNullException))]
  144. public void GetFile_Null ()
  145. {
  146. Assembly.GetExecutingAssembly ().GetFile (null);
  147. }
  148. [Test]
  149. [ExpectedException (typeof (ArgumentException))]
  150. public void GetFile_Empty ()
  151. {
  152. Assembly.GetExecutingAssembly ().GetFile (String.Empty);
  153. }
  154. [Test]
  155. public void GetFiles_False ()
  156. {
  157. Assembly corlib = typeof (int).Assembly;
  158. FileStream[] fss = corlib.GetFiles ();
  159. Assert.AreEqual (fss.Length, corlib.GetFiles (false).Length, "corlib.GetFiles (false)");
  160. Assembly corlib_test = Assembly.GetExecutingAssembly ();
  161. fss = corlib_test.GetFiles ();
  162. Assert.AreEqual (fss.Length, corlib_test.GetFiles (false).Length, "test.GetFiles (false)");
  163. }
  164. [Test]
  165. public void GetFiles_True ()
  166. {
  167. Assembly corlib = typeof (int).Assembly;
  168. FileStream[] fss = corlib.GetFiles ();
  169. Assert.IsTrue (fss.Length <= corlib.GetFiles (true).Length, "corlib.GetFiles (true)");
  170. Assembly corlib_test = Assembly.GetExecutingAssembly ();
  171. fss = corlib_test.GetFiles ();
  172. Assert.IsTrue (fss.Length <= corlib_test.GetFiles (true).Length, "test.GetFiles (true)");
  173. }
  174. [Test] // bug #78517
  175. #if ONLY_1_1
  176. [Category ("NotDotNet")] // MS.NET 1.x throws FileLoadException
  177. #endif
  178. public void LoadFrom_Empty_Assembly ()
  179. {
  180. string tempFile = Path.GetTempFileName ();
  181. try {
  182. Assembly.LoadFrom (tempFile);
  183. Assert.Fail ("#1");
  184. } catch (BadImageFormatException ex) {
  185. Assert.IsNull (ex.InnerException, "#2");
  186. } finally {
  187. File.Delete (tempFile);
  188. }
  189. }
  190. [Test] // bug #78517
  191. public void LoadFrom_Invalid_Assembly ()
  192. {
  193. string tempFile = Path.GetTempFileName ();
  194. using (StreamWriter sw = File.CreateText (tempFile)) {
  195. sw.WriteLine ("foo");
  196. sw.Close ();
  197. }
  198. try {
  199. Assembly.LoadFrom (tempFile);
  200. Assert.Fail ("#1");
  201. } catch (BadImageFormatException ex) {
  202. Assert.IsNull (ex.InnerException, "#2");
  203. } finally {
  204. File.Delete (tempFile);
  205. }
  206. }
  207. [Test]
  208. public void LoadFrom_NonExisting_Assembly ()
  209. {
  210. string tempFile = Path.GetTempFileName ();
  211. File.Delete (tempFile);
  212. try {
  213. Assembly.LoadFrom (tempFile);
  214. Assert.Fail ("#1");
  215. } catch (FileNotFoundException ex) {
  216. Assert.IsNull (ex.InnerException, "#2");
  217. } finally {
  218. File.Delete (tempFile);
  219. }
  220. }
  221. [Test]
  222. public void LoadWithPartialName ()
  223. {
  224. string [] names = { "corlib_test_default", "corlib_test_net_2_0", "corlib_plattest" };
  225. foreach (string s in names)
  226. if (Assembly.LoadWithPartialName (s) != null)
  227. return;
  228. Assertion.Fail ("Was not able to load any corlib test");
  229. }
  230. [Test]
  231. [ExpectedException (typeof (ArgumentNullException))]
  232. public void GetObjectData_Null ()
  233. {
  234. Assembly corlib = typeof (int).Assembly;
  235. corlib.GetObjectData (null, new StreamingContext (StreamingContextStates.All));
  236. }
  237. [Test]
  238. public void GetReferencedAssemblies ()
  239. {
  240. Assembly corlib_test = Assembly.GetExecutingAssembly ();
  241. AssemblyName[] names = corlib_test.GetReferencedAssemblies ();
  242. foreach (AssemblyName an in names) {
  243. Assert.IsNull (an.CodeBase, "CodeBase");
  244. Assert.IsNotNull (an.CultureInfo, "CultureInfo");
  245. Assert.IsNull (an.EscapedCodeBase, "EscapedCodeBase");
  246. Assert.AreEqual (AssemblyNameFlags.None, an.Flags, "Flags");
  247. Assert.IsNotNull (an.FullName, "FullName");
  248. Assert.AreEqual (AssemblyHashAlgorithm.SHA1, an.HashAlgorithm, "HashAlgorithm");
  249. Assert.IsNull (an.KeyPair, "KeyPair");
  250. Assert.IsNotNull (an.Name, "Name");
  251. Assert.IsNotNull (an.Version, "Version");
  252. Assert.AreEqual (AssemblyVersionCompatibility.SameMachine,
  253. an.VersionCompatibility, "VersionCompatibility");
  254. }
  255. }
  256. [Test]
  257. public void Location_Empty() {
  258. string assemblyFileName = Path.Combine (
  259. Path.GetTempPath (), "AssemblyLocation.dll");
  260. try {
  261. AssemblyName assemblyName = new AssemblyName ();
  262. assemblyName.Name = "AssemblyLocation";
  263. AssemblyBuilder ab = AppDomain.CurrentDomain
  264. .DefineDynamicAssembly (assemblyName,
  265. AssemblyBuilderAccess.Save,
  266. Path.GetTempPath (),
  267. AppDomain.CurrentDomain.Evidence);
  268. ab.Save (Path.GetFileName (assemblyFileName));
  269. using (FileStream fs = File.OpenRead (assemblyFileName)) {
  270. byte[] buffer = new byte[fs.Length];
  271. fs.Read (buffer, 0, buffer.Length);
  272. Assembly assembly = Assembly.Load (buffer);
  273. Assert.AreEqual (string.Empty, assembly.Location);
  274. fs.Close ();
  275. }
  276. } finally {
  277. File.Delete (assemblyFileName);
  278. }
  279. }
  280. [Test]
  281. [Category ("NotWorking")]
  282. public void bug78464 ()
  283. {
  284. string assemblyFileName = Path.Combine (
  285. Path.GetTempPath (), "bug78464.dll");
  286. try {
  287. // execute test in separate appdomain to allow assembly to be unloaded
  288. AppDomain testDomain = CreateTestDomain ();
  289. CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
  290. try {
  291. crossDomainTester.bug78464 (assemblyFileName);
  292. } finally {
  293. AppDomain.Unload (testDomain);
  294. }
  295. } finally {
  296. File.Delete (assemblyFileName);
  297. }
  298. }
  299. [Test]
  300. [Category ("NotWorking")]
  301. public void bug78465 ()
  302. {
  303. string assemblyFileName = Path.Combine (
  304. Path.GetTempPath (), "bug78465.dll");
  305. try {
  306. AssemblyName assemblyName = new AssemblyName ();
  307. assemblyName.Name = "bug78465";
  308. AssemblyBuilder ab = AppDomain.CurrentDomain
  309. .DefineDynamicAssembly (assemblyName,
  310. AssemblyBuilderAccess.Save,
  311. Path.GetDirectoryName (assemblyFileName),
  312. AppDomain.CurrentDomain.Evidence);
  313. ab.Save (Path.GetFileName (assemblyFileName));
  314. using (FileStream fs = File.OpenRead (assemblyFileName)) {
  315. byte[] buffer = new byte[fs.Length];
  316. fs.Read (buffer, 0, buffer.Length);
  317. Assembly assembly = Assembly.Load (buffer);
  318. Assert.AreEqual (string.Empty, assembly.Location, "#1");
  319. fs.Close ();
  320. }
  321. AppDomain testDomain = CreateTestDomain ();
  322. CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
  323. try {
  324. crossDomainTester.bug78465 (assemblyFileName);
  325. } finally {
  326. AppDomain.Unload (testDomain);
  327. }
  328. } finally {
  329. File.Delete (assemblyFileName);
  330. }
  331. }
  332. [Test]
  333. [Category ("NotWorking")]
  334. public void bug78468 ()
  335. {
  336. string assemblyFileNameA = Path.Combine (Path.GetTempPath (),
  337. "bug78468a.dll");
  338. string resourceFileName = Path.Combine (Path.GetTempPath (),
  339. "readme.txt");
  340. using (StreamWriter sw = File.CreateText (resourceFileName)) {
  341. sw.WriteLine ("FOO");
  342. sw.Close ();
  343. }
  344. try {
  345. AssemblyName assemblyName = new AssemblyName ();
  346. assemblyName.Name = "bug78468a";
  347. AssemblyBuilder ab = AppDomain.CurrentDomain
  348. .DefineDynamicAssembly (assemblyName,
  349. AssemblyBuilderAccess.Save,
  350. Path.GetTempPath (),
  351. AppDomain.CurrentDomain.Evidence);
  352. ab.AddResourceFile ("read", "readme.txt");
  353. ab.Save (Path.GetFileName (assemblyFileNameA));
  354. Assembly assembly;
  355. using (FileStream fs = File.OpenRead (assemblyFileNameA)) {
  356. byte[] buffer = new byte[fs.Length];
  357. fs.Read (buffer, 0, buffer.Length);
  358. assembly = Assembly.Load (buffer);
  359. fs.Close ();
  360. }
  361. Assert.AreEqual (string.Empty, assembly.Location, "#A1");
  362. string[] resNames = assembly.GetManifestResourceNames ();
  363. Assert.IsNotNull (resNames, "#A2");
  364. Assert.AreEqual (1, resNames.Length, "#A3");
  365. Assert.AreEqual ("read", resNames[0], "#A4");
  366. ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
  367. Assert.IsNotNull (resInfo, "#A5");
  368. Assert.AreEqual ("readme.txt", resInfo.FileName, "#A6");
  369. Assert.IsNull (resInfo.ReferencedAssembly, "#A7");
  370. Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#A8");
  371. Assert.IsNull (assembly.GetManifestResourceStream ("read"), "#A9");
  372. try {
  373. assembly.GetFile ("readme.txt");
  374. Assert.Fail ("#A10");
  375. } catch (FileNotFoundException) {
  376. }
  377. string assemblyFileNameB = Path.Combine (Path.GetTempPath (),
  378. "bug78468b.dll");
  379. AppDomain testDomain = CreateTestDomain ();
  380. CrossDomainTester crossDomainTester = CreateCrossDomainTester (testDomain);
  381. try {
  382. crossDomainTester.bug78468 (assemblyFileNameB);
  383. } finally {
  384. AppDomain.Unload (testDomain);
  385. File.Delete (assemblyFileNameB);
  386. }
  387. } finally {
  388. File.Delete (assemblyFileNameA);
  389. File.Delete (resourceFileName);
  390. }
  391. }
  392. #if NET_2_0
  393. [Test]
  394. [Category ("NotWorking")]
  395. public void ReflectionOnlyLoad ()
  396. {
  397. Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
  398. Assert.IsNotNull (assembly);
  399. Assert.IsTrue (assembly.ReflectionOnly);
  400. }
  401. [Test]
  402. public void ReflectionOnlyLoadFrom ()
  403. {
  404. string loc = typeof (AssemblyTest).Assembly.Location;
  405. string filename = Path.GetFileName (loc);
  406. Assembly assembly = Assembly.ReflectionOnlyLoadFrom (filename);
  407. Assert.IsNotNull (assembly);
  408. Assert.IsTrue (assembly.ReflectionOnly);
  409. }
  410. [Test]
  411. [ExpectedException (typeof (ArgumentException))]
  412. public void CreateInstanceOnRefOnly ()
  413. {
  414. Assembly assembly = Assembly.ReflectionOnlyLoad (typeof (AssemblyTest).Assembly.FullName);
  415. assembly.CreateInstance ("MonoTests.System.Reflection.AssemblyTest");
  416. }
  417. #endif
  418. private static AppDomain CreateTestDomain ()
  419. {
  420. return AppDomain.CreateDomain ("CompileFromDom", AppDomain.CurrentDomain.Evidence,
  421. AppDomain.CurrentDomain.SetupInformation);
  422. }
  423. private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
  424. {
  425. Type testerType = typeof (CrossDomainTester);
  426. return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
  427. testerType.Assembly.FullName, testerType.FullName, false,
  428. BindingFlags.Public | BindingFlags.Instance, null, new object[0],
  429. CultureInfo.InvariantCulture, new object[0], domain.Evidence);
  430. }
  431. private class CrossDomainTester : MarshalByRefObject
  432. {
  433. public void bug78464 (string assemblyFileName)
  434. {
  435. AssemblyName assemblyName = new AssemblyName ();
  436. assemblyName.Name = "bug78464";
  437. AssemblyBuilder ab = AppDomain.CurrentDomain
  438. .DefineDynamicAssembly (assemblyName,
  439. AssemblyBuilderAccess.Save,
  440. Path.GetDirectoryName (assemblyFileName),
  441. AppDomain.CurrentDomain.Evidence);
  442. ab.Save (Path.GetFileName (assemblyFileName));
  443. Assembly assembly;
  444. using (FileStream fs = File.OpenRead (assemblyFileName)) {
  445. byte[] buffer = new byte[fs.Length];
  446. fs.Read (buffer, 0, buffer.Length);
  447. assembly = Assembly.Load (buffer);
  448. fs.Close ();
  449. }
  450. Assert.AreEqual (string.Empty, assembly.Location, "#1");
  451. assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
  452. Assert.IsFalse (assembly.Location == string.Empty, "#2");
  453. Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName(assembly.Location), "#3");
  454. // note: we cannot check if directory names match, as MS.NET seems to
  455. // convert directory part of assembly location to lowercase
  456. Assert.IsFalse (Path.GetDirectoryName(assembly.Location) == string.Empty, "#4");
  457. }
  458. public void bug78465 (string assemblyFileName)
  459. {
  460. Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
  461. Assert.IsFalse (assembly.Location == string.Empty, "#2");
  462. Assert.AreEqual (Path.GetFileName (assemblyFileName), Path.GetFileName (assembly.Location), "#3");
  463. // note: we cannot check if directory names match, as MS.NET seems to
  464. // convert directory part of assembly location to lowercase
  465. Assert.IsFalse (Path.GetDirectoryName (assembly.Location) == string.Empty, "#4");
  466. }
  467. public void bug78468 (string assemblyFileName)
  468. {
  469. AssemblyName assemblyName = new AssemblyName ();
  470. assemblyName.Name = "bug78468b";
  471. AssemblyBuilder ab = AppDomain.CurrentDomain
  472. .DefineDynamicAssembly (assemblyName,
  473. AssemblyBuilderAccess.Save,
  474. Path.GetDirectoryName (assemblyFileName),
  475. AppDomain.CurrentDomain.Evidence);
  476. ab.AddResourceFile ("read", "readme.txt");
  477. ab.Save (Path.GetFileName (assemblyFileName));
  478. Assembly assembly = Assembly.LoadFrom (assemblyFileName, AppDomain.CurrentDomain.Evidence);
  479. Assert.IsTrue (assembly.Location != string.Empty, "#B1");
  480. string[] resNames = assembly.GetManifestResourceNames ();
  481. Assert.IsNotNull (resNames, "#B2");
  482. Assert.AreEqual (1, resNames.Length, "#B3");
  483. Assert.AreEqual ("read", resNames[0], "#B4");
  484. ManifestResourceInfo resInfo = assembly.GetManifestResourceInfo ("read");
  485. Assert.IsNotNull (resInfo, "#B5");
  486. Assert.AreEqual ("readme.txt", resInfo.FileName, "#B6");
  487. Assert.IsNull (resInfo.ReferencedAssembly, "#B7");
  488. Assert.AreEqual ((ResourceLocation) 0, resInfo.ResourceLocation, "#B8");
  489. Stream s = assembly.GetManifestResourceStream ("read");
  490. Assert.IsNotNull (s, "#B9");
  491. s.Close ();
  492. s = assembly.GetFile ("readme.txt");
  493. Assert.IsNotNull (s, "#B10");
  494. s.Close ();
  495. }
  496. }
  497. }
  498. }