Exemple #1
0
        public void input_values_sorted_by_sortobject_command()
        {
            var values = new[] { 2, 1 };
            var sorted = HttpPowerShellCommand.FromCommand("Sort-Object").Invoke <int>(values).ToArray();

            Assert.AreEqual <int>(values[0], sorted[1]);
            Assert.AreEqual <int>(values[1], sorted[0]);
        }
Exemple #2
0
        public void compare_getdate_to_datetime_now()
        {
            var date = HttpPowerShellCommand.FromCommand("Get-Date").Invoke <DateTime>().First();
            var now  = DateTime.Now;

            if (now.Subtract(date).TotalSeconds > 5)
            {
                Assert.Fail("The date returned from the PowerShell command 'Get-Date' and the date retrieved from 'DateTime.Now' is different by more than five seconds.");
            }
        }
        public void resolver_returns_int_array_when_int_is_registered_type_and_getservices_called()
        {
            var resolver = new PowerShellDependencyResolver();

            resolver.Register <int>(HttpPowerShellCommand.FromScript("1..5"));

            DependencyResolver.SetResolver(resolver);

            Assert.AreEqual(15, DependencyResolver.Current.GetServices <int>().Sum());
        }
        public void resolver_returns_ArgumentException_when_Exception_is_registered_type()
        {
            var resolver = new PowerShellDependencyResolver();

            resolver.Register <Exception>(HttpPowerShellCommand.FromScript("New-Object System.ArgumentException"));

            DependencyResolver.SetResolver(resolver);

            Assert.IsInstanceOfType(DependencyResolver.Current.GetService <Exception>(), typeof(ArgumentException));
        }
Exemple #5
0
 public void can_invoke_script_from_resource_by_basename()
 {
     Assert.AreNotEqual(false, HttpPowerShellCommand.FromResource <HttpPowerShellTests>("System.Web.PowerShell.Tests.PowerShellScripts", "EchoInputs").Invoke <bool>(new bool[] { true }).First());
 }
Exemple #6
0
 public void can_invoke_script_from_resource_string()
 {
     Assert.AreEqual(true, HttpPowerShellCommand.FromResource(PowerShellScripts.ResourceManager, "EchoInputs").Invoke <bool>(new bool[] { true }).First());
 }
Exemple #7
0
 public void can_invoke_script_from_resource_file()
 {
     Assert.AreEqual(DateTime.Now.Year, HttpPowerShellCommand.FromResource <PowerShellScripts>("GetYearFromDate").Invoke <int>().First());
 }
 public override HttpPowerShellCommand ToCommand(object parameters)
 {
     return(HttpPowerShellCommand.FromResource(this._getResourceManager(), this._resourceName, parameters: parameters, useLocalScope: true));
 }
 public override HttpPowerShellCommand ToCommand(object parameters)
 {
     return(HttpPowerShellCommand.FromFile(this._path, parameters: parameters, useLocalScope: true));
 }
 public void Register <T>(HttpPowerShellCommand command)
 {
     _commands.Add(typeof(T), command);
 }