示例#1
0
        public void CollectionWithComplexTypeThrowsDuringRenderingTest(Type complexType)
        {
            ViewEngine engine = ViewEngineSetup.SetupViewEngine("<ul>@Model.Collection.Collection(<li>@Item</li>)</ul>");

            object[] complexObjectCollection = { Activator.CreateInstance(complexType) };

            Dictionary <string, object> propertyBag = new Dictionary <string, object>
            {
                ["Collection"] = complexObjectCollection
            };

            Assert.That(() => engine.RenderView(string.Empty, string.Empty, propertyBag), Throws.ArgumentException);
        }
示例#2
0
        public void CollectionRenderingTest(params object[] collection)
        {
            ViewEngine engine = ViewEngineSetup.SetupViewEngine("<ul>@Model.Collection.Collection(<li>@Item</li>)</ul>");

            Dictionary <string, object> propertyBag = new Dictionary <string, object>
            {
                ["Collection"] = collection
            };

            string renderedView = engine.RenderView(string.Empty, string.Empty, propertyBag);

            Assert.That(renderedView, Is.EqualTo($"<ul>{string.Concat(collection.Select(item => $"<li>{item}</li>"))}</ul>"));
        }
示例#3
0
        public void NullPrimitiveValueRenderingTest()
        {
            ViewEngine viewEngine = ViewEngineSetup.SetupViewEngine("<h1>@Model.Value</h1>");

            Dictionary <string, object> propertyBag = new Dictionary <string, object>
            {
                ["Value"] = null
            };

            string renderedHtml = viewEngine.RenderView(string.Empty, string.Empty, propertyBag);

            Assert.That(renderedHtml, Is.EqualTo("<h1>null</h1>"));
        }
示例#4
0
        public void TestRenderError(string error)
        {
            ViewEngine viewEngine = ViewEngineSetup.SetupViewEngine(viewPath =>
            {
                if (viewPath.EndsWith("_Layout.html"))
                {
                    return("<html><head></head><body>@Error()</body></html>");
                }

                if (viewPath.EndsWith("_Error.html"))
                {
                    return("<h1>@Error</h1>");
                }

                throw new NotSupportedException("View path has unsupported ending");
            });

            Assert.That(viewEngine.RenderError(error), Is.EqualTo($"<html><head></head><body><h1>{error}</h1></body></html>"));
        }
示例#5
0
        public void CorrectBodyReplacementRenderingTest(string value)
        {
            ViewEngine engine = ViewEngineSetup.SetupViewEngine(viewPath =>
            {
                if (viewPath.EndsWith("_Layout.html"))
                {
                    return("<html><head></head><body>@Body()</body>");
                }

                return("<h1>@Model.Value</h1>");
            });

            Dictionary <string, object> propertyBag = new Dictionary <string, object>
            {
                ["Value"] = value
            };

            string renderedHtml = engine.RenderView(string.Empty, string.Empty, propertyBag);

            Assert.That(renderedHtml, Is.EqualTo($"<html><head></head><body><h1>{value}</h1></body>"));
        }
示例#6
0
        public void ComplexTypeRenderingTest(string title, string type, int count)
        {
            ViewEngine engine = ViewEngineSetup.SetupViewEngine(viewPath =>
            {
                if (viewPath.EndsWith("DisplayTemplate.html"))
                {
                    return("<div><h1>@Model.Title</h1><hr/><hr/><h2>@Model.Type</h2><h2>@Model.Count</h2><div>@Model.SomeOtherProperty</div></div>");
                }

                return("<section>@Model.Value</section>");
            });

            Dictionary <string, object> propertyBag = new Dictionary <string, object>
            {
                ["Value"] = new ComplexType(title, type, count)
            };

            string renderedHtml = engine.RenderView(string.Empty, string.Empty, propertyBag);

            Assert.That(renderedHtml, Is.EqualTo($"<section><div><h1>{title}</h1><hr/><hr/><h2>{type}</h2><h2>{count}</h2><div>null</div></div></section>"));
        }