public void CheckIfControllerThisObjectAccessible()
        {
            var fakefs = new InMemoryFileProvider();

            fakefs.AddFile("controllers/test.os", "Процедура Б() А = ЭтотОбъект; КонецПроцедуры");
            fakefs.AddFile("main.os", "");
            var appEngine = new WebApplicationEngine();
            var app       = ApplicationInstance.Create(new FileInfoCodeSource(fakefs.GetFileInfo("main.os")), appEngine);
            var provider  = new OscriptApplicationModelProvider(app, appEngine, fakefs, Mock.Of <IAuthorizationPolicyProvider>());

            var context = new ApplicationModelProviderContext(new TypeInfo[0]);

            provider.OnProvidersExecuting(context);

            var cc = new ControllerContext();
            var ad = new ControllerActionDescriptor();

            ad.Properties["type"]            = context.Result.Controllers[0].Properties["type"];
            ad.Properties["CompilationInfo"] = context.Result.Controllers[0].Properties["CompilationInfo"];
            cc.ActionDescriptor    = ad;
            cc.HttpContext         = new DefaultHttpContext();
            cc.HttpContext.Session = null;

            var activator  = new ScriptedControllerActivator(appEngine);
            var controller = (ScriptedController)activator.Create(cc);

            Assert.Equal(controller, controller.GetPropValue(0));
        }
Пример #2
0
        public void CheckIfControllerCreatedFromScript()
        {
            var fakefs = new FakeScriptsProvider();

            fakefs.Add("/controllers/test.os", "");
            fakefs.Add("/main.os", "");
            var appEngine = new WebApplicationEngine();
            var app       = ApplicationInstance.Create(fakefs.Get("/main.os"), appEngine);
            var provider  = new OscriptApplicationModelProvider(app, appEngine, fakefs);

            var context = new ApplicationModelProviderContext(new TypeInfo[0]);

            provider.OnProvidersExecuting(context);

            var cc = new ControllerContext();
            var ad = new ControllerActionDescriptor();

            ad.Properties["type"]   = context.Result.Controllers[0].Properties["type"];
            ad.Properties["module"] = context.Result.Controllers[0].Properties["module"];
            cc.ActionDescriptor     = ad;
            cc.HttpContext          = new DefaultHttpContext();
            cc.HttpContext.Session  = null;

            var activator  = new ScriptedControllerActivator(appEngine);
            var controller = (ScriptedController)activator.Create(cc);

            Assert.Equal("test", controller.SystemType.Name);
        }
        public void CheckIfControllerCreatedFromScript()
        {
            var fakefs = new InMemoryFileProvider();

            fakefs.AddFile("controllers/test.os", "");
            fakefs.AddFile("main.os", "");
            var appEngine = new WebApplicationEngine();
            var app       = ApplicationInstance.Create(new FileInfoCodeSource(fakefs.GetFileInfo("main.os")), appEngine);
            var provider  = new OscriptApplicationModelProvider(app, appEngine, fakefs, Mock.Of <IAuthorizationPolicyProvider>());

            var context = new ApplicationModelProviderContext(new TypeInfo[0]);

            provider.OnProvidersExecuting(context);

            var cc = new ControllerContext();
            var ad = new ControllerActionDescriptor();

            ad.Properties["type"]   = context.Result.Controllers[0].Properties["type"];
            ad.Properties["module"] = context.Result.Controllers[0].Properties["module"];
            cc.ActionDescriptor     = ad;
            cc.HttpContext          = new DefaultHttpContext();
            cc.HttpContext.Session  = null;

            var activator  = new ScriptedControllerActivator(appEngine);
            var controller = (ScriptedController)activator.Create(cc);

            Assert.Equal("Контроллер.test", controller.SystemType.Name);
        }
Пример #4
0
        public void TestAppModelFromSDO()
        {
            string testControllerSrc = "Процедура Метод1() КонецПроцедуры";

            var scriptsProvider = new FakeScriptsProvider();

            scriptsProvider.Add("/controllers/mycontroller.os", testControllerSrc);

            var factory  = new OneScriptScriptFactory(scriptsProvider);
            var provider = new OscriptApplicationModelProvider(factory);

            var types           = new TypeInfo[0];
            var resultContainer = new ApplicationModelProviderContext(types);

            provider.OnProvidersExecuted(resultContainer);

            var result = resultContainer.Result;

            Assert.AreEqual(1, result.Controllers.Count);
            Assert.AreEqual(1, result.Controllers[0]);
            Assert.AreEqual("mycontroller", result.Controllers[0].ControllerName);
        }