Skip to content

Commit 0f0d2d6

Browse files
author
Bernt Røskar Brenna
committed
View script files with includes executed.
1 parent 47ef253 commit 0f0d2d6

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

netmockery/Controllers/EndpointsController.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,14 @@ public ActionResult EndpointJsonFile(string name)
9191
public ActionResult ViewRequestCreatorFile(string name, int requestCreatorId)
9292
{
9393
var endpoint = _endpointCollection.Get(name);
94-
var requestCreator = endpoint.Responses.ElementAt(requestCreatorId).Item2 as IResponseCreatorWithFilename;
95-
if (requestCreator != null)
94+
var requestCreator = endpoint.Responses.ElementAt(requestCreatorId).Item2;
95+
if (requestCreator is FileDynamicResponseCreator fileDynamicResponseCreator)
9696
{
97-
return File(System.IO.File.OpenRead(requestCreator.Filename), "text/plain");
97+
return Content(fileDynamicResponseCreator.GetSourceCodeWithIncludesExecuted(), "text/plain");
98+
}
99+
else if (requestCreator is IResponseCreatorWithFilename requestCreatorWithFilename)
100+
{
101+
return File(System.IO.File.OpenRead(requestCreatorWithFilename.Filename), "text/plain");
98102
}
99103
else
100104
{

netmockery/DynamicResponseCreator.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ public DynamicResponseCreatorBase(Endpoint endpoint) : base(endpoint) { }
2929

3030
public virtual string FileSystemDirectory { get { return null; } }
3131

32+
public string GetSourceCodeWithIncludesExecuted()
33+
{
34+
var sourceCode = SourceCode;
35+
36+
return
37+
FileSystemDirectory != null
38+
?
39+
ExecuteIncludes(
40+
CreateCorrectPathsInLoadStatements(sourceCode, FileSystemDirectory),
41+
FileSystemDirectory
42+
)
43+
:
44+
sourceCode;
45+
}
46+
3247
#if NET462
3348
public override async Task<string> GetBodyAsync(RequestInfo requestInfo)
3449
{
@@ -46,14 +61,7 @@ public override async Task<string> GetBodyAsync(RequestInfo requestInfo)
4661
);
4762

4863
var script = CSharpScript.Create<string>(
49-
FileSystemDirectory != null
50-
?
51-
ExecuteIncludes(
52-
CreateCorrectPathsInLoadStatements(sourceCode, FileSystemDirectory),
53-
FileSystemDirectory
54-
)
55-
:
56-
sourceCode,
64+
GetSourceCodeWithIncludesExecuted(),
5765
scriptOptions,
5866
globalsType: typeof(RequestInfo)
5967
);
@@ -96,14 +104,7 @@ public override async Task<string> GetBodyAsync(RequestInfo requestInfo)
96104
);
97105

98106
var script = CSharpScript.Create<string>(
99-
FileSystemDirectory != null
100-
?
101-
ExecuteIncludes(
102-
CreateCorrectPathsInLoadStatements(SourceCode, FileSystemDirectory),
103-
FileSystemDirectory
104-
)
105-
:
106-
SourceCode,
107+
GetSourceCodeWithIncludesExecuted(),
107108
scriptOptions,
108109
globalsType: typeof(RequestInfo)
109110
);

0 commit comments

Comments
 (0)