private HttpResponse ViewByName <T>(string viewPath, object viewModel)
        {
            IViewEngine viewEngine = new ViewEngine();
            var         html       = File.ReadAllText(viewPath);

            html = viewEngine.GetHtml(html, viewModel);

            var layout         = File.ReadAllText("Views/Shared/_Layout.html");
            var bodyWithLayout = layout.Replace("@RenderBody()", html);

            bodyWithLayout = viewEngine.GetHtml(bodyWithLayout, viewModel);
            return(new HtmlResponse(bodyWithLayout));
        }
Beispiel #2
0
        public void TestWithoutViewModel(string folderName)
        {
            string path = FolderPath + folderName;

            string input          = FileReader.ReadAllText(path + "ImputData.html");
            string expectedResult = FileReader.ReadAllText(path + "ResultData.html");

            IViewEngine viewEngine = new ViewEngine();

            string actualResult = viewEngine.GetHtml(input, null, null);

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #3
0
        public void TestWithViewModel()
        {
            string path = FolderPath + "Test5/";

            string input          = FileReader.ReadAllText(path + "ImputData.html");
            string expectedResult = FileReader.ReadAllText(path + "ResultData.html");

            IViewEngine viewEngine = new ViewEngine();

            var viewModel = new MockClass1("*****@*****.**", "Gosho", 20);

            string actualResult = viewEngine.GetHtml(input, viewModel, null);

            Assert.Equal(expectedResult, actualResult);
        }
Beispiel #4
0
        public void TestGetHtmlWithGenericTemplateModel()
        {
            var viewModel = new Dictionary <string, Dictionary <string, int> >()
            {
                {
                    "Pesho",
                    new Dictionary <string, int>
                    {
                        { "C# Basics", 100 }, { "C# Web", 75 },
                    }
                },
                {
                    "Gosho",
                    new Dictionary <string, int>
                    {
                        { "JavaScript Advanced", 30 }, { "PHP Web", 50 },
                    }
                }
            };

            var         viewContent           = @"
@foreach (var student in Model)
{
<p> User: @student.Key </p>
<ul>
@foreach (var course in student.Value)
{
<li> @course.Key -> @course.Value </li>
}
</ul>
}";
            var         expectedResultContent = @"
<p> User: Pesho </p>
<ul>
<li> C# Basics -> 100 </li>
<li> C# Web -> 75 </li>
</ul>
<p> User: Gosho </p>
<ul>
<li> JavaScript Advanced -> 30 </li>
<li> PHP Web -> 50 </li>
</ul>
";
            IViewEngine viewEngine            = new ViewEngine();
            var         actualResult          = viewEngine.GetHtml(viewContent, viewModel, null);

            Assert.Equal(expectedResultContent, actualResult);
        }
        public void GetHtmlTest(string testName)
        {
            var viewModel = new TestViewModel()
            {
                Name    = "Niki",
                Year    = 2020,
                Numbers = new int[] { 1, 10, 100, 1000, 10000 }
            };

            var viewContent           = File.ReadAllText($"ViewTests/{testName}.html");
            var expectedResultContent = File.ReadAllText($"ViewTests/{testName}.Expected.html");

            IViewEngine viewEngine   = new ViewEngine();
            var         actualResult = viewEngine.GetHtml(viewContent, viewModel);

            Assert.Equal(expectedResultContent, actualResult);
        }
Beispiel #6
0
        public static void Main()
        {
            var viewEngine = new ViewEngine();
            var people     = new List <Person>
            {
                new Person {
                    FirstName = "Nikolay", LastName = "Kostov"
                },
                new Person {
                    FirstName = "Viktor", LastName = "Dakov"
                },
                new Person {
                    FirstName = "Ivaylo", LastName = "Kenov"
                },
            };
            var html = viewEngine.GetHtml(File.ReadAllText("Details.html"), people);

            Console.WriteLine(html);
        }
        public void TestGetHtml(string testName)
        {
            TestViewModel viewModel = new TestViewModel()
            {
                Name    = "Niki",
                Year    = 2020,
                Numbers = new List <int> {
                    1, 10, 100, 1000, 10000
                },
            };

            string viewContent           = File.ReadAllText($"ViewTests/{testName}.html");
            string expectedResultContent = File.ReadAllText($"ViewTests/{testName}.Expected.html");

            IViewEngine viewEngine   = new ViewEngine();
            string      actualResult = viewEngine.GetHtml(viewContent, viewModel, "123");

            Assert.Equal(expectedResultContent, actualResult);
        }
Beispiel #8
0
        public void GetHtmlTest(string viewName)
        {
            var viewModel = new TestViewModel()
            {
                Name    = "Kiro",
                Year    = 2020,
                Numbers = new List <int> {
                    1, 10, 100, 1000, 10000
                },
            };

            var testContent     = File.ReadAllText($"ViewTests/{viewName}.html");
            var expectedContent = File.ReadAllText($"ViewTests/{viewName}.Expected.html");

            IViewEngine viewEngine   = new ViewEngine();
            var         actualResult = viewEngine.GetHtml(testContent, viewModel);

            Assert.Equal(expectedContent, actualResult);
        }
        public void GetHtmlTest(string testName)
        {
            var viewModel = new TestViewModel()
            {
                Name    = "Petroslav",
                Year    = 2021,
                Numbers = new List <int> {
                    1, 10, 100, 1000, 10000
                }
            };

            var viewContent    = File.ReadAllText($"ViewTests/{testName}.html");
            var expectedResult = File.ReadAllText($"ViewTests/{testName}Expected.html");

            IViewEngine viewEngine   = new ViewEngine();
            var         actualResult = viewEngine.GetHtml(viewContent, viewModel, "123");

            ;
            Assert.Equal(expectedResult, actualResult);
        }
        public void TestGetHtmlWithTemplateModel()
        {
            List <int> viewModel = new List <int> {
                1, 2, 3
            };

            string      viewContent           = @"
@foreach (var num in Model)
{
<p>@num</p>
}";
            string      expectedResultContent = @"
<p>1</p>
<p>2</p>
<p>3</p>
";
            IViewEngine viewEngine            = new ViewEngine();
            string      actualResult          = viewEngine.GetHtml(viewContent, viewModel, null);

            Assert.Equal(expectedResultContent, actualResult);
        }
        public void TestGetHtml()
        {
            var viewModel = new List <int> {
                1, 2, 3
            };

            var viewContent    = @"@foreach(var num in Model)
{
<p>@num</p>
}";
            var expectedResult = @"
<p>1</p>
<p>2</p>
<p>3</p>
";

            IViewEngine viewEngine   = new ViewEngine();
            var         actualResult = viewEngine.GetHtml(viewContent, viewModel, null);

            ;
            Assert.Equal(expectedResult, actualResult);
        }
        public void TestGetHtml(string testName)
        {
            var viewModel = new TestViewModel()
            {
                Name    = "Niki",
                Year    = 2020,
                Numbers = new List <int> {
                    1, 10, 100, 1000, 10000
                },
            };

            var viewContent           = File.ReadAllText($"ViewTests/{testName}.html");
            var expectedResultContent = File.ReadAllText($"ViewTests/{testName}.Expected.html");

            IViewEngine viewEngine   = new ViewEngine();
            var         actualResult = viewEngine.GetHtml(viewContent, viewModel);

            if (actualResult.StartsWith("\ufeff"))
            {
                actualResult = actualResult.Substring(1);
            }

            Assert.Equal(expectedResultContent, actualResult);
        }
        public void RunTestViews(string testViewName)
        {
            // read view
            var viewCode = File.ReadAllText($"TestViews/{testViewName}.html");

            //read result
            var expectedResult = File.ReadAllText($"TestViews/{testViewName}.Result.html");

            //run view engine
            IViewEngine viewEngine = new ViewEngine();
            var         model      = new TestModel
            {
                String = "Username",
                List   = new List <string>()
                {
                    "Item1", "item2", "test", "123", ""
                }
            };

            var engineResult = viewEngine.GetHtml(testViewName, viewCode, model);

            // compare result!= view engine result
            Assert.Equal(expectedResult, engineResult);
        }