Пример #1
0
        public void Can_run_a_Powershell_script_returning_a_value()
        {
            string script = @" return $self.Id ";

            var repository = new WorkItemRepositoryMock();
            var workItem = new WorkItemMock(repository);

            workItem.Id = 1;

            repository.SetWorkItems(new[] { workItem });
            var logger = Substitute.For<ILogEvents>();

            Assert.IsNotNull(repository.GetWorkItem(1));

            var engine = new PsScriptEngine(logger, Debugger.IsAttached);

            engine.LoadAndRun("test", script, workItem, repository);

            var expected = new Collection<PSObject> { new PSObject(1) };

            logger.Received().ResultsFromScriptRun(
                "test",
                Arg.Is<Collection<PSObject>>(x => x.Select(o => o.BaseObject).SequenceEqual(expected.Select(o => o.BaseObject))));
        }
Пример #2
0
        public void Can_run_a_Powershell_script_interacting_with_an_object_model()
        {
            string script = @" 

$self.Fields[""x""].Value = 33
return $self.Fields[""z""].Value ";

            var repository = new WorkItemRepositoryMock();
            var workItem = new WorkItemMock(repository);

            workItem.Fields["z"].Value = 42;
            workItem.Fields["x"].Value = 0;
            workItem.Id = 1;

            repository.SetWorkItems(new[] { workItem });
            var logger = Substitute.For<ILogEvents>();

            Assert.IsNotNull(repository.GetWorkItem(1));

            var engine = new PsScriptEngine(logger, Debugger.IsAttached);

            // sanity check
            Assert.AreEqual(42, workItem.Fields["z"].Value);

            engine.LoadAndRun("test", script, workItem, repository);

            var expected = new Collection<PSObject> { new PSObject(42) };

            Assert.AreEqual(33, workItem.Fields["x"].Value);

            logger.Received().ResultsFromScriptRun(
                "test",
                Arg.Is<Collection<PSObject>>(x => x.Select(o => o.BaseObject).SequenceEqual(expected.Select(o => o.BaseObject))));
        }