Пример #1
0
        public void RenderView_should_accept_a_model_with_a_list_and_iterate_over_it()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<ul>{% for item in Model.Items %}<li>{{ item.Name }}</li>{% endfor %}</ul>")
                );

            var currentStartupContext =
                CreateContext(new[] { location });

            this.engine.Initialize(currentStartupContext);
            var stream = new MemoryStream();

            // Construct the model for the View
            IList <Article> articles = new List <Article>()
            {
                new Article()
                {
                    Name = "Hello"
                },
                new Article()
                {
                    Name = "Jamie!"
                },
                new Article()
                {
                    Name = "You're fun!"
                }
            };

            Magazine menu = new Magazine()
            {
                Items = articles
            };

            // When
            var response = this.engine.RenderView(location, menu, this.renderContext);

            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<ul><li>Hello</li><li>Jamie!</li><li>You're fun!</li></ul>");
        }
        public void RenderView_should_accept_a_model_with_a_list_and_iterate_over_it()
        {
            // Given
            var location = new ViewLocationResult(
                string.Empty,
                string.Empty,
                "liquid",
                () => new StringReader(@"<ul>{% for item in Model.Items %}<li>{{ item.Name }}</li>{% endfor %}</ul>")
            );

            var currentStartupContext =
                CreateContext(new[] { location });

            this.engine.Initialize(currentStartupContext);
            var stream = new MemoryStream();

            // Construct the model for the View
            IList<Article> articles = new List<Article>() {
                new Article() {Name = "Hello"},
                new Article() {Name = "Jamie!"},
                new Article() {Name = "You're fun!"}
            };

            Magazine menu = new Magazine() { Items = articles };

            // When
            var response = this.engine.RenderView(location, menu, this.renderContext);
            response.Contents.Invoke(stream);

            // Then
            stream.ShouldEqual("<ul><li>Hello</li><li>Jamie!</li><li>You're fun!</li></ul>");
        }