// 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        internal string GetTempConfigFile(LangSetup[] langs) {
            string xmlPrefix = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +  
"<configuration>" +
  "<configSections>"+
    "<section name=\"microsoft.scripting\" type=\"Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=1.1.0.20, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" requirePermission=\"false\" />"+
  "</configSections>"+

  "<microsoft.scripting>"+
    "<languages>";

            string xmlSuffix ="</languages>"+
  "</microsoft.scripting>"+
"</configuration>";

    //"<options>"+
    //  "<set language=\"Ruby\" option=\"LibraryPaths\" value=\"..\\..\\Languages\\Ruby\\libs;..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\site_ruby\\1.8;..\\..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\site_ruby;..\\..\\..\\External.LCA_RESTRICTED\\Languages\\Ruby\\Ruby-1.8.6p287\\lib\\ruby\\1.8\" />"+
    //"</options>"+

            StringBuilder ret = new StringBuilder();
            Array.ForEach(langs, lang => ret.AppendLine(lang.ToString()));

            string contents = xmlPrefix + ret.ToString() + xmlSuffix;

            return TestHelpers.CreateTempSourceFile( contents, ".config");
        }
示例#2
0
        static LangSetup() {
            Python = new LangSetup( new[] { "IronPython","Python","py" },new[] { ".py" }, "IronPython 2.6",
                "IronPython.Runtime.PythonContext", "IronPython, Version=2.7.0.10, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            );

            Ruby = new LangSetup( new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" },"IronRuby",
                "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
            );
        }
示例#3
0
        static LangSetup() {
            Python = new LangSetup( new[] { "IronPython","Python","py" },new[] { ".py" }, "IronPython 3.0",
                "IronPython.Runtime.PythonContext", "IronPython, Version=3.0.0.0, Culture=neutral"
            );

            Ruby = new LangSetup( new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" },"IronRuby",
                "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.4.0, Culture=neutral"
            );
        }
示例#4
0
        static LangSetup()
        {
            Python = new LangSetup(new[] { "IronPython", "Python", "py" }, new[] { ".py" }, "IronPython 2.7",
                                   "IronPython.Runtime.PythonContext", "IronPython, Version=2.7.0.40, Culture=neutral"
                                   );

            Ruby = new LangSetup(new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" }, "IronRuby",
                                 "IronRuby.Runtime.RubyContext", "IronRuby, Version=1.1.3.0, Culture=neutral"
                                 );
        }
示例#5
0
        public void ReadConfiguration_EmptyTypeName()
        {
            LangSetup py2 = new LangSetup(LangSetup.Python.Names, LangSetup.Python.Extensions, LangSetup.Python.DisplayName,
                                          "", LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    eng        = new ScriptRuntime(srs).GetEngine("py");

            Assert.AreEqual(LangSetup.Python.Names[0], eng.Setup.DisplayName);
        }
示例#6
0
        public void ReadConfiguration_EmptyExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, new[] { "", "" }, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var    runtime    = new ScriptRuntime(srs);

            Assert.AreEqual(5, runtime.GetEngine("py").Execute("2+3"));
        }
示例#7
0
        public void ReadConfiguration_IncorrectType()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, py1.Extensions, py1.DisplayName,
                                          "IronPython.Runtime.PythonBuffer", py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr  = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");

            Assert.Fail("some exception should have been thrown");
        }
示例#8
0
        public void ReadConfiguration_MissingAssembly()
        {
            LangSetup lang = new LangSetup(new[] { "SomeName" }, new[] { ".sn" }, "Somename",
                                           "SomeLang.Runtime.LangContext",
                                           "SomeLang, Version=8.0.0.5050, Culture=neutral, PublicKeyToken=31345fgsd4344e35");

            string configFile = GetTempConfigFile(new[] { lang });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            //this should throw..error message should be meaningful
            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
示例#9
0
        public void ReadConfiguration_DuplicateNames()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(LangSetup.Ruby.Names, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2, LangSetup.Ruby });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.Fail("some exception should have been thrown");
        }
示例#10
0
        public void ReadConfiguration_Multi_SameTypeDifferentName()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(new[] { "NewPython" }, py1.Extensions, py1.DisplayName,
                                          py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);

            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
            Assert.AreEqual("NewPython", sr.Setup.LanguageSetups[0].Names[0]);
        }
示例#11
0
        public void ReadConfiguration_DuplicateEmptyExtensions()
        {
            LangSetup rb1 = new LangSetup(LangSetup.Ruby.Names, new[] { "", "" }, LangSetup.Ruby.DisplayName,
                                          LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            LangSetup py2 = new LangSetup(LangSetup.Python.Names, new[] { "", "" }, LangSetup.Python.DisplayName,
                                          LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { rb1, py2 });
            var    srs        = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr   = new ScriptRuntime(srs);
            var eng  = sr.GetEngine("py");
            var eng2 = sr.GetEngine("rb");

            Assert.AreEqual(5, eng.Execute("2+3"));
        }
        internal string GetTempConfigFile(LangSetup[] langs)
        {
            string xmlPrefix = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
            "<configuration>" +
              "<configSections>"+
            "<section name=\"microsoft.scripting\" type=\"Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=1.1.0.30, Culture=neutral, PublicKeyToken=31bf3856ad364e35\" requirePermission=\"false\" />"+
              "</configSections>"+

              "<microsoft.scripting>"+
            "<languages>";

            string xmlSuffix ="</languages>"+
              "</microsoft.scripting>"+
            "</configuration>";

            StringBuilder ret = new StringBuilder();
            Array.ForEach(langs, lang => ret.AppendLine(lang.ToString()));

            string contents = xmlPrefix + ret.ToString() + xmlSuffix;

            return TestHelpers.CreateTempSourceFile( contents, ".config");
        }
示例#13
0
        public void ReadConfiguration_DuplicateEmptyExtensions()
        {
            LangSetup rb1 = new LangSetup(LangSetup.Ruby.Names, new[] { "", "" }, LangSetup.Ruby.DisplayName,
                    LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            LangSetup py2 = new LangSetup(LangSetup.Python.Names, new[] { "", "" }, LangSetup.Python.DisplayName,
                                LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { rb1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            var eng2 = sr.GetEngine("rb");

            Assert.AreEqual(5, eng.Execute("2+3"));
        }
示例#14
0
        public void ReadConfiguration_DuplicateExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, LangSetup.Ruby.Extensions, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2, LangSetup.Ruby });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            Assert.Fail("some exception should have been thrown");
        }
示例#15
0
        public void ReadConfiguration_MisMatchedTypeAssembly()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, py1.Extensions, py1.DisplayName,
                                LangSetup.Ruby.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2});
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            var sr = new ScriptRuntime(srs);
            var eng = sr.GetEngine("py");
            Assert.Fail("some exception should have been thrown");
        }
示例#16
0
        public void ReadConfiguration_NullDisplayName()
        {
            LangSetup py2 = new LangSetup(LangSetup.Python.Names, LangSetup.Python.Extensions, null,
                                LangSetup.Python.TypeName, LangSetup.Python.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var eng = new ScriptRuntime(srs).GetEngine("py");

            Assert.AreEqual("", eng.Setup.DisplayName);
        }
示例#17
0
        public void ReadConfiguration_Multi_SameTypeDifferentName()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup( new[]{"NewPython"}, py1.Extensions, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(1, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
            Assert.AreEqual("NewPython", sr.Setup.LanguageSetups[0].Names[0]);
        }
示例#18
0
        public void ReadConfiguration_Multi_SameNameDifferentType()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup( py1.Names, py1.Extensions, py1.DisplayName,
                                LangSetup.Ruby.TypeName, LangSetup.Ruby.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py1, py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            Assert.AreEqual(2, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
            Assert.Fail("some exception should have been thrown");
        }
示例#19
0
        public void ReadConfiguration_MissingAssembly()
        {
            LangSetup lang = new LangSetup(new[]{"SomeName"}, new[]{".sn"}, "Somename",
                    "SomeLang.Runtime.LangContext",
                    "SomeLang, Version=8.0.0.5050, Culture=neutral, PublicKeyToken=31345fgsd4344e35");

            string configFile = GetTempConfigFile(new[] { lang});
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);

            //this should throw..error message should be meaningful
            var sr = new ScriptRuntime(srs);
            Assert.Fail("some exception should have been thrown");
        }
示例#20
0
        public void ReadConfiguration_EmptyExtensions()
        {
            LangSetup py1 = LangSetup.Python;
            LangSetup py2 = new LangSetup(py1.Names, new[]{"",""}, py1.DisplayName,
                                py1.TypeName, py1.AssemblyString);

            string configFile = GetTempConfigFile(new[] { py2 });
            var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
            var runtime = new ScriptRuntime(srs);

            Assert.AreEqual(5, runtime.GetEngine("py").Execute("2+3"));
        }
示例#21
0
 static LangSetup()
 {
     Python = new LangSetup(new[] { "IronPython", "Python", "py" }, new[] { ".py" }, "IronPython 3.0",
                            "IronPython.Runtime.PythonContext", "IronPython, Version=2.9.0.0, Culture=neutral"
                            );
 }