Skip to content

Commit 2808e99

Browse files
author
Bernt Røskar Brenna
committed
Refactored ResponseCreatorViewComponent
1 parent 0f0d2d6 commit 2808e99

File tree

4 files changed

+7
-3
lines changed

4 files changed

+7
-3
lines changed

netmockery/Controllers/ResponseCreatorViewComponent.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ namespace netmockery.Controllers
88
{
99
public class ResponseCreatorViewComponent : ViewComponent
1010
{
11-
public IViewComponentResult Invoke(Endpoint endpoint, ResponseCreator responseCreator, int index)
11+
public IViewComponentResult Invoke(Endpoint endpoint, ResponseCreator responseCreator)
1212
{
13-
ViewData["index"] = index;
13+
ViewData["index"] = responseCreator.Index;
1414
ViewData["endpointName"] = endpoint.Name;
1515

1616
if (responseCreator is FileResponse)

netmockery/Endpoint.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ public void Add(RequestMatcher requestMatcher, ResponseCreator responseCreator)
101101
Debug.Assert(requestMatcher != null);
102102
Debug.Assert(responseCreator != null);
103103
Debug.Assert(requestMatcher.Index == -1);
104+
Debug.Assert(responseCreator.Index == -1);
104105

105106
if (_ruleThatCatchesEveryThingHasBeenAdded)
106107
{
107108
throw new ArgumentException("The endpoint contains a response matching any request/method, you cannot add more responses");
108109
}
109110

110111
requestMatcher.Index = _responses.Count;
112+
responseCreator.Index = _responses.Count;
111113
_responses.Add(Tuple.Create(requestMatcher, responseCreator));
112114
if (requestMatcher is AnyMatcher && requestMatcher.MatchesAnyHttpMethod)
113115
{

netmockery/ResponseCreator.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public abstract class ResponseCreator
133133
private Endpoint _endpoint;
134134
private string _delay;
135135

136+
public int Index = -1;
137+
136138
public ResponseCreator(Endpoint endpoint)
137139
{
138140
Debug.Assert(endpoint != null);

netmockery/Views/Endpoints/EndpointDetails.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
@await Component.InvokeAsync("RequestMatcher", new { requestMatcher = t.Item1 })
5454
</td>
5555
<td>
56-
@await Component.InvokeAsync("ResponseCreator", new { index = i, responseCreator = creator, endpoint=Model })
56+
@await Component.InvokeAsync("ResponseCreator", new { responseCreator = creator, endpoint=Model })
5757
</td>
5858
<td>
5959
@if (creator.Delay > 0)

0 commit comments

Comments
 (0)