Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Tests the rendered results against expected output.
        /// Trims to remove leading and trailing whitespace
        /// </summary>
        /// <param name="control"></param>
        /// <param name="expectedResult"></param>
        /// <returns></returns>
        public bool AssertRenderResultsEqual(BaseGadgetControl control, string expectedResult)
        {
            string result = ControlTestHelper.GetRenderedContents(control);

            result         = ControlTestHelper.NormalizeRenderResult(result);
            expectedResult = ControlTestHelper.NormalizeRenderResult(expectedResult);
            return(result == expectedResult);
        }
Exemplo n.º 3
0
        public void TestRenderStaticTag()
        {
            CustomTag inst = factory.CreateTagInstance(CustomTagFactoryTests.CUSTOM_TAG);

            string result = ControlTestHelper.GetRenderedContents(inst);

            Assert.AreEqual(CustomTagFactoryTests.CUSTOM_TAG_RESULT, result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Helper to check the rendered results
        /// </summary>
        /// <param name="gadget"></param>
        void TestRepeaterRenderResult(DataGadgetTestData gadget)
        {
            GadgetMaster master = null;

            master = GadgetMaster.CreateGadget(TEST_FACTORY_KEY, gadget.Source);
            master.RenderingOptions.DivWrapContentBlocks = false;
            ResolveDataControlValues(master.MyDataContext, gadget.ExpectedViewer, gadget.ExpectedViewer, gadget.ExpectedFriends);

            string result   = ControlTestHelper.GetRenderedContents(master, "canvas");
            string expected = gadget.ExpectedCanvas.Trim().Replace("\r\n", "\n");

            Assert.AreEqual(ControlTestHelper.NormalizeRenderResult(expected), ControlTestHelper.NormalizeRenderResult(result), "Rendered results incorrect");
        }
Exemplo n.º 5
0
        public void LiteralsWithCDataHonored(string raw, bool suppressCDATA, string expected)
        {
            GadgetLiteral control = new GadgetLiteral(raw);

            Assert.AreEqual(raw, control.RawTag);
            Assert.AreEqual(raw, control.InnerMarkup);

            control.SuppressCDATATags = suppressCDATA;
            string rendered = ControlTestHelper.NormalizeRenderResult(
                ControlTestHelper.GetRenderedContents(control));

            expected = ControlTestHelper.NormalizeRenderResult(expected);

            Assert.AreEqual(expected, rendered, "Rendered results do not match expectations");
        }
Exemplo n.º 6
0
        public void TestContentRenderTrailingScript()
        {
            ContentBlockTrailingClientScript testContent = new ContentBlockTrailingClientScript();
            GadgetMaster master = new GadgetMaster(testFactory);
            ContentBlock block  = new ContentBlock();

            master.AddContentBlock(block);
            block.LoadTag(testContent.Source);
            block.IncludeWrappingDivs = false;

            string tagRendered = ControlTestHelper.NormalizeRenderResult(ControlTestHelper.GetRenderedContents(block));

            Assert.IsTrue(tagRendered.Length > 0, "Empty rendered tag from content");
            Assert.AreEqual(ControlTestHelper.NormalizeRenderResult(testContent.ExpectedCanvas), tagRendered);
        }
Exemplo n.º 7
0
        public void RenderCustomTagWithClientTemplateIncluded()
        {
            GadgetMaster           target;
            TemplateGadgetTestData gadget = new TemplateGadgetTestData();

            target = new GadgetMaster(testFactory, gadget.Source);
            AccountTestData.ResolveDataControlValues(target.MyDataContext, GadgetTestData.Viewer, GadgetTestData.Viewer, null);

            target.RenderingOptions.DivWrapContentBlocks = false;
            target.RenderingOptions.SuppressWhitespace   = true;
            target.ClientRenderCustomTemplates           = true;

            string written = ControlTestHelper.GetRenderedContents(target, "canvas");

            Assert.IsTrue(written.IndexOf(TemplateGadgetTestData.CUSTOM_TAG_CONTENTS) > -1, "Client template not found");
        }
Exemplo n.º 8
0
        public void TestRenderCustomTag()
        {
            GadgetMaster           target;
            TemplateGadgetTestData gadget = new TemplateGadgetTestData();

            target = new GadgetMaster(testFactory, gadget.Source);
            AccountTestData.ResolveDataControlValues(target.MyDataContext, GadgetTestData.Viewer, GadgetTestData.Viewer, null);

            target.RenderingOptions.DivWrapContentBlocks = false;
            target.RenderingOptions.SuppressWhitespace   = true;

            string written = ControlTestHelper.GetRenderedContents(target, "canvas");

            written = written.Trim();
            string expected = gadget.ExpectedCanvas.Trim();

            Assert.AreEqual(expected, written, "Canvas does not match");
        }
Exemplo n.º 9
0
        public void TestSurfaceViewRender(string source, string surfaceName, string expected)
        {
            GadgetMaster target;

            target = new GadgetMaster(testFactory, source);
            target.RenderingOptions.DivWrapContentBlocks   = false;
            target.RenderingOptions.DivWrapContentSubViews = false;
            AccountTestData.ResolveDataControlValues(target.MyDataContext, GadgetTestData.Viewer, GadgetTestData.Viewer, null);

            string written = ControlTestHelper.GetRenderedContents(target, surfaceName);

            expected = ControlTestHelper.NormalizeRenderResult(expected);
            written  = ControlTestHelper.NormalizeRenderResult(written);

            Assert.AreEqual(expected.Length, written.Length, "Lengths do not match");

            Assert.AreEqual(expected, written, "Rendered gadget not expected from view: [" + surfaceName + "]\nEXPECTED:\n" + expected + "\n\nWRITTEN:\n" + written);
        }
Exemplo n.º 10
0
        public void TestRenderOptions()
        {
            GadgetMaster target;
            SuppressedWhitespaceAndDivGadget gadget = new SuppressedWhitespaceAndDivGadget();

            target = new GadgetMaster(testFactory, gadget.Source);
            AccountTestData.ResolveDataControlValues(target.MyDataContext, GadgetTestData.Viewer, GadgetTestData.Viewer, null);

            target.RenderingOptions.DivWrapContentBlocks = false;
            target.RenderingOptions.SuppressWhitespace   = true;

            string written = ControlTestHelper.GetRenderedContents(target, "canvas");

            Assert.AreEqual(gadget.ExpectedCanvas, written, "Canvas does not match");

            written = ControlTestHelper.GetRenderedContents(target, "profile");

            Assert.AreEqual(gadget.ExpectedProfile, written, "Profile does not match");
        }
Exemplo n.º 11
0
        public void CustomTagTemplateRegistered()
        {
            ContentBlock target;
            TagTemplateContentBlockTestData data = new TagTemplateContentBlockTestData();


            GadgetMaster master = new GadgetMaster(testFactory);

//			master.MyDataContext.Viewer = GadgetTestData.Viewer;
            target = new ContentBlock(data.Source, master);

            OffsetItem offset = target.MyOffset;

            Assert.AreEqual(2, offset.ChildOffsets.Count);
            Assert.AreEqual(new OsTagTemplate().OffsetKey, offset.ChildOffsets[0].OffsetKey);

            string written = ControlTestHelper.GetRenderedContents(target);

            Assert.IsTrue(written.Length > 0);
        }
Exemplo n.º 12
0
        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");
        }
Exemplo n.º 13
0
        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");
        }
Exemplo n.º 14
0
        public void RepeaterGadgetTest()
        {
            DataGadgetTestData gadget = null;
            GadgetMaster       target = null;
            MemoryStream       stream = null;
            StreamWriter       writer = null;

            stream = new MemoryStream();
            writer = new StreamWriter(stream);

            gadget = new DataGadgetTestData();
            target = new GadgetMaster(testFactory, gadget.Source);


            target.RenderingOptions.DivWrapContentBlocks = false;
            ResolveDataControlValues(target.MyDataContext, gadget.ExpectedViewer, gadget.ExpectedViewer, gadget.ExpectedFriends);
            string written = ControlTestHelper.GetRenderedContents(target, "canvas");

            written = written.Trim();
            string expected = gadget.ExpectedCanvas.Trim();

            Assert.AreEqual(expected, written, "Repeater canvas does not match");
        }