Skip to content

Commit b5d1ddd

Browse files
author
Ajay kumar
committed
[Blog] [Ajay]: Checkin progress on first blog
1 parent acff778 commit b5d1ddd

15 files changed

+152
-23
lines changed

TestArena/Blog/Common/List.razor

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@using System.ComponentModel.DataAnnotations
2+
3+
@code {
4+
[Required] [Parameter] public string Heading { get; set; }
5+
[Parameter] public int HeadingLevel { get; set; } = 3;
6+
[Parameter, EditorRequired] public List<RenderFragment> ChildContents { get; set; } = default!;
7+
}
8+
9+
<section>
10+
@{
11+
switch(HeadingLevel){
12+
case 1:
13+
<h1>@Heading</h1>
14+
break;
15+
case 2:
16+
<h2>@Heading</h2>
17+
break;
18+
case 3:
19+
<h3>@Heading</h3>
20+
break;
21+
case 4:
22+
<h4>@Heading</h4>
23+
break;
24+
case 5:
25+
<h5>@Heading</h5>
26+
break;
27+
case 6:
28+
<h6>@Heading</h6>
29+
break;
30+
default:
31+
<h3>@Heading</h3>
32+
break;
33+
}
34+
}
35+
<ol>
36+
@foreach (var child in ChildContents)
37+
{
38+
<li>@child</li>
39+
}
40+
</ol>
41+
</section>

TestArena/Blog/Common/Section.razor

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@
22

33
@code {
44
[Required] [Parameter] public string Heading { get; set; }
5+
[Parameter] public int Level { get; set; } = 3;
56
[Parameter, EditorRequired] public RenderFragment ChildContent { get; set; } = default!;
67
}
78

89
<section>
9-
<h3>@Heading</h3>
10+
@{
11+
switch(Level){
12+
case 1:
13+
<h1>@Heading</h1>
14+
break;
15+
case 2:
16+
<h2>@Heading</h2>
17+
break;
18+
case 3:
19+
<h3>@Heading</h3>
20+
break;
21+
case 4:
22+
<h4>@Heading</h4>
23+
break;
24+
case 5:
25+
<h5>@Heading</h5>
26+
break;
27+
case 6:
28+
<h6>@Heading</h6>
29+
break;
30+
default:
31+
<h3>@Heading</h3>
32+
break;
33+
}
34+
}
1035
<div>@ChildContent</div>
1136
</section>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@using TestArena.Blog.Common
2+
3+
<Section Heading="Everything till here looks good, we are able to capture failures, then why we explored another options ?"
4+
Level="4">
5+
<ChildContent>
6+
<p>Its because in the approach above, the contract test pipeline was running on development environment
7+
and the schema was taken from a currently deployed service in development environment. This
8+
means that the failure will only be caught after the breaking change has been introduced in the
9+
Provider API repository and deployed to certain environment. In short, failure detection was
10+
late.</p>
11+
12+
<BlogImage ImagePath="/images/blog/pact/intro/Flow with schema based testing.webp"
13+
Description="Flow with schema based testing" Number="3" />
14+
15+
<p>As you can see above, the failure detection is after the build and deployment step were done.</p>
16+
17+
<p>We wanted the build step itself to fail so that an early detection of the breaking change is caught
18+
before it can make make any mess. Something like below.</p>
19+
<BlogImage ImagePath="/images/blog/pact/intro/Failure at build step.webp"
20+
Description="Failure at build step" Number="4" />
21+
</ChildContent>
22+
</Section>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
@using TestArena.Blog.Common
2+
3+
@{
4+
var listItems = new List<RenderFragment>()
5+
{
6+
builder => builder.AddContent(0, (RenderFragment)(@<p>Student service (<code>PactNet.Provider</code>): Provider API</p>)),
7+
builder => builder.AddContent(0, (RenderFragment)(@<p>Report Card Service (<code>PactNet.ConsumerOne</code>): Consumer API</p>))
8+
};
9+
}
10+
<Section Heading="How we achieved the above using PACT framework ?">
11+
<ChildContent>
12+
<p>I will focus on how i implemented consumer driven contract testing using PACT in .NET Core API. I will not go
13+
into the very details of what PACT is, as that is explained much better at <a href="https://docs.pact.io/">pact
14+
official site</a>.</p>
15+
16+
<List Heading="Services that we will be setting up for this exercise" HeadingLevel="6" ChildContents="listItems"/>
17+
<p>Student service exposes below API:</p>
18+
<BlogImage ImagePath="/images/blog/pact/intro/Student by Id API.webp"
19+
Description="Student by Id API" Number="5" />
20+
</ChildContent>
21+
</Section>

TestArena/Blog/PactNet/Intro/Index.razor

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,8 @@
33

44
<BlogContainer>
55
<Header Title="Intro to PACT for .NET Core: API contract testing"
6-
Image="/images/blog/pact/intro/contract_test_intro.webp"></Header>
7-
<Section Heading="Summary">
8-
<ChildContent>
9-
<p>Recently i came a across a situation where i had to explore contract testing using PACT framework.</p>
10-
11-
<p>For some background, the account that i was working for had already implemented contract testing in their micro-services. They were following schema based contract testing approach.</p>
12-
13-
<p>In short, schema based testing approach involves matching of the schema that consumers of an API are using against the said API provider. The example and images below will illustrate schema based testing using a small example scenario.</p>
14-
15-
<p>Imagine a microservices system with 3 consumers (A, B and C) for a Provider API. Now all three consumers are expecting a certain fields for their use case from the Provider API. As long as Provider is able to maintain the contract expectations of the consumers, things will be fine.</p>
16-
17-
<p>In schema based contract tests, the testing framework is responsible for getting the schemas of all the consumers and it also holds the current schema of the Provider service. The next step is the comparison which is show in images below.</p>
18-
19-
<BlogImage ImagePath="/images/blog/pact/intro/diagram-1-success-case.webp"
20-
Description="Success case"
21-
Number="1"></BlogImage>
22-
</ChildContent>
23-
</Section>
6+
Image="/images/blog/pact/intro/contract_test_intro.webp"></Header>
7+
<Summary/>
8+
<BuildStepDetection />
9+
<HowToSteps />
2410
</BlogContainer>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@using TestArena.Blog.Common
2+
3+
<Section Heading="Summary">
4+
<ChildContent>
5+
<p>Recently i came a across a situation where i had to explore contract testing using PACT framework.</p>
6+
7+
<p>For some background, the account that i was working for had already implemented contract testing in their
8+
micro-services. They were following schema based contract testing approach.</p>
9+
10+
<p>In short, schema based testing approach involves matching of the schema that consumers of an API are
11+
using against the said API provider. The example and images below will illustrate schema based testing
12+
using a small example scenario.</p>
13+
14+
<p>Imagine a microservices system with 3 consumers (A, B and C) for a Provider API. Now all three consumers
15+
are expecting a certain fields for their use case from the Provider API. As long as Provider is able to
16+
maintain the contract expectations of the consumers, things will be fine.</p>
17+
18+
<p>In schema based contract tests, the testing framework is responsible for getting the schemas of all the
19+
consumers and it also holds the current schema of the Provider service. The next step is the comparison
20+
which is show in images below.</p>
21+
22+
<BlogImage ImagePath="/images/blog/pact/intro/diagram-1-success-case.webp" Description="Success case"
23+
Number="1">
24+
</BlogImage>
25+
26+
<p>In diagram above, a success scenario is shown in a schema based contract testing. All the tests are success as the expected fields by all the clients are available in provider’s schema.</p>
27+
28+
<BlogImage ImagePath="/images/blog/pact/intro/ct-fail.webp" Description="Failure case"
29+
Number="2">
30+
</BlogImage>
31+
32+
<p>The above diagram shows a failure case. The failure is because the <code>Consumer C</code> is expecting the role field which now has been removed from the Provider API schema.</p>
33+
</ChildContent>
34+
</Section>

TestArena/Layout/MainLayout.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@inherits LayoutComponentBase
22
<div class="page">
3-
<div class="sidebar">
3+
@* <div class="sidebar">
44
<NavMenu/>
5-
</div>
5+
</div> *@
66

77
<main>
88
<div class="top-row px-4">

TestArena/Layout/NavMenu.razor

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<div class="top-row ps-3 navbar navbar-dark">
2-
<div class="container-fluid">
2+
@* <div class="container-fluid">
33
<a class="navbar-brand" href="">TestArena</a>
44
<button title="Navigation menu" class="navbar-toggler" @onclick="ToggleNavMenu">
55
<span class="navbar-toggler-icon"></span>
66
</button>
7-
</div>
7+
</div> *@
88
</div>
99

1010
@* <div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu"> *@
4.36 KB
Loading
12.7 KB
Loading

0 commit comments

Comments
 (0)