Skip to content

Commit

Permalink
#18: Web.Api.Testing: Introduced method for ignoring parts of (or ent…
Browse files Browse the repository at this point in the history
…ire) request body
  • Loading branch information
MarcinCelej committed Jan 17, 2024
1 parent f66a43e commit 335f610
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ private string CreateUser()
.ShouldBe(ApiConventionFor.CreateResource())
.ShouldBe(
this.EqualToPattern("/Patterns/S02_E01_CreateUser.json")
.Ignore(Ignore.RequestBody("Login"))
.Ignore(Ignore.ResponseLocationHeader())
.Ignore(Ignore.ResponseBody("user.id"))
.Expected("Manual: User is created and its details are returned"))
Expand Down
19 changes: 14 additions & 5 deletions Web/Synergy.Web.Api.Testing/Json/Ignore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ public Ignore And(Ignore ignore)
this.Append(ignore.Nodes);
return this;
}

public static Ignore ResponseBody(params string[] nodes)
public static Ignore RequestBody(params string[] nodes)
{
var ignore = new Ignore();
if (nodes.Any() == false)
ignore.Append(new[] {"$.response.body"});
ignore.Append(nodes.Select(node=> $"$.response.body.{node}"));
ignore.Append(new[] {"$.request.body"});
ignore.Append(nodes.Select(node=> $"$.request.body.{node}"));
return ignore;
}

public static Ignore RequestMethod()
{
return new Ignore("$.request.method");
Expand All @@ -45,6 +45,15 @@ public static Ignore RequestDescription()
return new Ignore("$.request.description");
}

public static Ignore ResponseBody(params string[] nodes)
{
var ignore = new Ignore();
if (nodes.Any() == false)
ignore.Append(new[] {"$.response.body"});
ignore.Append(nodes.Select(node=> $"$.response.body.{node}"));
return ignore;
}

public static Ignore ResponseLocationHeader()
{
return new Ignore("$.response.headers.Location");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,9 @@
- Append(
ignores: IEnumerable<string>
) : void
- Ignore.RequestBody(
nodes: params String[] [ParamArray]
) : Ignore
- Ignore.RequestDescription() : Ignore
- Ignore.RequestMethod() : Ignore
- Ignore.ResponseBody(
Expand Down

0 comments on commit 335f610

Please sign in to comment.