Ejemplo n.º 1
0
 public InjectionApi(IApiBridge bridge, Metadata metadata, Globals globals, ITimeSource timeSource, Paths paths, Objects objects)
 {
     this.bridge = bridge;
     UO          = new InjectionApiUO(bridge, this, metadata, globals, timeSource, paths, objects);
     Register(metadata);
     this.timeSource = timeSource;
 }
Ejemplo n.º 2
0
 public InjectionApi(IApiBridge bridge, Metadata metadata, InjectionRuntimeState state, ITimeSource timeSource, Paths paths)
 {
     this.bridge = bridge;
     UO          = new InjectionApiUO(bridge, this, metadata, state, timeSource, paths);
     Register(metadata);
     this.timeSource = timeSource;
 }
Ejemplo n.º 3
0
 internal InjectionApiUO(IApiBridge bridge, InjectionApi injectionApi, Metadata metadata, Globals globals, ITimeSource timeSource)
 {
     this.bridge       = bridge;
     this.injectionApi = injectionApi;
     this.globals      = globals;
     Register(metadata);
     random          = new Random();
     this.timeSource = timeSource;
 }
Ejemplo n.º 4
0
 public void Setup()
 {
     IOC.Reset();
     lua       = new Lua();
     apiBridge = Mock.Interface <IApiBridge>();
     IOC.Register <IApiBridge>(() => apiBridge);
     IOC.Register <Lua>(() => lua);
     IOC.Register <ApiAdapter>(() => new ApiAdapter());
 }
Ejemplo n.º 5
0
 public void Setup()
 {
     IOC.Reset();
     lua       = new Lua();
     luaEnv    = lua.CreateEnvironment();
     apiBridge = Mock.Interface <IApiBridge>();
     IOC.Register <IApiBridge>(() => apiBridge);
     IOC.Register <ApiAdapter>(() => new ApiAdapter());
     api        = IOC.Resolve <ApiAdapter>();
     api.LuaEnv = luaEnv;
 }
Ejemplo n.º 6
0
        public InjectionRuntime(IApiBridge bridge, IDebuggerServer debuggerServer, ITimeSource timeSource, Func <CancellationToken?> retrieveCancellationToken)
        {
            paths = new Paths(() => Path.GetDirectoryName(CurrentScript.FileName));

            Api = new InjectionApi(bridge, Metadata, State, timeSource, paths);
            RegisterNatives();
            this.bridge                    = bridge;
            this.debuggerServer            = debuggerServer;
            this.timeSource                = timeSource;
            this.retrieveCancellationToken = retrieveCancellationToken;

            CurrentScript = new ScriptFile("<empty>", string.Empty, null);
            interpreter   = new ThreadLocal <Interpreter>(()
                                                          => new Interpreter(Metadata, CurrentScript.FileName, debuggerServer.Create(), retrieveCancellationToken));
        }
Ejemplo n.º 7
0
        public void Run_FullTestCase()
        {
            IOC.Reset();
            lua       = new Lua();
            apiBridge = new DefaultApiBridge();
            IOC.Register <IApiBridge>(() => apiBridge);
            IOC.Register <ITestEnvironment>(() => new TestEnvironment());
            IOC.Register <ITestContext>(() => new MutagenRuntime.TestContext());
            IOC.Register <Lua>(() => lua);
            IOC.Register <ApiAdapter>(() => new ApiAdapter());


            var tc   = NUnit.Framework.TestContext.CurrentContext.TestDirectory;
            var strm = System.IO.File.OpenRead(tc + "./LuaScripts/FullTestCase.lua");

            runner = new ScriptRunner();
            IOC.ResolveImports(runner);

            // Black Magic: NUnit sets the working dir to a crappy place,
            // so we're shit out of luck, if we try to access a file relative to
            // our working dir. To get around this problem we magic the correct
            // path here and reset the working directory to reflect this:
            var dir = AppDomain.CurrentDomain.BaseDirectory;

            Environment.CurrentDirectory = dir;

            runner.Load(strm);

            runner.Run();

            var results = Api.GetResults();

            Assert.AreEqual(6, results.Count);
            var harness = Api.Testharness() as SimpleHarness;

            Assert.AreEqual("fnord", harness.lastPrint);
        }
Ejemplo n.º 8
0
 public InjectionRuntime(IApiBridge bridge, IDebuggerServer debuggerServer, ITimeSource timeSource)
 {
     interpreter = new ThreadLocal <Interpreter>(() => new Interpreter(Metadata, CurrentFileName, debuggerServer.Create()));
     Api         = new InjectionApi(bridge, Metadata, Globals, timeSource);
     RegisterNatives();
 }