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 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("/main.os", ""); 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); } }
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); }
public void CreateAppModelFromSDOTest() { lock (TestOrderingLock.Lock) { string testControllerSrc = "Процедура Метод1() Экспорт КонецПроцедуры"; 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); Assert.Equal("VoidAction", result.Controllers[0].Actions[0].ActionMethod.Name); } }