Example #1
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 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));
        }
        public void CheckThatRoutesAreRegisteredInHandler()
        {
            var services = MockMvcServices();

            services.AddSingleton(Mock.Of <IConfiguration>());
            services.AddSingleton(Mock.Of <ILogger <ApplicationInstance> >());

            var provider = services.BuildServiceProvider();
            var fakeFS   = (InMemoryFileProvider)provider.GetService <IFileProvider>();

            fakeFS.AddFile("main.os", "Перем ТестМаршруты Экспорт;\n" +
                           "Процедура ПриНачалеРаботыСистемы()\n" +
                           "    ИспользоватьМаршруты(\"РегистрацияМаршрутов\");" +
                           "КонецПроцедуры\n" +
                           "\n" +
                           "Процедура РегистрацияМаршрутов(КоллекцияМаршрутов) Экспорт\n" +
                           "    ТестМаршруты = КоллекцияМаршрутов\n" +
                           "КонецПроцедуры");

            var webApp        = provider.GetService <IApplicationRuntime>();
            var app           = ApplicationInstance.Create(new FileInfoCodeSource(fakeFS.GetFileInfo("main.os")), webApp);
            var mvcAppBuilder = new Mock <IApplicationBuilder>();

            mvcAppBuilder.SetupGet(x => x.ApplicationServices).Returns(provider);

            app.OnStartup(mvcAppBuilder.Object);

            int propIndex       = app.FindProperty("ТестМаршруты");
            var routeCollection = app.GetPropValue(propIndex);

            Assert.IsType <RoutesCollectionContext>(routeCollection);
        }
        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);
        }
        public void CheckThatRoutesAreRegisteredInHandler()
        {
            lock (TestOrderingLock.Lock)
            {
                var services = MockMvcServices();

                var provider = services.BuildServiceProvider();
                var fakeFS   = (FakeScriptsProvider)provider.GetService <IScriptsProvider>();
                fakeFS.Add("/main.os", "Перем ТестМаршруты Экспорт;\n" +
                           "Процедура ПриНачалеРаботыСистемы()\n" +
                           "    ИспользоватьМаршруты(\"РегистрацияМаршрутов\");" +
                           "КонецПроцедуры\n" +
                           "\n" +
                           "Процедура РегистрацияМаршрутов(КоллекцияМаршрутов) Экспорт\n" +
                           "    ТестМаршруты = КоллекцияМаршрутов\n" +
                           "КонецПроцедуры");

                var webApp        = provider.GetService <IApplicationRuntime>();
                var app           = ApplicationInstance.Create(fakeFS.Get("/main.os"), webApp);
                var mvcAppBuilder = new Mock <IApplicationBuilder>();
                mvcAppBuilder.SetupGet(x => x.ApplicationServices).Returns(provider);

                app.OnStartup(mvcAppBuilder.Object);

                int propIndex       = app.FindProperty("ТестМаршруты");
                var routeCollection = app.GetPropValue(propIndex);
                Assert.IsType <RoutesCollectionContext>(routeCollection);
            }
        }
        public ApplicationInstance CreateApp()
        {
            var codeSrc = _scripts.Get("/main.os");

            _webEng.Environment.InjectObject(new WebGlobalContext(this, codeSrc));
            _webEng.Engine.UpdateContexts();

            return(ApplicationInstance.Create(codeSrc, _webEng));
        }
        public ApplicationInstance CreateApp()
        {
            var codeSrc = new FileInfoCodeSource(_scripts.GetFileInfo("main.os"));

            _webEng.Environment.InjectObject(new WebGlobalContext(this, codeSrc, _webEng));

            var templateFactory = new DefaultTemplatesFactory();

            var storage = new TemplateStorage(templateFactory);

            _webEng.Environment.InjectObject(storage);
            _webEng.Engine.UpdateContexts();
            GlobalsManager.RegisterInstance(storage);

            return(ApplicationInstance.Create(codeSrc, _webEng));
        }
Example #8
0
        public void CheckThatAppMethodsAreCalled()
        {
            var services = MockMvcServices();

            var provider = services.BuildServiceProvider();
            var fakeFS   = (FakeScriptsProvider)provider.GetService <IScriptsProvider>();

            fakeFS.Add("/main.os", "Процедура ПриНачалеРаботыСистемы()\n" +
                       "    ИспользоватьСтатическиеФайлы();\n" +
                       "    ИспользоватьМаршруты();\n" +
                       "    ИспользоватьСессии()" +
                       "КонецПроцедуры");

            var webApp        = provider.GetService <IApplicationRuntime>();
            var app           = ApplicationInstance.Create(fakeFS.Get("/main.os"), webApp);
            var mvcAppBuilder = new Mock <IApplicationBuilder>();

            mvcAppBuilder.SetupGet(x => x.ApplicationServices).Returns(provider);

            app.OnStartup(mvcAppBuilder.Object);
            mvcAppBuilder.Verify(x => x.Use(It.IsAny <Func <RequestDelegate, RequestDelegate> >()), Times.Exactly(3));
        }
        public void CheckThatAppMethodsAreCalled()
        {
            var services = MockMvcServices();

            services.AddSingleton(Mock.Of <IConfiguration>());
            services.AddSingleton(Mock.Of <ILogger <ApplicationInstance> >());

            var provider = services.BuildServiceProvider();
            var fakeFS   = (InMemoryFileProvider)provider.GetService <IFileProvider>();

            fakeFS.AddFile("main.os", "Процедура ПриНачалеРаботыСистемы()\n" +
                           "    ИспользоватьСтатическиеФайлы();\n" +
                           "    ИспользоватьСессии();" +
                           "КонецПроцедуры");

            var webApp        = provider.GetService <IApplicationRuntime>();
            var app           = ApplicationInstance.Create(new FileInfoCodeSource(fakeFS.GetFileInfo("main.os")), webApp);
            var mvcAppBuilder = new Mock <IApplicationBuilder>();

            mvcAppBuilder.SetupGet(a => a.ApplicationServices).Returns(provider);

            app.OnStartup(mvcAppBuilder.Object);
            mvcAppBuilder.Verify(x => x.Use(It.IsAny <Func <RequestDelegate, RequestDelegate> >()), Times.Exactly(2));
        }
Example #10
0
        public ApplicationInstance CreateApp()
        {
            var codeSrc = _scripts.Get("/main.os");

            return(ApplicationInstance.Create(codeSrc, _webEng));
        }