00001 import unittest
00002 import os
00003 import os.path
00004 import GPyUnit.util
00005 from GPyUnit.util import DispatchEx
00006
00007 _filedir = os.path.dirname(os.path.abspath(__file__))
00008 def _adjacent_file(file):
00009 return os.path.join(_filedir, file)
00010
00011 class TestCSharpDSMLGenerator(unittest.TestCase):
00012 def test_run(self):
00013 mga = GPyUnit.util.parse_xme("MGA=" + _adjacent_file("BidirConnection.mga"), _adjacent_file("BidirConnection.xme"))
00014 print self.connstr
00015 try:
00016 mga.Save()
00017 selectedobj = DispatchEx("Mga.MgaFCOs")
00018 launcher = DispatchEx("Mga.MgaLauncher")
00019
00020 launcher.RunComponent("Mga.Interpreter.CSharpDSMLGenerator", mga, None, selectedobj, 128)
00021 finally:
00022 mga.Close()
00023 self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.BidirConnection.Classes.cs")))
00024 self.assertTrue(os.path.isfile(os.path.join(self.outdir(), "ISIS.GME.Dsml.BidirConnection.dll")))
00025
00026 mga = GPyUnit.util.parse_xme(self.connstr, _adjacent_file("BidirConnectionModel.xme"))
00027 mga.Save()
00028 mga.BeginTransactionInNewTerr()
00029 try:
00030 self.assertEqual(mga.ObjectByPath("/@NewModel/@Child1").PartOfConns.Count, 2)
00031 self.assertEqual(set([x.ConnRole for x in mga.ObjectByPath("/@NewModel/@Child1").PartOfConns]), set(['src', 'dst']))
00032 self.assertEqual(set([x.ConnRole for x in mga.ObjectByPath("/@NewModel/@Child2").PartOfConns]), set(['src', 'dst']))
00033 finally:
00034 mga.AbortTransaction()
00035 mga.Close()
00036
00037 import subprocess
00038 subprocess.check_call([r"c:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe", _adjacent_file(r"DsmlGeneratorTest\DsmlGeneratorTest.csproj")])
00039 subprocess.check_call([_adjacent_file(r"DsmlGeneratorTest\bin\Debug\DsmlGeneratorTest.exe"), self.connstr])
00040
00041
00042 def setUp(self):
00043 registrar = DispatchEx("Mga.MgaRegistrar")
00044 registrar.RegisterParadigmFromData("XML=" + _adjacent_file("BidirConnection.xmp"), "BidirConnection", 1)
00045
00046 def tearDown(self):
00047 for file in ("AssemblySignature.snk", "ISIS.GME.Dsml.BidirConnection.Classes.cs", "ISIS.GME.Dsml.BidirConnection.dll",
00048 "ISIS.GME.Dsml.BidirConnection.Interfaces.cs", "ISIS.GME.Dsml.BidirConnection.xml", "ISIS.GME.Dsml.pdb", "BidirConnection.xmp.log",
00049 "BidirConnection.mta", r"DsmlGeneratorTest\bin\Debug\DsmlGeneratorTest.exe"):
00050 if os.path.isfile(os.path.join(self.outdir(), file)):
00051 os.unlink(os.path.join(self.outdir(), file))
00052
00053 @property
00054 def connstr(self):
00055 return "MGA=" + _adjacent_file("BidirConnectionModel.mga")
00056
00057 def outdir(self):
00058 return os.path.abspath(_adjacent_file('.'))
00059
00060 if GPyUnit.util._opts.Dispatch_x64:
00061 del TestCSharpDSMLGenerator
00062
00063
00064 if __name__ == "__main__":
00065 unittest.main()