Skip to content

Commit

Permalink
Fixed typo: requestCreator -> responseCreator
Browse files Browse the repository at this point in the history
If response creator file is script, add line numbers.
  • Loading branch information
Bernt Røskar Brenna committed Sep 2, 2017
1 parent 9cbb96a commit ee89875
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
19 changes: 13 additions & 6 deletions netmockery/Controllers/EndpointsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,24 @@ public ActionResult EndpointJsonFile(string name)
return Content(System.IO.File.ReadAllText(System.IO.Path.Combine(endpoint.Directory, "endpoint.json")));
}

public ActionResult ViewRequestCreatorFile(string name, int requestCreatorId)
public ActionResult ViewResponseCreatorFile(string name, int responseCreatorId)
{
var endpoint = _endpointCollection.Get(name);
var requestCreator = endpoint.Responses.ElementAt(requestCreatorId).Item2;
if (requestCreator is FileDynamicResponseCreator fileDynamicResponseCreator)
var responseCreator = endpoint.Responses.ElementAt(responseCreatorId).Item2;
if (responseCreator is FileDynamicResponseCreator fileDynamicResponseCreator)
{
return Content(fileDynamicResponseCreator.GetSourceCodeWithIncludesExecuted(), "text/plain");
var sourceCode = fileDynamicResponseCreator.GetSourceCodeWithIncludesExecuted();
var lines = sourceCode.Split('\n');
var sourceWithLineNumber =
from
i in Enumerable.Range(0, lines.Length)
select
$"{i + 1}: {lines[i]}";
return Content(string.Join("\n", sourceWithLineNumber), "text/plain");
}
else if (requestCreator is IResponseCreatorWithFilename requestCreatorWithFilename)
else if (responseCreator is IResponseCreatorWithFilename responseCreatorWithFilename)
{
return File(System.IO.File.OpenRead(requestCreatorWithFilename.Filename), "text/plain");
return File(System.IO.File.OpenRead(responseCreatorWithFilename.Filename), "text/plain");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using netmockery
@model FileDynamicResponseCreator
Script:
<a href="@Url.Action("ViewRequestCreatorFile", "Endpoints", new { name = (string)ViewData["endpointName"], requestCreatorId = (int)ViewData["index"] })">
<a href="@Url.Action("ViewResponseCreatorFile", "Endpoints", new { name = (string)ViewData["endpointName"], responseCreatorId = (int)ViewData["index"] })">
<code>@System.IO.Path.GetFileName(Model.Filename)</code>
</a>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using netmockery
@model FileResponse
From file:
<a href="@Url.Action("ViewRequestCreatorFile", "Endpoints", new { name = (string)ViewData["endpointName"], requestCreatorId = (int)ViewData["index"] })">
<a href="@Url.Action("ViewResponseCreatorFile", "Endpoints", new { name = (string)ViewData["endpointName"], responseCreatorId = (int)ViewData["index"] })">
<code>@System.IO.Path.GetFileName(Model.Filename)</code>
</a>

Expand Down

0 comments on commit ee89875

Please sign in to comment.