예제 #1
0
        internal static Business GetInstance(string name)
        {
            Business business = BusinessesFolder.Load(name);

            business.Name = name;
            return(business);
        }
        public void TestGetInstance()
        {
            {
                // when
                BusinessInformation information = BusinessInformation.GetInstance("xxx");

                // then
                Assert.AreEqual("xxx", information.Name);
                Assert.AreEqual(null, information.Synopsis);
                Assert.AreEqual(null, information.Description);
                Assert.AreEqual(null, information.Examples);
            }

            {
                // setup
                BusinessesFolder.Initialize("zzz");

                // when
                BusinessInformation information = BusinessInformation.GetInstance("zzz");

                // then
                Assert.AreEqual("zzz", information.Name);
                Assert.AreEqual("Reports current time.", information.Synopsis);
                Assert.IsTrue(information.Description.StartsWith("Copyright "));
                Assert.AreEqual("[<CommonParameters>]", information.Examples.Trim());
            }
        }
 private void openBusinessConfigurationFolder_Click(object sender, RoutedEventArgs e)
 {
     if (ValidateAsFileName(this.businessName))
     {
         BusinessesFolder.Open(this.businessName.Text);
     }
 }
예제 #4
0
        private Hashtable ExecuteScript(string businessName, string parameters, Hashtable report)
        {
            PowerShell powerShell = base.GetPowerShell();

            SetWorkingDirectory(powerShell, BusinessesFolder.GetFolder(businessName));
            powerShell.AddScript(@"foreach($i in $input) {$report = $i};. .\main.ps1;Main " + parameters);
            Collection <PSObject> results = Invoke(powerShell, new[] { report });

            return(GetObject <Hashtable>(powerShell, results));
        }
예제 #5
0
        public void TestGetInstance()
        {
            // when
            Business business = Business.GetInstance("xxx");

            // then
            Assert.AreEqual("xxx", business.Name);
            Assert.IsNull(business.Parameters);
            Assert.AreEqual(30, business.TimerInterval);
            Assert.IsFalse(Directory.Exists(BusinessesFolder.GetFolder("xxx")));
        }
        internal Hashtable ExecuteScript(string name)
        {
            string     folder     = BusinessesFolder.GetFolder(name);
            PowerShell powerShell = base.GetPowerShell();

            powerShell.Runspace.SessionStateProxy.Path.SetLocation(folder);
            powerShell.AddScript(Script);
            Collection <PSObject> results = Invoke(powerShell, null);

            return(results.Select(pso => (Hashtable)pso.BaseObject).First());
        }
예제 #7
0
        public void TestCreateReport()
        {
            // setup
            BusinessesFolder.Initialize("zzz");
            Business business = Business.GetInstance(BusinessesFolder.TimeKeeping);

            // when
            Hashtable report = business.CreateReport(new Hashtable());

            // then
            Assert.AreEqual(true, report["IsUpdated"]);
        }
 internal static BusinessInformation GetInstance(string name)
 {
     if (Directory.Exists(BusinessesFolder.GetFolder(name)))
     {
         return(BusinessInformationScriptEngine.Load(name));
     }
     else
     {
         return(new BusinessInformation()
         {
             Name = name
         });
     }
 }
예제 #9
0
        public void TestLoad()
        {
            // setup
            BusinessesFolder.Initialize("Check-Job-status");

            // when
            BusinessInformation information = BusinessInformationScriptEngine.Load("Check-Job-status");

            // then
            Assert.AreEqual("Check-Job-status", information.Name);
            Assert.AreEqual("Reports job statuses of a build server.", information.Synopsis);
            Assert.IsTrue(information.Description.StartsWith("Copyright "));
            Assert.IsTrue(information.Examples.Trim().StartsWith("[-url] <String>"));
        }
        public void TestScriptError()
        {
            // setup
            BusinessesFolder.Initialize(BusinessesFolder.CheckJobStatus);

            try
            {
                // when
                BusinessScriptEngine.Execute(BusinessesFolder.CheckJobStatus, null, new Hashtable());
                Assert.Fail("ここにはこない");
            }
            catch (ApplicationException e)
            {
                // then
                Console.WriteLine(e.Message);
                Assert.IsTrue(e.Message.StartsWith("Cannot process command because of "));
            }
        }
        public void TestErrorTheScriptMustReturnObject()
        {
            // setup
            BusinessesFolder.Initialize(BusinessesFolder.TimeKeeping);
            string script = Path.Combine(BusinessesFolder.GetFolder(BusinessesFolder.TimeKeeping), "main.ps1");

            TestUtil.Replace(script, "    $newReport\r\n}", "}");

            try
            {
                // when
                BusinessScriptEngine.Execute(BusinessesFolder.TimeKeeping, null, new Hashtable());
                Assert.Fail("ここにはこない");
            }
            catch (ApplicationException e)
            {
                // then
                Console.WriteLine(e.Message);
                Assert.AreEqual("the script must return a instance of Hashtable", e.Message);
            }
        }
예제 #12
0
 internal void Save(string name)
 {
     BusinessesFolder.Save(name, this);
 }
예제 #13
0
 private void AddBusinessNames()
 {
     AddItems(this.businessName, BusinessesFolder.GetFolderNames(),
              this.Workspace.Configuration.Business);
 }