public void TagSimpleElementParametersRender() { string content = "My favorite color is {0}"; string param = "color"; string tag = "x:Foo"; string val = "blue"; string template = "<script type='text/os-template' tag='{0}'>\n{1}</script>"; template = String.Format(template, tag, string.Format(content, "${My." + param + "}")); string elemInstMarkup = "<{0}><{1}>{2}</{1}></{0}>"; string tagInstanceMarkup = string.Format(elemInstMarkup, new string[] { tag, param, val }); string expected = string.Format(content, val); factory.RegisterCustomTag(tag, template); CustomTag inst = factory.CreateTagInstance(tag, tagInstanceMarkup); Assert.AreEqual(val, inst.Parameters[param], "Registered instance value incorrect"); string result = ControlTestHelper.GetRenderedContents(inst); result = ControlTestHelper.NormalizeRenderResult(result); Assert.AreEqual(expected, result, "Rendered results incorrect"); }
public void SetupCustomTag() { factory = new CustomTagFactory(ControlFactory.GetControlFactory(TEST_FACTORY_KEY)); Assert.IsTrue(0 == factory.CustomTags.Count); template = factory.RegisterCustomTag(CustomTagFactoryTests.CUSTOM_TAG, CustomTagFactoryTests.CUSTOM_TAG_TEMPLATE); Assert.IsTrue(1 == factory.CustomTags.Count); }
CustomTagFactory BuildInitTagFactoryWithTemplate() { CustomTagFactory factory = new CustomTagFactory(); factory.MyControlFactory = ControlFactory.GetControlFactory(TEST_FACTORY_KEY); RootElementMaster tmpMaster = new RootElementMaster(TEST_FACTORY_KEY); CustomTagTemplate tagTemplate = new CustomTagTemplate(); tagTemplate.MyRootMaster = tmpMaster; tagTemplate.LoadTag(CUSTOM_TAG_TEMPLATE); tagTemplate.OverrideInstanceMarkupTag("script"); factory.RegisterCustomTag(tagTemplate); return(factory); }
public void SuppressRenderClientSide() { CustomTagFactory factory = BuildInitTagFactoryWithTemplate(); MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); CustomTagTemplate template = factory.CustomTags[CUSTOM_TAG]; template.ClientRegister = false; factory.RenderClientTemplates(writer); writer.Flush(); string result = ControlTestHelper.GetStreamContent(stream); string templateDefinedTestString = CustomTagFactory.CLIENT_TEMPLATE_TAG_ATTRIBUTE + "=\"" + CUSTOM_TAG + "\""; Assert.IsTrue(-1 == result.IndexOf(templateDefinedTestString), "Client template incorrectly rendered" + result); }
public void DynamicDataElementParametersRender() { string name = "Yohan"; Person viewer = ControlTestHelper.CreatePerson(909, name, null); string content = "My Name is {0}"; string param = "thisPerson"; string mainPersonDataKey = "vwr"; //string instVariable = "${" + param string paramGet = param + ".displayName"; string tag = "x:Foo"; string template = "<script type='text/os-template' tag='{0}'>\n{1}</script>"; template = String.Format(template, tag, string.Format(content, "${My." + paramGet + "}")); string elemInstMarkup = "<{0}><{1}>{2}</{1}></{0}>"; string tagInstanceMarkup = string.Format(elemInstMarkup, new string[] { tag, param, "${" + mainPersonDataKey + "}" }); string expected = string.Format(content, name); factory.RegisterCustomTag(tag, template); DataContext dc = factory.MyRootMaster.MyDataContext; OsViewerRequest viewerReq = new OsViewerRequest(); viewerReq.Key = mainPersonDataKey; dc.RegisterDataItem(viewerReq); ResolveDataControlValues(dc, viewer, viewer, null); CustomTag inst = factory.CreateTagInstance(tag, tagInstanceMarkup); // Assert.AreEqual(name, inst.Parameters[param], "Registered instance value incorrect"); string result = ControlTestHelper.GetRenderedContents(inst); result = ControlTestHelper.NormalizeRenderResult(result); Assert.AreEqual(expected, result, "Rendered results incorrect"); }
public void TagTopVariableParametersRender() { string name = "Yohan"; Person viewer = ControlTestHelper.CreatePerson(909, name, null); string content = "My Name is {1} and my favorite color is {0}"; string param = "color"; string tag = "x:Foo"; string val = "blue"; string paramTop = "vwr.displayName"; //${Top.vwr.DisplayName} string template = "<script type='text/os-template' tag='{0}'>\n{1}</script>"; template = String.Format(template, tag, string.Format(content, "${My." + param + "}", "${Top." + paramTop + "}")); string elemInstMarkup = "<{0}><{1}>{2}</{1}></{0}>"; string tagInstanceMarkup = string.Format(elemInstMarkup, new string[] { tag, param, val }); string expected = string.Format(content, val, name); factory.RegisterCustomTag(tag, template); DataContext dc = factory.MyRootMaster.MyDataContext; ResolveDataControlValues(dc, viewer, viewer, null); OsViewerRequest viewerReq = new OsViewerRequest(); viewerReq.Key = "vwr"; dc.RegisterDataItem(viewerReq); ResolveDataControlValues(dc, viewer, viewer, null); CustomTag inst = factory.CreateTagInstance(tag, tagInstanceMarkup); Assert.AreEqual(val, inst.Parameters[param], "Registered instance value incorrect"); string result = ControlTestHelper.GetRenderedContents(inst); result = ControlTestHelper.NormalizeRenderResult(result); Assert.AreEqual(expected, result, "Rendered results incorrect"); }