Ejemplo n.º 1
0
        protected HttpResponse View(object viewModel = null,
                                    [CallerMemberName] string viewPath = null)
        {
            var viewContent = System.IO.File
                              .ReadAllText($"Views/{this.GetType().Name.Replace("Controller", string.Empty)}/{viewPath}.cshtml");

            viewContent = viewEngine.GetHtml(viewContent, viewModel, GetUserId());

            var responseHtml = PutViewInLayout(viewContent, viewModel);

            var responseBodyBytes = Encoding.UTF8.GetBytes(responseHtml);
            var response          = new HttpResponse("text/html", responseBodyBytes);

            return(response);
        }
        public void TestGetHtml(string testFileName)
        {
            IViewEngine viewEngine             = new SisViewEngine();
            var         viewFileName           = $"ViewTests/{testFileName}.html";
            var         expectedResultFileName = $"ViewTests/{testFileName}.Result.html";

            var viewContent     = File.ReadAllText(viewFileName);
            var expectedContent = File.ReadAllText(expectedResultFileName);

            var model = new TestViewModel
            {
                StringValue = "str",
                ListValues  = new List <string>
                {
                    "123",
                    "val1",
                    string.Empty
                }
            };

            var modelState = new ModelStateDictionary();
            var principal  = new Identity.Principal();

            var actualResult = viewEngine.GetHtml <object>(viewContent, model, modelState, principal);

            Assert.Equal(expectedContent.Trim(), actualResult.Trim());
        }
        public void TestGetHtmlWithoutModel(string testFileName)
        {
            IViewEngine viewEngine = new SisViewEngine();

            string viewFileName         = $"ViewTests/{testFileName}.html";
            string expectedViewFileName = $"ViewTests/{testFileName}.Result.html";

            string viewContent         = File.ReadAllText(viewFileName);
            string expectedViewContent = File.ReadAllText(expectedViewFileName);

            string actualViewContent = viewEngine.GetHtml <object>(viewContent, null, new ModelStateDictionary());

            Assert.Equal(expectedViewContent, actualViewContent);
        }
Ejemplo n.º 4
0
        public void TestTemplateViewModel()
        {
            IViewEngine viewEngine = new SisViewEngine();

            var actualResult = viewEngine.GetHtml(@"@foreach(var num in Model)
{
<span>@num</span>
}", new List <int> {
                1, 2, 3
            }, null);
            var expectedResult = @"<span>1</span>
<span>2</span>
<span>3</span>";

            Assert.Equal(expectedResult, actualResult);
        }
Ejemplo n.º 5
0
        public void TestGetHtml(string fileName)
        {
            var viewModel = new TestViewModel
            {
                DateOfBirth = new DateTime(2021, 05, 10),
                Name        = "Doggo Arghentino",
                Price       = 12345.67M,
            };

            IViewEngine viewEngine = new SisViewEngine();

            var view           = File.ReadAllText($"ViewTests/{fileName}.html");
            var result         = viewEngine.GetHtml(view, viewModel, null);
            var expectedResult = File.ReadAllText($"ViewTests/{fileName}.Result.html");

            Assert.Equal(expectedResult, result);
        }
Ejemplo n.º 6
0
        public void TestGetHtml(string testFileName)
        {
            IViewEngine viewEngine             = new SisViewEngine();
            var         viewFileName           = $"ViewTests/{testFileName}.html";
            var         expectedResultFileName = $"ViewTests/{testFileName}.Result.html";

            var viewContent    = File.ReadAllText(viewFileName);
            var expectedResult = File.ReadAllText(expectedResultFileName);

            var actualResult = viewEngine.GetHtml <object>(viewContent, new TestViewModel()
            {
                StringValue = "str",
                ListValues  = new List <string> {
                    "123", "val1", string.Empty
                },
            });

            Assert.Equal(expectedResult.TrimEnd(), actualResult.TrimEnd());
        }
        public void TestGetHtmlWithAlbumViewModel(string testFileName)
        {
            IViewEngine viewEngine = new SisViewEngine();

            string viewFileName         = $"ViewTests/{testFileName}.html";
            string expectedViewFileName = $"ViewTests/{testFileName}.Result.html";

            string viewContent         = File.ReadAllText(viewFileName);
            string expectedViewContent = File.ReadAllText(expectedViewFileName);

            AlbumTestViewModel model = new AlbumTestViewModel
            {
                Name  = "Album Name",
                Id    = 1,
                Price = 5
            };

            string actualViewContent = viewEngine.GetHtml(viewContent, model, new ModelStateDictionary());

            Assert.Equal(expectedViewContent, actualViewContent);
        }
        public void TestGetHtml(string testFileName)
        {
            IViewEngine viewEngine = new SisViewEngine();

            string viewFileName         = $"ViewTests/{testFileName}.html";
            string expectedViewFileName = $"ViewTests/{testFileName}.Result.html";

            string viewContent         = File.ReadAllText(viewFileName);
            string expectedViewContent = File.ReadAllText(expectedViewFileName);

            TestViewModel model = new TestViewModel
            {
                StringValue = "str",
                ListValues  = new List <string>()
                {
                    "123", string.Empty, "val1"
                }
            };

            ModelStateDictionary modelState = new ModelStateDictionary();
            string actualViewContent        = viewEngine.GetHtml <TestViewModel>(viewContent, model, modelState);

            Assert.Equal(expectedViewContent, actualViewContent);
        }