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);
        }
Example #2
0
        public void MethodEchoWritesLog()
        {
            var services = new ServiceCollection();

            services.AddSingleton <IScriptsProvider, FakeScriptsProvider>();
            services.AddSingleton <IApplicationRuntime, WebApplicationEngine>();
            services.AddSingleton <IConfigurationRoot>(Mock.Of <Func <IServiceProvider, IConfigurationRoot> >());
            var fakeFS = new FakeScriptsProvider();

            fakeFS.Add("/main.os", "Сообщить(\"Я строка лога\")");
            services.AddSingleton <IScriptsProvider>(fakeFS);

            var loggerMock = new Mock <ILogger <ApplicationInstance> >();

            services.TryAddSingleton(loggerMock.Object);
            services.AddTransient <IApplicationFactory, AppStarter>();

            var provider = services.BuildServiceProvider();
            var starter  = provider.GetService <IApplicationFactory>();

            var app = starter.CreateApp();

            loggerMock.Verify(x =>
                              x.Log(
                                  LogLevel.Debug,
                                  It.IsAny <EventId>(),
                                  It.IsAny <object>(),
                                  null,
                                  It.IsAny <Func <object, Exception, string> >()),
                              Times.Once);
        }
        public void CheckThatActionsMappedToFunctions()
        {
            lock (TestOrderingLock.Lock)
            {
                string testControllerSrc = "Функция ВозвращающийМетод() Экспорт КонецФункции";

                var scriptsProvider = new FakeScriptsProvider();
                scriptsProvider.Add("/controllers/mycontroller.os", testControllerSrc);

                var result = CreateApplicationModel(scriptsProvider);

                Assert.Equal(1, result.Controllers[0].Actions.Count);
                Assert.Equal("ВозвращающийМетод", result.Controllers[0].Actions[0].ActionName);
                Assert.Equal("ResultAction", result.Controllers[0].Actions[0].ActionMethod.Name);
            }
        }
Example #4
0
        public void CheckIfOnlyExportedMethods_AreActions()
        {
            string testControllerSrc = "Процедура Метод1() Экспорт КонецПроцедуры\n" +
                                       "Процедура Метод2() КонецПроцедуры";

            var scriptsProvider = new FakeScriptsProvider();

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

            var result = CreateApplicationModel(scriptsProvider);

            Assert.Equal(1, result.Controllers.Count);
            Assert.Equal("ScriptedController", result.Controllers[0].ControllerType.Name);
            Assert.Equal("mycontroller", result.Controllers[0].ControllerName);

            Assert.Equal(1, result.Controllers[0].Actions.Count);
            Assert.Equal("Метод1", result.Controllers[0].Actions[0].ActionName);
        }
        private static ApplicationModel CreateApplicationModel(FakeScriptsProvider scriptsProvider)
        {
            var services = new ServiceCollection();

            services.TryAddSingleton <IScriptsProvider>(scriptsProvider);
            services.TryAddScoped <IHostingEnvironment>(x => new HostingEnvironment());
            services.AddOneScript();

            var serviceProvider = services.BuildServiceProvider();
            var modelProvider   = serviceProvider.GetService <IApplicationModelProvider>();

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

            modelProvider.OnProvidersExecuting(resultContainer);

            var result = resultContainer.Result;

            return(result);
        }
        public void CreateAppModelFromSDOTest()
        {
            lock (TestOrderingLock.Lock)
            {
                string testControllerSrc = "Процедура Метод1() Экспорт КонецПроцедуры";

                var scriptsProvider = new FakeScriptsProvider();
                scriptsProvider.Add("/controllers/mycontroller.os", testControllerSrc);

                var result = CreateApplicationModel(scriptsProvider);

                Assert.Equal(1, result.Controllers.Count);
                Assert.Equal("ScriptedController", result.Controllers[0].ControllerType.Name);
                Assert.Equal("mycontroller", result.Controllers[0].ControllerName);

                Assert.Equal(1, result.Controllers[0].Actions.Count);
                Assert.Equal("Метод1", result.Controllers[0].Actions[0].ActionName);
                Assert.Equal("VoidAction", result.Controllers[0].Actions[0].ActionMethod.Name);
            }
        }