Exemplo n.º 1
0
        public void Can_run_a_VBNet_script_interacting_with_an_object_model()
        {
            string script     = @"
self(""x"") = 33
return self(""z"")
";
            var    repository = Substitute.For <IWorkItemRepository>();
            var    workItem   = Substitute.For <IWorkItem>();

            workItem.Id.Returns(1);
            workItem["x"] = 11;
            workItem["z"].Returns(42);
            repository.GetWorkItem(1).Returns(workItem);
            var logger = Substitute.For <ILogEvents>();

            logger.WhenForAnyArgs(c => Debug.WriteLine(c));
            var engine = new VBNetScriptEngine(repository, logger, Debugger.IsAttached);

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

            Assert.AreEqual(33, workItem["x"]);
            object expected = 42;

            logger.Received().ResultsFromScriptRun("test", expected);
        }
Exemplo n.º 2
0
        public void Can_run_a_VBNet_script_with_logging()
        {
            string script     = @"
logger.Log(""Test"")
";
            var    repository = Substitute.For <IWorkItemRepository>();
            var    workItem   = Substitute.For <IWorkItem>();
            var    logger     = Substitute.For <ILogEvents>();

            logger.ScriptLogger = Substitute.For <IRuleLogger>();
            var engine = new VBNetScriptEngine(repository, logger, Debugger.IsAttached);

            engine.LoadAndRun("test", script, workItem);
            logger.ScriptLogger.Received().Log("Test");
        }
Exemplo n.º 3
0
        public void Can_VBNet_use_Linq()
        {
            string script     = @"
Dim array As Integer() = {1, 3, 5, 7}
Return Cint(array.Average())
";
            var    repository = Substitute.For <IWorkItemRepository>();
            var    workItem   = Substitute.For <IWorkItem>();

            repository.GetWorkItem(1).Returns(workItem);
            var logger = Substitute.For <ILogEvents>();
            var engine = new VBNetScriptEngine(repository, logger, Debugger.IsAttached);

            engine.LoadAndRun("test", script, workItem);
            object expected = 4;

            logger.Received().ResultsFromScriptRun("test", expected);
        }
Exemplo n.º 4
0
        public void Can_run_a_VBNet_script_interacting_with_an_object_model()
        {
            string script = @"
self(""x"") = 33
return self(""z"")
";
            var repository = Substitute.For<IWorkItemRepository>();
            var workItem = Substitute.For<IWorkItem>();
            workItem.Id.Returns(1);
            workItem["x"] = 11;
            workItem["z"].Returns(42);
            repository.GetWorkItem(1).Returns(workItem);
            var logger = Substitute.For<ILogEvents>();
            logger.WhenForAnyArgs(c => Debug.WriteLine(c));
            var engine = new VBNetScriptEngine(logger, Debugger.IsAttached);

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

            Assert.AreEqual(33, workItem["x"]);
            object expected = 42;
            logger.Received().ResultsFromScriptRun("test", expected);
        }
Exemplo n.º 5
0
        public void Can_VBNet_use_Linq()
        {
            string script = @"
Dim array As Integer() = {1, 3, 5, 7}
Return CInt(array.Average())
";
            var repository = Substitute.For<IWorkItemRepository>();
            var workItem = Substitute.For<IWorkItem>();
            repository.GetWorkItem(1).Returns(workItem);
            var logger = Substitute.For<ILogEvents>();
            var engine = new VBNetScriptEngine(logger, Debugger.IsAttached);
            engine.LoadAndRun("test", script, workItem, repository);
            object expected = 4;
            logger.Received().ResultsFromScriptRun("test", expected);
        }
Exemplo n.º 6
0
        public void Can_run_a_VBNet_script_with_logging()
        {
            string script = @"
logger.Log(""Test"")
";
            var repository = Substitute.For<IWorkItemRepository>();
            var workItem = Substitute.For<IWorkItem>();
            var logger = Substitute.For<ILogEvents>();
            logger.ScriptLogger = Substitute.For<IRuleLogger>();
            var engine = new VBNetScriptEngine(logger, Debugger.IsAttached);
            engine.LoadAndRun("test", script, workItem, repository);
            logger.ScriptLogger.Received().Log("Test");
        }