f7586f551d0dab5f8315d286d274deb7ea667367
[mono.git] / mcs / class / System / Test / Microsoft.VisualBasic / VBCodeProviderTest.cs
1 //
2 // Microsoft.VisualBasic.VBCodeProvider.cs
3 //
4 // Author:
5 //   Jochen Wezel (jwezel@compumaster.de)
6 //
7 // (C) 2003 Jochen Wezel (CompuMaster GmbH)
8 //
9 // Last modifications:
10 // 2003-12-10 JW: publishing of this file
11 //
12
13 using System;
14 using System.CodeDom;
15 using System.CodeDom.Compiler;
16 using System.Collections.Specialized;
17 using System.Globalization;
18 using System.Reflection;
19 using System.Diagnostics;
20 using System.IO;
21 using System.Text;
22 using Microsoft.VisualBasic;
23 using NUnit.Framework;
24
25 namespace MonoTests.Microsoft.VisualBasic
26 {
27         enum OsType
28         {
29                 Windows,
30                 Unix,
31                 Mac
32         }
33
34         [TestFixture]
35         public class VBCodeProviderTest
36         {
37                 private string _tempDir;
38                 private CodeDomProvider _codeProvider;
39                 private static OsType OS;
40                 private static char DSC = Path.DirectorySeparatorChar;
41
42                 private static readonly string _sourceTest1 = "Public Class Test1" +
43                         Environment.NewLine + "End Class";
44                 private static readonly string _sourceTest2 = "Public Class Test2" +
45                         Environment.NewLine + "End Class";
46
47                 [SetUp]
48                 public void GetReady ()
49                 {
50                         if ('/' == DSC) {
51                                 OS = OsType.Unix;
52                         } else if ('\\' == DSC) {
53                                 OS = OsType.Windows;
54                         } else {
55                                 OS = OsType.Mac;
56                         }
57
58                         _codeProvider = new VBCodeProvider ();
59                         _tempDir = CreateTempDirectory ();
60                 }
61
62                 [TearDown]
63                 public void TearDown ()
64                 {
65                         RemoveDirectory (_tempDir);
66                 }
67
68                 [Test]
69                 public void FileExtension ()
70                 {
71                         Assert.AreEqual ("vb", _codeProvider.FileExtension, "#JW10");
72                 }
73
74                 [Test]
75                 public void LanguageOptionsTest ()
76                 {
77                         Assert.AreEqual (LanguageOptions.CaseInsensitive, _codeProvider.LanguageOptions, "#JW20");
78                 }
79
80                 [Test]
81                 public void GeneratorSupports ()
82                 {
83                         ICodeGenerator codeGenerator = _codeProvider.CreateGenerator ();
84                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#1");
85                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ArraysOfArrays), "#2");
86                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.AssemblyAttributes), "#3");
87                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ChainedConstructorArguments), "#4");
88                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ComplexExpressions), "#5");
89                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareDelegates), "#6");
90                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#7");
91                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEvents), "#8");
92                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareInterfaces), "#9");
93                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareValueTypes), "#10");
94                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.EntryPointMethod), "#11");
95                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GotoStatements), "#12");
96                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultidimensionalArrays), "#13");
97                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultipleInterfaceMembers), "#14");
98                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.NestedTypes), "#15");
99                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ParameterAttributes), "#16");
100                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PublicStaticMembers), "#17");
101                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReferenceParameters), "#18");
102                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReturnTypeAttributes), "#19");
103                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.StaticConstructors), "#20");
104                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.TryCatchStatements), "#21");
105                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Win32Resources), "#22");
106 #if NET_2_0
107                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareIndexerProperties), "#23");
108                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeDeclaration), "#24");
109                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeReference), "#25");
110                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PartialTypes), "#26");
111                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Resources), "#27");
112 #endif
113                 }
114
115                 [Test]
116 #if NET_2_0
117                 // there's not yet an mbas for the 2.0 profile
118                 [Category ("NotWorking")]
119 #endif
120                 public void CreateCompiler ()
121                 {
122                         // Prepare the compilation
123                         ICodeCompiler codeCompiler = _codeProvider.CreateCompiler ();
124                         Assert.IsNotNull (codeCompiler, "#JW30 - CreateCompiler");
125
126                         CompilerParameters options = new CompilerParameters ();
127                         options.GenerateExecutable = true;
128                         options.IncludeDebugInformation = true;
129                         options.TreatWarningsAsErrors = true;
130
131                         // process compilation
132                         CompilerResults compilerResults = codeCompiler.CompileAssemblyFromSource (options,
133                                 "public class TestModule" + Environment.NewLine + "public shared sub Main()"
134                                 + Environment.NewLine + "System.Console.Write(\"Hello world!\")"
135                                 + Environment.NewLine + "End Sub" + Environment.NewLine + "End Class");
136
137                         // Analyse the compilation success/messages
138                         StringCollection MyOutput = compilerResults.Output;
139                         string MyOutStr = "";
140                         foreach (string MyStr in MyOutput) {
141                                 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
142                         }
143
144                         if (compilerResults.Errors.Count != 0) {
145                                 Assert.Fail ("#JW31 - Hello world compilation: " + MyOutStr);
146                         }
147
148                         try {
149                                 Assembly MyAss = compilerResults.CompiledAssembly;
150                         } catch (Exception ex) {
151                                 Assert.Fail ("#JW32 - compilerResults.CompiledAssembly hasn't been an expected object" +
152                                                 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
153                         }
154
155                         // Execute the test app
156                         ProcessStartInfo NewProcInfo = new ProcessStartInfo ();
157                         if (Windows) {
158                                 NewProcInfo.FileName = compilerResults.CompiledAssembly.Location;
159                         } else {
160                                 NewProcInfo.FileName = "mono";
161                                 NewProcInfo.Arguments = compilerResults.CompiledAssembly.Location;
162                         }
163                         NewProcInfo.RedirectStandardOutput = true;
164                         NewProcInfo.UseShellExecute = false;
165                         NewProcInfo.CreateNoWindow = true;
166                         string TestAppOutput = "";
167                         try {
168                                 Process MyProc = Process.Start (NewProcInfo);
169                                 MyProc.WaitForExit ();
170                                 TestAppOutput = MyProc.StandardOutput.ReadToEnd ();
171                                 MyProc.Close ();
172                                 MyProc.Dispose ();
173                         } catch (Exception ex) {
174                                 Assert.Fail ("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace);
175                         }
176                         Assert.AreEqual ("Hello world!", TestAppOutput, "#JW33 - Application output");
177
178                         // Clean up
179                         try {
180                                 File.Delete (NewProcInfo.FileName);
181                         } catch { }
182                 }
183
184                 [Test]
185                 public void CreateGenerator ()
186                 {
187                         ICodeGenerator MyVBCodeGen;
188                         MyVBCodeGen = _codeProvider.CreateGenerator ();
189                         Assert.IsNotNull (MyVBCodeGen, "#JW40 - CreateGenerator");
190                         Assert.IsTrue (MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums), "#JW41");
191                 }
192
193                 [Test]
194 #if NET_2_0
195                 // there's not yet an mbas for the 2.0 profile
196                 [Category ("NotWorking")]
197 #endif
198                 public void CompileFromFile_InMemory ()
199                 {
200                         // create vb source file
201                         string sourceFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
202                         using (FileStream f = new FileStream (sourceFile, FileMode.Create)) {
203                                 using (StreamWriter s = new StreamWriter (f)) {
204                                         s.Write (_sourceTest1);
205                                         s.Close ();
206                                 }
207                                 f.Close ();
208                         }
209
210                         CompilerParameters options = new CompilerParameters ();
211                         options.GenerateExecutable = false;
212                         options.GenerateInMemory = true;
213                         options.TempFiles = new TempFileCollection (_tempDir);
214
215                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
216                         CompilerResults results = compiler.CompileAssemblyFromFile (options,
217                                 sourceFile);
218
219                         // verify compilation was successful
220                         AssertCompileResults (results, true);
221
222                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
223                         Assert.IsNull (results.PathToAssembly, "#2");
224                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
225
226                         // verify we don't cleanup files in temp directory too agressively
227                         string[] tempFiles = Directory.GetFiles (_tempDir);
228                         Assert.AreEqual (1, tempFiles.Length, "#4");
229                         Assert.AreEqual (sourceFile, tempFiles[0], "#5");
230                 }
231
232                 [Test]
233 #if NET_2_0
234                 // there's not yet an mbas for the 2.0 profile
235                 [Category ("NotWorking")]
236 #endif
237                 public void CompileFromFileBatch_InMemory ()
238                 {
239                         // create vb source file
240                         string sourceFile1 = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
241                         using (FileStream f = new FileStream (sourceFile1, FileMode.Create)) {
242                                 using (StreamWriter s = new StreamWriter (f)) {
243                                         s.Write (_sourceTest1);
244                                         s.Close ();
245                                 }
246                                 f.Close ();
247                         }
248
249                         string sourceFile2 = Path.Combine (_tempDir, "file2." + _codeProvider.FileExtension);
250                         using (FileStream f = new FileStream (sourceFile2, FileMode.Create)) {
251                                 using (StreamWriter s = new StreamWriter (f)) {
252                                         s.Write (_sourceTest2);
253                                         s.Close ();
254                                 }
255                                 f.Close ();
256                         }
257
258                         CompilerParameters options = new CompilerParameters ();
259                         options.GenerateExecutable = false;
260                         options.GenerateInMemory = true;
261                         options.TempFiles = new TempFileCollection (_tempDir);
262
263                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
264                         CompilerResults results = compiler.CompileAssemblyFromFileBatch (options,
265                                 new string[] { sourceFile1, sourceFile2 });
266
267                         // verify compilation was successful
268                         AssertCompileResults (results, true);
269
270                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
271                         Assert.IsNull (results.PathToAssembly, "#2");
272
273                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
274                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test2"), "#4");
275
276                         // verify we don't cleanup files in temp directory too agressively
277                         string[] tempFiles = Directory.GetFiles (_tempDir);
278                         Assert.AreEqual (2, tempFiles.Length, "#5");
279                         Assert.IsTrue (File.Exists (sourceFile1), "#6");
280                         Assert.IsTrue (File.Exists (sourceFile2), "#7");
281                 }
282
283                 [Test]
284 #if NET_2_0
285                 // there's not yet an mbas for the 2.0 profile
286                 [Category ("NotWorking")]
287 #endif
288                 public void CompileFromSource_InMemory ()
289                 {
290                         // create a file in temp directory to ensure that compiler is not removing
291                         // too much (temporary) files
292                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
293                         using (FileStream fs = File.Create (tempFile)) {
294                                 fs.Close ();
295                         }
296
297                         CompilerParameters options = new CompilerParameters ();
298                         options.GenerateExecutable = false;
299                         options.GenerateInMemory = true;
300                         options.TempFiles = new TempFileCollection (_tempDir);
301
302                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
303                         CompilerResults results = compiler.CompileAssemblyFromSource (options,
304                                 _sourceTest1);
305
306                         // verify compilation was successful
307                         AssertCompileResults (results, true);
308
309                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
310                         Assert.IsNull (results.PathToAssembly, "#2");
311                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
312
313                         // verify we don't cleanup files in temp directory too agressively
314                         string[] tempFiles = Directory.GetFiles (_tempDir);
315                         Assert.AreEqual (1, tempFiles.Length, "#4");
316                         Assert.AreEqual (tempFile, tempFiles[0], "#5");
317                 }
318
319                 [Test]
320 #if NET_2_0
321                 // there's not yet an mbas for the 2.0 profile
322                 [Category ("NotWorking")]
323 #endif
324                 public void CompileFromSourceBatch_InMemory ()
325                 {
326                         // create a file in temp directory to ensure that compiler is not removing
327                         // too much (temporary) files
328                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
329                         using (FileStream fs = File.Create (tempFile)) {
330                                 fs.Close ();
331                         }
332
333                         CompilerParameters options = new CompilerParameters ();
334                         options.GenerateExecutable = false;
335                         options.GenerateInMemory = true;
336                         options.TempFiles = new TempFileCollection (_tempDir);
337
338                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
339                         CompilerResults results = compiler.CompileAssemblyFromSourceBatch (options,
340                                 new string[] { _sourceTest1, _sourceTest2 });
341
342                         // verify compilation was successful
343                         AssertCompileResults (results, true);
344
345                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
346                         Assert.IsNull (results.PathToAssembly, "#2");
347
348                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
349                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test2"), "#4");
350
351                         // verify we don't cleanup files in temp directory too agressively
352                         string[] tempFiles = Directory.GetFiles (_tempDir);
353                         Assert.AreEqual (1, tempFiles.Length, "#5");
354                         Assert.AreEqual (tempFile, tempFiles[0], "#6");
355                 }
356
357                 [Test]
358 #if NET_2_0
359                 // there's not yet an mbas for the 2.0 profile
360                 [Category ("NotWorking")]
361 #endif
362                 public void CompileFromDom_NotInMemory ()
363                 {
364                         // create a file in temp directory to ensure that compiler is not removing
365                         // too much (temporary) files
366                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
367                         using (FileStream fs = File.Create (tempFile)) {
368                                 fs.Close ();
369                         }
370
371                         // compile and verify result in separate appdomain to avoid file locks
372                         AppDomain testDomain = CreateTestDomain ();
373                         CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
374
375                         string outputAssembly = null;
376
377                         try {
378                                 outputAssembly = compileTester.CompileAssemblyFromDom (_tempDir);
379                         } finally {
380                                 AppDomain.Unload (testDomain);
381                         }
382
383                         // there should be two files in temp dir: temp file and output assembly
384                         string[] tempFiles = Directory.GetFiles (_tempDir);
385                         Assert.AreEqual (2, tempFiles.Length, "#1");
386                         Assert.IsTrue (File.Exists (outputAssembly), "#2");
387                         Assert.IsTrue (File.Exists (tempFile), "#3");
388                 }
389
390                 [Test]
391 #if NET_2_0
392                 // there's not yet an mbas for the 2.0 profile
393                 [Category ("NotWorking")]
394 #endif
395                 public void CompileFromDomBatch_NotInMemory ()
396                 {
397                         // create a file in temp directory to ensure that compiler is not removing
398                         // too much (temporary) files
399                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
400                         using (FileStream fs = File.Create (tempFile)) {
401                                 fs.Close ();
402                         }
403
404                         // compile and verify result in separate appdomain to avoid file locks
405                         AppDomain testDomain = CreateTestDomain ();
406                         CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
407
408                         string outputAssembly = null;
409
410                         try {
411                                 outputAssembly = compileTester.CompileAssemblyFromDomBatch (_tempDir);
412                         } finally {
413                                 AppDomain.Unload (testDomain);
414                         }
415
416                         // there should be two files in temp dir: temp file and output assembly
417                         string[] tempFiles = Directory.GetFiles (_tempDir);
418                         Assert.AreEqual (2, tempFiles.Length, "#1");
419                         Assert.IsTrue (File.Exists (outputAssembly), "#2");
420                         Assert.IsTrue (File.Exists (tempFile), "#3");
421                 }
422
423                 [Test]
424 #if NET_2_0
425                 // there's not yet an mbas for the 2.0 profile
426                 [Category ("NotWorking")]
427 #endif
428                 public void CompileFromDom_InMemory ()
429                 {
430                         // create a file in temp directory to ensure that compiler is not removing
431                         // too much (temporary) files
432                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
433                         using (FileStream fs = File.Create (tempFile)) {
434                                 fs.Close ();
435                         }
436
437                         CompilerParameters options = new CompilerParameters ();
438                         options.GenerateExecutable = false;
439                         options.GenerateInMemory = true;
440                         options.TempFiles = new TempFileCollection (_tempDir);
441
442                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
443                         CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
444
445                         // verify compilation was successful
446                         AssertCompileResults (results, true);
447
448                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
449                         Assert.IsNull (results.PathToAssembly, "#2");
450
451                         // verify we don't cleanup files in temp directory too agressively
452                         string[] tempFiles = Directory.GetFiles (_tempDir);
453                         Assert.AreEqual (1, tempFiles.Length, "#3");
454                         Assert.AreEqual (tempFile, tempFiles[0], "#4");
455                 }
456
457                 [Test]
458 #if NET_2_0
459                 // there's not yet an mbas for the 2.0 profile
460                 [Category ("NotWorking")]
461 #endif
462                 public void CompileFromDomBatch_InMemory ()
463                 {
464                         // create a file in temp directory to ensure that compiler is not removing
465                         // too much (temporary) files
466                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
467                         using (FileStream fs = File.Create (tempFile)) {
468                                 fs.Close ();
469                         }
470
471                         CompilerParameters options = new CompilerParameters ();
472                         options.GenerateExecutable = false;
473                         options.GenerateInMemory = true;
474                         options.TempFiles = new TempFileCollection (_tempDir);
475
476                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
477                         CompilerResults results = compiler.CompileAssemblyFromDomBatch (options,
478                                 new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
479
480                         // verify compilation was successful
481                         AssertCompileResults (results, true);
482
483                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
484                         Assert.IsNull (results.PathToAssembly, "#2");
485
486                         // verify we don't cleanup files in temp directory too agressively
487                         string[] tempFiles = Directory.GetFiles (_tempDir);
488                         Assert.AreEqual (1, tempFiles.Length, "#3");
489                         Assert.AreEqual (tempFile, tempFiles[0], "#4");
490                 }
491
492                 //TODO: [Test]
493                 public void CreateParser ()
494                 {
495                         //System.CodeDom.Compiler.ICodeParser CreateParser()
496                 }
497
498                 //TODO: [Test]
499                 public void CreateObjRef ()
500                 {
501                         //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
502                 }
503
504                 bool Windows
505                 {
506                         get {
507                                 return OS == OsType.Windows;
508                         }
509                 }
510
511                 bool Unix
512                 {
513                         get {
514                                 return OS == OsType.Unix;
515                         }
516                 }
517
518                 bool Mac
519                 {
520                         get {
521                                 return OS == OsType.Mac;
522                         }
523                 }
524
525                 private static string CreateTempDirectory ()
526                 {
527                         // create a uniquely named zero-byte file
528                         string tempFile = Path.GetTempFileName ();
529                         // remove the temporary file
530                         File.Delete (tempFile);
531                         // create a directory named after the unique temporary file
532                         Directory.CreateDirectory (tempFile);
533                         // return the path to the temporary directory
534                         return tempFile;
535                 }
536
537                 private static void RemoveDirectory (string path)
538                 {
539                         try {
540                                 if (Directory.Exists (path)) {
541                                         string[] directoryNames = Directory.GetDirectories (path);
542                                         foreach (string directoryName in directoryNames) {
543                                                 RemoveDirectory (directoryName);
544                                         }
545                                         string[] fileNames = Directory.GetFiles (path);
546                                         foreach (string fileName in fileNames) {
547                                                 File.Delete (fileName);
548                                         }
549                                         Directory.Delete (path, true);
550                                 }
551                         } catch (Exception ex) {
552                                 throw new AssertionException ("Unable to cleanup '" + path + "'.", ex);
553                         }
554                 }
555
556                 private static void AssertCompileResults (CompilerResults results, bool allowWarnings)
557                 {
558                         foreach (CompilerError compilerError in results.Errors) {
559                                 if (allowWarnings && compilerError.IsWarning) {
560                                         continue;
561                                 }
562
563                                 Assert.Fail (compilerError.ToString ());
564                         }
565                 }
566
567                 private static AppDomain CreateTestDomain ()
568                 {
569                         return AppDomain.CreateDomain ("CompileFromDom", AppDomain.CurrentDomain.Evidence,
570                                 AppDomain.CurrentDomain.SetupInformation);
571                 }
572
573                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
574                 {
575                         Type testerType = typeof (CrossDomainTester);
576
577                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
578                                 testerType.Assembly.FullName, testerType.FullName, false,
579                                 BindingFlags.Public | BindingFlags.Instance, null, new object[0],
580                                 CultureInfo.InvariantCulture, new object[0], domain.Evidence);
581                 }
582
583                 private class CrossDomainTester : MarshalByRefObject
584                 {
585                         public string CompileAssemblyFromDom (string tempDir)
586                         {
587                                 CompilerParameters options = new CompilerParameters ();
588                                 options.GenerateExecutable = false;
589                                 options.GenerateInMemory = false;
590                                 options.TempFiles = new TempFileCollection (tempDir);
591
592                                 VBCodeProvider codeProvider = new VBCodeProvider ();
593                                 ICodeCompiler compiler = codeProvider.CreateCompiler ();
594                                 CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
595
596                                 // verify compilation was successful
597                                 AssertCompileResults (results, true);
598
599                                 Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
600                                         "Location should not be empty string");
601                                 Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");
602
603                                 return results.PathToAssembly;
604                         }
605
606                         public string CompileAssemblyFromDomBatch (string tempDir)
607                         {
608                                 CompilerParameters options = new CompilerParameters ();
609                                 options.GenerateExecutable = false;
610                                 options.GenerateInMemory = false;
611                                 options.TempFiles = new TempFileCollection (tempDir);
612
613                                 VBCodeProvider codeProvider = new VBCodeProvider ();
614                                 ICodeCompiler compiler = codeProvider.CreateCompiler ();
615                                 CompilerResults results = compiler.CompileAssemblyFromDomBatch (options, new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
616
617                                 // verify compilation was successful
618                                 AssertCompileResults (results, true);
619
620                                 Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
621                                         "Location should not be empty string");
622                                 Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");
623
624                                 return results.PathToAssembly;
625                         }
626                 }
627         }
628 }