From 335f61097ce69a54d8ce7440e299bee7c7f274f3 Mon Sep 17 00:00:00 2001 From: Marcin Celej Date: Wed, 17 Jan 2024 15:54:35 +0100 Subject: [PATCH] #18: Web.Api.Testing: Introduced method for ignoring parts of (or entire) request body --- .../Users/UserScenario.cs | 1 + Web/Synergy.Web.Api.Testing/Json/Ignore.cs | 19 ++++++++++++++----- ...Api.of.Synergy.Web.Api.Testing.verified.md | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/Web/Sample/Synergy.Sample.Web.API.Tests/Users/UserScenario.cs b/Web/Sample/Synergy.Sample.Web.API.Tests/Users/UserScenario.cs index 482ff08..2fb7514 100644 --- a/Web/Sample/Synergy.Sample.Web.API.Tests/Users/UserScenario.cs +++ b/Web/Sample/Synergy.Sample.Web.API.Tests/Users/UserScenario.cs @@ -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")) diff --git a/Web/Synergy.Web.Api.Testing/Json/Ignore.cs b/Web/Synergy.Web.Api.Testing/Json/Ignore.cs index 7bfa2aa..de3b2e2 100644 --- a/Web/Synergy.Web.Api.Testing/Json/Ignore.cs +++ b/Web/Synergy.Web.Api.Testing/Json/Ignore.cs @@ -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"); @@ -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"); diff --git a/Web/Synergy.Web.Api.Tests/Architecture/Public/Api.of.Synergy.Web.Api.Testing.verified.md b/Web/Synergy.Web.Api.Tests/Architecture/Public/Api.of.Synergy.Web.Api.Testing.verified.md index 2aa55e6..349b012 100644 --- a/Web/Synergy.Web.Api.Tests/Architecture/Public/Api.of.Synergy.Web.Api.Testing.verified.md +++ b/Web/Synergy.Web.Api.Tests/Architecture/Public/Api.of.Synergy.Web.Api.Testing.verified.md @@ -282,6 +282,9 @@ - Append( ignores: IEnumerable ) : void + - Ignore.RequestBody( + nodes: params String[] [ParamArray] + ) : Ignore - Ignore.RequestDescription() : Ignore - Ignore.RequestMethod() : Ignore - Ignore.ResponseBody(