CSharpTests.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using csharp_sccd_compiler;
  3. using NUnit.Framework;
  4. namespace csharp_tests
  5. {
  6. [TestFixture]
  7. [Category("CSharp")]
  8. public class CSharpTests : TestsBase
  9. {
  10. [TestFixtureSetUp]
  11. public void setLogger()
  12. {
  13. Logger.verbose = 1;
  14. }
  15. protected override bool generate(string file_path, string expected_exception)
  16. {
  17. TestDelegate generation_delegate = () => Compiler.generate(file_path, this.path_generated_code, CodeGenerator.Platform.THREADS);
  18. if (expected_exception == null)
  19. generation_delegate();
  20. else
  21. {
  22. Type expected_exception_type = null;
  23. if (expected_exception == "CompilerException")
  24. expected_exception_type = typeof(CompilerException);
  25. else if (expected_exception == "TransitionException")
  26. expected_exception_type = typeof(TransitionException);
  27. else
  28. Assert.Fail("Invalid value for the exception attribute.");
  29. Exception throwed_exception = Assert.Catch<Exception>(generation_delegate, "Expected an exception but none was throwed.").GetBaseException();
  30. Assert.IsInstanceOf(expected_exception_type, throwed_exception,
  31. string.Format("Expected exception of type {0} but got an exception of type {1} instead.", expected_exception_type, throwed_exception.GetType()));
  32. return false;
  33. }
  34. return true;
  35. }
  36. }
  37. }