CodeGeneratorTestBase.cs 902 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // Base class for CodeGenerator unit tests
  3. //
  4. // Authors:
  5. // Gert Driesen ([email protected])
  6. //
  7. // (c) Novell
  8. //
  9. using System;
  10. using System.CodeDom;
  11. using System.CodeDom.Compiler;
  12. using System.IO;
  13. using NUnit.Framework;
  14. namespace MonoTests.System.CodeDom.Compiler
  15. {
  16. public abstract class CodeGeneratorTestBase
  17. {
  18. private StringWriter _writer;
  19. private CodeGeneratorOptions _options;
  20. [SetUp]
  21. public virtual void SetUp ()
  22. {
  23. _writer = new StringWriter ();
  24. _writer.NewLine = "\n";
  25. _options = new CodeGeneratorOptions ();
  26. }
  27. protected abstract ICodeGenerator CodeGenerator
  28. {
  29. get;
  30. }
  31. protected StringWriter Writer
  32. {
  33. get { return _writer; }
  34. }
  35. protected virtual string GenerateCodeFromType (CodeTypeDeclaration type)
  36. {
  37. CodeGenerator.GenerateCodeFromType (type, _writer, _options);
  38. _writer.Close ();
  39. return _writer.ToString ();
  40. }
  41. }
  42. }