public async Task TestMultiLangImport() { var resourceExplorer = new ResourceExplorer().LoadProject(GetProjectFolder(), monitorChanges: false); // use LG file as entrance var lgResourceGroup = LGResourceLoader.GroupByLocale(resourceExplorer); var resource = resourceExplorer.GetResource("a.en-US.lg") as FileResource; var generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup); var result = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null); Assert.AreEqual("from a.en-us.lg", result); // import b.en-us.lg result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null); Assert.AreEqual("from b.en-us.lg", result); // fallback to c.en.lg result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null); Assert.AreEqual("from c.en.lg", result); // there is no 'greeting' template in b.en-us.lg, no more fallback to b.lg var ex = await Assert.ThrowsExceptionAsync <Exception>(async() => await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null)); Assert.IsTrue(ex.Message.Contains("greeting does not have an evaluator")); resource = resourceExplorer.GetResource("a.lg") as FileResource; generator = new TemplateEngineLanguageGenerator(resource.FullName, lgResourceGroup); result = await generator.GenerateAsync(GetDialogContext(), "${templatea()}", null); Assert.AreEqual("from a.lg", result); result = await generator.GenerateAsync(GetDialogContext(), "${templateb()}", null); Assert.AreEqual("from b.lg", result); // ignore the "en" in c.en.lg, just load c.lg result = await generator.GenerateAsync(GetDialogContext(), "${templatec()}", null); Assert.AreEqual("from c.lg", result); result = await generator.GenerateAsync(GetDialogContext(), "${greeting()}", null); Assert.AreEqual("hi", result); }
public async Task TestNotFoundTemplate() { var context = GetDialogContext(string.Empty); var lg = new TemplateEngineLanguageGenerator(); await lg.GenerateAsync(context, "${tesdfdfsst()}", null); }
public async Task TestNotFoundTemplate() { var context = GetDialogContext(string.Empty); var lg = new TemplateEngineLanguageGenerator(); await Assert.ThrowsAsync <InvalidOperationException>(() => lg.GenerateAsync(context, "${tesdfdfsst()}", null)); }