示例#1
0
            public void ShouldAddNewReferencesIfTheyAreProvided(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var a = 0;";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                ((SessionState <Session>)scriptPackSession.State[RoslynScriptEngine.SessionKey]).References.PathReferences.Count().ShouldEqual(1);
            }
示例#2
0
            public void ShouldReturnAScriptResult(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                var code = string.Empty;

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences();

                refs.PathReferences.Add("System");

                // Act
                var result = engine.Execute(code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ShouldBeType <ScriptResult>();
            }
            public void ShouldCreateNewSessionIfNotProvided(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var a = 0;";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                // Act
                engine.Execute(Code, new string[0], new AssemblyReferences(), Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                engine.Session.ShouldNotBeNull();
            }
示例#4
0
            public void ShouldAddNewReferencesIfTheyAreProvided(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var a = 0;";

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences(new[] { "System" });

                // Act
                engine.Execute(Code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                ((SessionState <Session>)scriptPackSession.State[RoslynScriptEngine.SessionKey]).References.Paths.Count().ShouldEqual(1);
            }
示例#5
0
            public void ShouldReturnAScriptResult(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                var code = string.Empty;

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;
                var refs = new AssemblyReferences(new[] { "System" });

                // Act
                var result = engine.Execute(code, new string[0], refs, Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                result.ShouldBeType <ScriptResult>();
            }
            public void ShouldReuseExistingSessionIfProvided(
                [Frozen] Mock <IScriptHostFactory> scriptHostFactory,
                [NoAutoProperties] RoslynTestScriptEngine engine,
                ScriptPackSession scriptPackSession)
            {
                // Arrange
                const string Code = "var a = 0;";

                scriptHostFactory.Setup(f => f.CreateScriptHost(It.IsAny <IScriptPackManager>(), It.IsAny <string[]>()))
                .Returns <IScriptPackManager, string[]>((p, q) => new ScriptHost(p, new ScriptEnvironment(q)));

                var session = new SessionState <Session> {
                    Session = new ScriptEngine().CreateSession()
                };

                scriptPackSession.State[RoslynScriptEngine.SessionKey] = session;

                // Act
                engine.Execute(Code, new string[0], new AssemblyReferences(), Enumerable.Empty <string>(), scriptPackSession);

                // Assert
                engine.Session.ShouldEqual(session.Session);
            }
            public void ShouldAddReferenceToCore()
            {
                var engine = new RoslynTestScriptEngine(new Mock <IScriptHostFactory>().Object, new Mock <ILog>().Object);

                engine.Engine.GetReferences().Where(x => x.Display.EndsWith("ScriptCs.Core.dll")).Count().ShouldEqual(1);
            }
 public void ShouldAddReferenceToCore()
 {
     var engine = new RoslynTestScriptEngine(new Mock<IScriptHostFactory>().Object, new Mock<ILog>().Object);
     engine.Engine.GetReferences().Where(x => x.Display.EndsWith("ScriptCs.Core.dll")).Count().ShouldEqual(1);
 }