-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#72 Fixed an issue in the MVC application where views were not being … (
#75) * #72 Fixed an issue in the MVC application where views were not being discovered in the same controller’s view location. Now, if the controller is HomeController and the view file Index.cshtml is located under Views/Home/Index.cshtml, the library can render the view from HomeController simply by passing Index as the view name. Previously, it was necessary to pass the full relative URL Views/Home/Index.cshtml. This functionality is available only when IRazorTemplateEngine is utilized through Dependency Injection (DI). For applications that are not MVC-based, this view discovery method will not work, and the library will revert to the default behavior, which requires the full relative path of the view file. * #71 Adds support for MVC View localization
- Loading branch information
1 parent
f1788b1
commit c690b92
Showing
11 changed files
with
158 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@{ | ||
ViewData["Title"] = "Home Page"; | ||
} | ||
|
||
<div>Content from Index.fr.cshtml</div> | ||
|
||
<partial name="_partialTest"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace Razor.Templating.Core.Test; | ||
public class MvcApplicationTest | ||
{ | ||
private readonly WebApplicationFactory<Program> _factory; | ||
|
||
public MvcApplicationTest() | ||
{ | ||
_factory = new WebApplicationFactory<Program>(); | ||
} | ||
|
||
[Fact] | ||
public async Task HomePage_Should_RenderViewByName() | ||
{ | ||
// Arrange | ||
var client = _factory.CreateClient(); | ||
|
||
// Act | ||
var response = await client.GetAsync("/Home/Index"); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var pageHtml = await response.Content.ReadAsStringAsync(); | ||
|
||
Assert.Contains(@"<li><a href=""/home/Index"">Render content by using only the view name instead of path</a></li>", pageHtml); | ||
Assert.Contains(@"<h1>This is a partial page</h1>", pageHtml); | ||
} | ||
|
||
[Theory] | ||
[InlineData("fr", "<div>Content from Index.fr.cshtml</div>")] | ||
[InlineData("en-US", "<div>Content from Index.cshtml</div>")] | ||
public async Task RequestWithCulture_Should_RenderLocalizedView(string culture, string expectedContent) | ||
{ | ||
// Arrange | ||
var client = _factory.CreateClient(); | ||
|
||
// Act | ||
var response = await client.GetAsync($"/Home/Index?culture={culture}"); | ||
|
||
// Assert | ||
response.EnsureSuccessStatusCode(); | ||
|
||
var pageHtml = await response.Content.ReadAsStringAsync(); | ||
|
||
Assert.Contains(expectedContent, pageHtml); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters