diff --git a/src/ServiceStack.Common/Utils/PathUtils.cs b/src/ServiceStack.Common/Utils/PathUtils.cs
index 1826030b1a3..dc3cfd8ffb2 100644
--- a/src/ServiceStack.Common/Utils/PathUtils.cs
+++ b/src/ServiceStack.Common/Utils/PathUtils.cs
@@ -13,7 +13,9 @@ public static string MapAbsolutePath(string relativePath, string appendPartialPa
var assemblyDirectoryPath = Path.GetDirectoryName(new Uri(typeof(PathUtils).Assembly.EscapedCodeBase).LocalPath);
// Escape the assembly bin directory to the hostname directory
- var hostDirectoryPath = assemblyDirectoryPath + appendPartialPathModifier;
+ var hostDirectoryPath = appendPartialPathModifier != null
+ ? assemblyDirectoryPath + appendPartialPathModifier
+ : assemblyDirectoryPath;
return Path.GetFullPath(relativePath.Replace("~", hostDirectoryPath));
}
@@ -21,12 +23,37 @@ public static string MapAbsolutePath(string relativePath, string appendPartialPa
return relativePath;
}
- public static string MapAbsolutePath(this string relativePath)
+ ///
+ /// Maps the path of a file in the context of a VS project
+ ///
+ /// the relative path
+ /// the absolute path
+ /// Assumes static content is two directories above the /bin/ directory,
+ /// eg. in a unit test scenario the assembly would be in /bin/Debug/.
+ public static string MapProjectPath(this string relativePath)
{
var mapPath = MapAbsolutePath(relativePath, string.Format("{0}..{0}..", Path.DirectorySeparatorChar));
return mapPath;
}
+ ///
+ /// Maps the path of a file in a self-hosted scenario
+ ///
+ /// the relative path
+ /// the absolute path
+ /// Assumes static content is copied to /bin/ folder with the assemblies
+ public static string MapAbsolutePath(this string relativePath)
+ {
+ var mapPath = MapAbsolutePath(relativePath, null);
+ return mapPath;
+ }
+
+ ///
+ /// Maps the path of a file in an Asp.Net hosted scenario
+ ///
+ /// the relative path
+ /// the absolute path
+ /// Assumes static content is in the parent folder of the /bin/ directory
public static string MapHostAbsolutePath(this string relativePath)
{
var mapPath = MapAbsolutePath(relativePath, string.Format("{0}..", Path.DirectorySeparatorChar));
diff --git a/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionTests.cs b/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionTests.cs
index 675bf96279f..8d2667edf7d 100644
--- a/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionTests.cs
+++ b/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionTests.cs
@@ -60,7 +60,7 @@ public static IEnumerable UserAuthRepositorys
sqliteRepo.Clear();
yield return new TestCaseData(sqliteRepo);
- var dbFilePath = "~/App_Data/auth.sqlite".MapAbsolutePath();
+ var dbFilePath = "~/App_Data/auth.sqlite".MapProjectPath();
if (File.Exists(dbFilePath)) File.Delete(dbFilePath);
var sqliteDbFactory = new OrmLiteConnectionFactory(dbFilePath);
var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
diff --git a/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionWithoutTestSourceTests.cs b/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionWithoutTestSourceTests.cs
index e8177dc86e0..e7a989b1070 100644
--- a/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionWithoutTestSourceTests.cs
+++ b/tests/ServiceStack.Common.Tests/OAuth/OAuthUserSessionWithoutTestSourceTests.cs
@@ -51,7 +51,7 @@ public void SetUp()
userAuthRepositorys.Add(sqliteInMemoryRepo);
var sqliteDbFactory = new OrmLiteConnectionFactory(
- "~/App_Data/auth.sqlite".MapAbsolutePath());
+ "~/App_Data/auth.sqlite".MapProjectPath());
var sqliteDbRepo = new OrmLiteAuthRepository(sqliteDbFactory);
sqliteDbRepo.CreateMissingTables();
userAuthRepositorys.Add(sqliteDbRepo);
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
index d635d5eaf8a..fe1d94c8ab0 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/MarkdownFormatTests.cs
@@ -45,7 +45,7 @@ public void TestFixtureSetUp()
//staticTemplatePath = "~/AppData/Template/default.shtml".MapAbsolutePath();
//staticTemplateContent = File.ReadAllText(staticTemplatePath);
- dynamicPagePath = "~/Views/Template/DynamicTpl.md".MapAbsolutePath();
+ dynamicPagePath = "~/Views/Template/DynamicTpl.md".MapProjectPath();
dynamicPageContent = File.ReadAllText(dynamicPagePath);
//dynamicListPagePath = "~/Views/Template/DynamicListTpl.md".MapAbsolutePath();
@@ -61,7 +61,7 @@ public void OnBeforeEachTest()
[Test]
public void Can_load_all_markdown_files()
{
- markdownFormat.RegisterMarkdownPages("~/".MapAbsolutePath());
+ markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
Assert.That(markdownFormat.ViewPages.Count, Is.EqualTo(viewPageNames.Length));
Assert.That(markdownFormat.ViewSharedPages.Count, Is.EqualTo(sharedViewPageNames.Length));
@@ -78,8 +78,8 @@ public void Can_load_all_markdown_files()
[Test]
public void Can_Render_StaticPage()
{
- markdownFormat.RegisterMarkdownPages("~/".MapAbsolutePath());
- var html = markdownFormat.RenderStaticPageHtml("~/AppData/NoTemplate/Static".MapAbsolutePath());
+ markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
+ var html = markdownFormat.RenderStaticPageHtml("~/AppData/NoTemplate/Static".MapProjectPath());
Assert.That(html, Is.Not.Null);
Assert.That(html, Is.StringStarting("
Static Markdown template
"));
@@ -88,8 +88,8 @@ public void Can_Render_StaticPage()
[Test]
public void Can_Render_StaticPage_WithTemplate()
{
- markdownFormat.RegisterMarkdownPages("~/".MapAbsolutePath());
- var html = markdownFormat.RenderStaticPageHtml("~/AppData/Template/StaticTpl".MapAbsolutePath());
+ markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
+ var html = markdownFormat.RenderStaticPageHtml("~/AppData/Template/StaticTpl".MapProjectPath());
Console.WriteLine(html);
@@ -101,7 +101,7 @@ public void Can_Render_StaticPage_WithTemplate()
public void Can_Render_DynamicPage()
{
var person = new Person { FirstName = "Demis", LastName = "Bellot" };
- markdownFormat.RegisterMarkdownPages("~/".MapAbsolutePath());
+ markdownFormat.RegisterMarkdownPages("~/".MapProjectPath());
var html = markdownFormat.RenderDynamicPageHtml("Dynamic", person);
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/MockClass.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/MockClass.cs
index 6218506d718..022eee1e0eb 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/MockClass.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/MockClass.cs
@@ -27,7 +27,7 @@ public ServiceStack.Markdown.MvcHtmlString EvalExpr_0()
//[Test]
public void Compare_access()
{
- var filePath = "~/AppData/TestsResults/Customer.htm".MapAbsolutePath();
+ var filePath = "~/AppData/TestsResults/Customer.htm".MapProjectPath();
const int Times = 10000;
var start = DateTime.Now;
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
index 957ed58ff9e..ff0d5444e2d 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/TemplateTests.cs
@@ -27,13 +27,13 @@ public class TemplateTests
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- staticTemplatePath = "~/Views/Template/default.shtml".MapAbsolutePath();
+ staticTemplatePath = "~/Views/Template/default.shtml".MapProjectPath();
staticTemplateContent = File.ReadAllText(staticTemplatePath);
- dynamicPagePath = "~/Views/Template/DynamicTpl.md".MapAbsolutePath();
+ dynamicPagePath = "~/Views/Template/DynamicTpl.md".MapProjectPath();
dynamicPageContent = File.ReadAllText(dynamicPagePath);
- dynamicListPagePath = "~/Views/Template/DynamicListTpl.md".MapAbsolutePath();
+ dynamicListPagePath = "~/Views/Template/DynamicListTpl.md".MapProjectPath();
dynamicListPageContent = File.ReadAllText(dynamicListPagePath);
}
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/TextBlockTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/TextBlockTests.cs
index 02709502fb9..bb9d2fffecd 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/TextBlockTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/TextBlockTests.cs
@@ -17,7 +17,7 @@ public class TextBlockTests
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- dynamicListPagePath = "~/Views/Template/DynamicListTpl.md".MapAbsolutePath();
+ dynamicListPagePath = "~/Views/Template/DynamicListTpl.md".MapProjectPath();
dynamicListPageContent = File.ReadAllText(dynamicListPagePath);
}
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/UseCaseTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/UseCaseTests.cs
index ec54e74bca7..5e7d547bdc6 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/UseCaseTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/UseCaseTests.cs
@@ -73,7 +73,7 @@ public class UseCaseTests : MarkdownTestBase
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- var jsonPages = File.ReadAllText("~/AppData/Pages.json".MapAbsolutePath());
+ var jsonPages = File.ReadAllText("~/AppData/Pages.json".MapProjectPath());
Pages = JsonSerializer.DeserializeFromString>(jsonPages);
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
index 25c7dc021bf..15945586e7a 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats/ViewTests.cs
@@ -25,7 +25,7 @@ public class ViewTests
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- var json = "~/AppData/ALFKI.json".MapAbsolutePath().ReadAllText();
+ var json = "~/AppData/ALFKI.json".MapProjectPath().ReadAllText();
response = JsonSerializer.DeserializeFromString(json);
}
@@ -42,7 +42,7 @@ public class AppHost : IAppHost
public AppHost()
{
this.Config = new EndpointHostConfig {
- MarkdownSearchPath = "~".MapAbsolutePath(),
+ MarkdownSearchPath = "~".MapProjectPath(),
MarkdownReplaceTokens = new Dictionary(),
IgnoreFormatsInMetadata = new HashSet(),
};
@@ -235,14 +235,14 @@ public void Does_process_Markdown_pages()
var markdownHandler = new MarkdownHandler {
MarkdownFormat = markdownFormat,
PathInfo = "/AppData/NoTemplate/Static.md",
- FilePath = "~/AppData/NoTemplate/Static.md".MapAbsolutePath(),
+ FilePath = "~/AppData/NoTemplate/Static.md".MapProjectPath(),
};
var httpReq = new MockHttpRequest { QueryString = new NameValueCollection() };
var httpRes = new MockHttpResponse();
markdownHandler.ProcessRequest(httpReq, httpRes, "Static");
var expectedHtml = markdownFormat.Transform(
- File.ReadAllText("~/AppData/NoTemplate/Static.md".MapAbsolutePath()));
+ File.ReadAllText("~/AppData/NoTemplate/Static.md".MapProjectPath()));
httpRes.Close();
Assert.That(httpRes.Contents, Is.EqualTo(expectedHtml));
diff --git a/tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs b/tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
index 3f61b03cdb9..e2b114a6110 100644
--- a/tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
+++ b/tests/ServiceStack.ServiceHost.Tests/Formats_Razor/TemplateTests.cs
@@ -121,13 +121,13 @@ public class RazorTemplateTests
[TestFixtureSetUp]
public void TestFixtureSetUp()
{
- staticTemplatePath = "~/Views/Template/_Layout.cshtml".MapAbsolutePath();
+ staticTemplatePath = "~/Views/Template/_Layout.cshtml".MapProjectPath();
staticTemplateContent = File.ReadAllText(staticTemplatePath);
- dynamicPagePath = "~/Views/Template/DynamicTpl.cshtml".MapAbsolutePath();
+ dynamicPagePath = "~/Views/Template/DynamicTpl.cshtml".MapProjectPath();
dynamicPageContent = File.ReadAllText(dynamicPagePath);
- dynamicListPagePath = "~/Views/Template/DynamicListTpl.cshtml".MapAbsolutePath();
+ dynamicListPagePath = "~/Views/Template/DynamicListTpl.cshtml".MapProjectPath();
dynamicListPageContent = File.ReadAllText(dynamicListPagePath);
templateArgs = person;
diff --git a/tests/ServiceStack.WebHost.Endpoints.Tests/FileUploadTests.cs b/tests/ServiceStack.WebHost.Endpoints.Tests/FileUploadTests.cs
index 2b5f6131139..4fbcf9edfee 100644
--- a/tests/ServiceStack.WebHost.Endpoints.Tests/FileUploadTests.cs
+++ b/tests/ServiceStack.WebHost.Endpoints.Tests/FileUploadTests.cs
@@ -93,7 +93,7 @@ public void AssertResponse(HttpWebResponse response, string contentType)
[Test]
public void Can_POST_upload_file()
{
- var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapAbsolutePath());
+ var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapProjectPath());
var webRequest = (HttpWebRequest)WebRequest.Create(ListeningOn + "/fileuploads");
webRequest.Accept = ContentType.Json;
@@ -114,7 +114,7 @@ public void Can_POST_upload_file_using_ServiceClient()
{
IServiceClient client = new JsonServiceClient(ListeningOn);
- var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapAbsolutePath());
+ var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapProjectPath());
var response = client.PostFile(
@@ -133,7 +133,7 @@ public void Can_handle_error_on_POST_upload_file_using_ServiceClient()
{
IServiceClient client = new JsonServiceClient(ListeningOn);
- var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapAbsolutePath());
+ var uploadFile = new FileInfo("~/TestExistingDir/upload.html".MapProjectPath());
try
{
@@ -155,7 +155,7 @@ public void Can_handle_error_on_POST_upload_file_using_ServiceClient()
[Test]
public void Can_GET_upload_file()
{
- var uploadedFile = new FileInfo("~/TestExistingDir/upload.html".MapAbsolutePath());
+ var uploadedFile = new FileInfo("~/TestExistingDir/upload.html".MapProjectPath());
var webRequest = (HttpWebRequest)WebRequest.Create(ListeningOn + "/fileuploads/TestExistingDir/upload.html");
var expectedContents = new StreamReader(uploadedFile.OpenRead()).ReadToEnd();
diff --git a/tests/ServiceStack.WebHost.Endpoints.Tests/ServiceStack.WebHost.Endpoints.Tests.csproj b/tests/ServiceStack.WebHost.Endpoints.Tests/ServiceStack.WebHost.Endpoints.Tests.csproj
index 4d3d0d6f6dc..3c57f13970a 100644
--- a/tests/ServiceStack.WebHost.Endpoints.Tests/ServiceStack.WebHost.Endpoints.Tests.csproj
+++ b/tests/ServiceStack.WebHost.Endpoints.Tests/ServiceStack.WebHost.Endpoints.Tests.csproj
@@ -230,8 +230,12 @@
sqlite3.dll
PreserveNewest
-
-
+
+ PreserveNewest
+
+
+ PreserveNewest
+
diff --git a/tests/ServiceStack.WebHost.Endpoints.Tests/Support/Services/FileUploadService.cs b/tests/ServiceStack.WebHost.Endpoints.Tests/Support/Services/FileUploadService.cs
index 88700e7ae68..26d52abd0b2 100644
--- a/tests/ServiceStack.WebHost.Endpoints.Tests/Support/Services/FileUploadService.cs
+++ b/tests/ServiceStack.WebHost.Endpoints.Tests/Support/Services/FileUploadService.cs
@@ -46,7 +46,7 @@ public override object OnGet(FileUpload request)
if (request.RelativePath.IsNullOrEmpty())
throw new ArgumentNullException("RelativePath");
- var filePath = ("~/" + request.RelativePath).MapAbsolutePath();
+ var filePath = ("~/" + request.RelativePath).MapProjectPath();
if (!File.Exists(filePath))
throw new FileNotFoundException(request.RelativePath);