ViewStartUtility should not return current path if current is a view start
file
This commit is contained in:
parent
2c4b3dd3fc
commit
44d888c319
|
|
@ -47,6 +47,16 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
path = path.Substring(1);
|
path = path.Substring(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (string.Equals(ViewStartFileName, Path.GetFileName(path), StringComparison.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
// If the specified path is a ViewStart file, then the first view start that applies to it is the
|
||||||
|
// parent view start.
|
||||||
|
if (!fileSystem.TryGetParentPath(path, out path))
|
||||||
|
{
|
||||||
|
return Enumerable.Empty<string>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var viewStartLocations = new List<string>();
|
var viewStartLocations = new List<string>();
|
||||||
|
|
||||||
while (fileSystem.TryGetParentPath(path, out path))
|
while (fileSystem.TryGetParentPath(path, out path))
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -45,8 +45,31 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Equal(expected, result);
|
Assert.Equal(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Theory]
|
||||||
public void GetViewStartLocations_ReturnsPotentialViewStartLocations_IfPathIsAbsolute()
|
[InlineData("/views/Home/_ViewStart.cshtml")]
|
||||||
|
[InlineData("~/views/Home/_viewstart.cshtml")]
|
||||||
|
[InlineData("views/Home/_Viewstart.cshtml")]
|
||||||
|
public void GetViewStartLocations_SkipsCurrentPath_IfCurrentIsViewStart(string inputPath)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = new[]
|
||||||
|
{
|
||||||
|
@"views\_viewstart.cshtml",
|
||||||
|
@"_viewstart.cshtml"
|
||||||
|
};
|
||||||
|
var fileSystem = new PhysicalFileSystem(GetTestFileSystemBase());
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = ViewStartUtility.GetViewStartLocations(fileSystem, inputPath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("Test.cshtml")]
|
||||||
|
[InlineData("ViewStart.cshtml")]
|
||||||
|
public void GetViewStartLocations_ReturnsPotentialViewStartLocations_IfPathIsAbsolute(string fileName)
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var expected = new[]
|
var expected = new[]
|
||||||
|
|
@ -59,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
@"_viewstart.cshtml",
|
@"_viewstart.cshtml",
|
||||||
};
|
};
|
||||||
var appBase = GetTestFileSystemBase();
|
var appBase = GetTestFileSystemBase();
|
||||||
var viewPath = Path.Combine(appBase, "Areas", "MyArea", "Sub", "Views", "Admin", "Test.cshtml");
|
var viewPath = Path.Combine(appBase, "Areas", "MyArea", "Sub", "Views", "Admin", fileName);
|
||||||
var fileSystem = new PhysicalFileSystem(appBase);
|
var fileSystem = new PhysicalFileSystem(appBase);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
|
|
@ -69,6 +92,46 @@ namespace Microsoft.AspNet.Mvc.Razor
|
||||||
Assert.Equal(expected, result);
|
Assert.Equal(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("_ViewStart.cshtml")]
|
||||||
|
[InlineData("_viewstart.cshtml")]
|
||||||
|
public void GetViewStartLocations_SkipsCurrentPath_IfAbsolutePathIsAViewStartFile(string fileName)
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var expected = new[]
|
||||||
|
{
|
||||||
|
@"Areas\MyArea\Sub\Views\_viewstart.cshtml",
|
||||||
|
@"Areas\MyArea\Sub\_viewstart.cshtml",
|
||||||
|
@"Areas\MyArea\_viewstart.cshtml",
|
||||||
|
@"Areas\_viewstart.cshtml",
|
||||||
|
@"_viewstart.cshtml",
|
||||||
|
};
|
||||||
|
var appBase = GetTestFileSystemBase();
|
||||||
|
var viewPath = Path.Combine(appBase, "Areas", "MyArea", "Sub", "Views", "Admin", fileName);
|
||||||
|
var fileSystem = new PhysicalFileSystem(appBase);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = ViewStartUtility.GetViewStartLocations(fileSystem, viewPath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal(expected, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void GetViewStartLocations_ReturnsEmptySequence_IfViewStartIsAtRoot()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var appBase = GetTestFileSystemBase();
|
||||||
|
var viewPath = "_viewstart.cshtml";
|
||||||
|
var fileSystem = new PhysicalFileSystem(appBase);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
var result = ViewStartUtility.GetViewStartLocations(fileSystem, viewPath);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Empty(result);
|
||||||
|
}
|
||||||
|
|
||||||
private static string GetTestFileSystemBase()
|
private static string GetTestFileSystemBase()
|
||||||
{
|
{
|
||||||
var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider;
|
var serviceProvider = CallContextServiceLocator.Locator.ServiceProvider;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue