Skip to content

Commit 6a765fa

Browse files
author
Ajay kumar
committed
[Blog] [Ajay]: Centralize the header with sitemap
1 parent 5838cec commit 6a765fa

File tree

7 files changed

+64
-31
lines changed

7 files changed

+64
-31
lines changed

TestArena/Blog/IntegrationTesting/Intro/Index.razor

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
@page "/blog/integration-testing-in-dotnet-intro"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/integration-testing-in-dotnet-intro");
7+
}
38

49
<BlogContainer>
5-
<Header Title="Integration testing for dotnet core APIs: Introduction"
6-
Image="/images/blog/integration-testing/intro/banner.png" PublishedOn="@DateTime.Now" Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
712
</Header>
813

9-
<Section Heading="What are integration tests in context of APIs?" Level="4">
14+
<Section>
15+
<p>This is going to be multi-part series on integration tests from introduction to advanced used cases.</p>
16+
</Section>
17+
18+
<Section Heading="What are integration tests in context of APIs?">
1019
<p>In the context of <b>.NET Core APIs</b> for a blog, integration tests are automated tests that evaluate the
1120
functionality of various parts of your application working together as a whole. Specifically, these tests
1221
ensure that multiple components — such as controllers, database access, middleware, internal and external
@@ -28,7 +37,7 @@
2837

2938
</Section>
3039

31-
<Section Heading="Ways to write integration tests" Level="4">
40+
<Section Heading="Ways to write integration tests">
3241
<p>Now there are various ways to write integration tests:</p>
3342
<ul>
3443
<li>Using Postman or any other API testing tool</li>
@@ -48,7 +57,7 @@
4857
</ul>
4958
</Section>
5059

51-
<Section Heading="Diving into the code" Level="4">
60+
<Section Heading="Diving into the code">
5261
<p>For a demo code, we will be referring a code repository, which stores the information for superhero personalities. I’ll be sharing the GitHub link of the code repo at the end of the article.</p>
5362
<p>Our demo API has 2 APIs:</p>
5463

@@ -84,7 +93,7 @@ public class SuperHeroController(ISuperHeroRepository superHeroRepository)
8493
<p>Since this is basic demo, our ISuperHeroRepository interacts with a Sqlite database which has some predefined SuperHero entries.</p>
8594
</Section>
8695

87-
<Section Heading="Integration test example" Level="4">
96+
<Section Heading="Integration test example">
8897
<p>Here is an example for our integration test for <b>Get SuperHero By Id</b> scenario:</p>
8998

9099
<CodeSnippet Description='Integration test for Get SuperHero By Id' Number="2">
@@ -140,13 +149,13 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
140149
<h5>4. Assert: Validating the Response</h5>
141150
<p>Now we enter the Assert phase, where we check if the response from the API matches our expectations.</p>
142151

143-
<p><b>Checking the Status Code:</b> This ensures that the API returns the expected HTTP status code, confirming the success or failure of the request.</p>
152+
<p><b>Checking the Status Code:</b></p>
144153
<CodeSnippet Description='Assert Status Code' Number="6">
145154
response.StatusCode.Should().Be(HttpStatusCode.OK);
146155
</CodeSnippet>
147156
<p>This assertion ensures the API returns a status code of <code>200 OK</code>, confirming that the request was successful. If the API returned any other status code (like <code>404 Not Found</code> or <code>500 Internal Server Error</code>), the test would fail.</p>
148157
</Section>
149-
<Section Heading="Validating the Returned Data" Level="4">
158+
<Section Heading="Validating the Returned Data">
150159
<p>Next, we check the actual content of the response by deserializing the JSON response into a <code>SuperHero</code> object:</p>
151160

152161
<CodeSnippet Description='Validate Returned Data' Number="7">
@@ -160,7 +169,7 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
160169
</ul>
161170
</Section>
162171

163-
<Section Heading="Verifying Specific Property Values" Level="4">
172+
<Section Heading="Verifying Specific Property Values">
164173
<p>Finally, we verify that the returned superhero has the correct properties, specifically checking that the ID is 1 and the superhero's name is "Batman":</p>
165174

166175
<CodeSnippet Description='Verify Specific Property Values' Number="8">
@@ -173,7 +182,7 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
173182
<BlogImage ImagePath="/images/blog/integration-testing/intro/Success test result.webp" Description="Success test result" Number="4" />
174183
</Section>
175184

176-
<Section Heading="Negative Scenario" Level="4">
185+
<Section Heading="Negative Scenario">
177186
<p>Let’s deliberately try to break our code to understand how the test behaves in a negative scenario. The test scenario <b>Get superhero by invalid Id returns not found</b> expects a <code>404 Not Found</code> status code when a superhero is not found.</p>
178187

179188
<p>We will make a change in our code to return <code>400 Bad Request</code> instead of <code>404 Not Found</code>:</p>
@@ -196,7 +205,7 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
196205

197206
<CodeSnippet Description='Test Failure Result' Number="10">
198207
Expected response.StatusCode to be HttpStatusCode.NotFound {value: 404},
199-
but found HttpStatusCode.BadRequest {value: 400}
208+
but found HttpStatusCode.BadRequest {value: 400}.
200209
</CodeSnippet>
201210

202211
<BlogImage ImagePath="/images/blog/integration-testing/intro/Failure result status.webp" Description="Failure result status" Number="5" />
@@ -206,6 +215,6 @@ public async Task Get_ById_SuperHero_Returns_SuperHero()
206215
<p>Such scenarios highlight the importance of integration tests in catching unintended changes or bugs in the application behavior.</p>
207216
</Section>
208217
<p>This is it for the basic setup demo. I will be covering more in the future articles like, how to work with database, authentication, events etc.</p>
209-
<EndNotes RepositoryLink="https://github.com/ajaysskumar/SuperHeroSolution" />
218+
<EndNotes RepositoryLink="https://github.com/ajaysskumar/pact-net-example" />
210219

211220
</BlogContainer>

TestArena/Blog/IntegrationTesting/handling-auth/Index.razor

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
@page "/blog/integration-testing-in-dotnet-with-auth"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/integration-testing-in-dotnet-with-auth");
7+
}
8+
39
<BlogContainer>
4-
<Header Title="Integration testing for dotnet core APIs: Handling APIs behind authentication"
5-
Image="/images/blog/integration-testing/handling-auth/banner.png" PublishedOn="@DateTime.Now"
6-
Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
712
</Header>
813

914
<Section Heading="Integration testing for APIs behind authentication" Level="4">

TestArena/Blog/IntegrationTesting/handling-database/Index.razor

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
@page "/blog/integration-testing-in-dotnet-with-database"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
34

5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/integration-testing-in-dotnet-with-database");
7+
}
48

59
<BlogContainer>
6-
<Header Title="Integration testing for dotnet core APIs: Handling database"
7-
Image="/images/blog/integration-testing/handling-database/banner.png" PublishedOn="@DateTime.Now"
8-
Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
912
</Header>
1013

1114
<Section Heading="Summary" Level="4">

TestArena/Blog/IntegrationTesting/handling-external-services/Index.razor

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
@page "/blog/integration-testing-in-dotnet-with-external-services"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
34

5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/integration-testing-in-dotnet-with-external-services");
7+
}
48

59
<BlogContainer>
6-
<Header Title="Integration testing for dotnet core APIs: Handling 3rd party service calls using wiremock"
7-
Image="/images/blog/integration-testing/handling-external-services/banner.png" PublishedOn="@DateTime.Now"
8-
Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
912
</Header>
1013

1114
<Section Heading="Summary" Level="4">

TestArena/Blog/PactNet/Intro/Index.razor

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
@page "/blog/contract-testing-pact-net-intro"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/contract-testing-pact-net-intro");
7+
}
38

49
<BlogContainer>
5-
<Header Title="Intro to PACT for .NET Core: API contract testing"
6-
Image="/images/blog/pact/intro/header_landscape.png" PublishedOn="@DateTime.Now" Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
712
</Header>
813

914
<Summary></Summary>
@@ -20,4 +25,4 @@
2025

2126
<EndNotes RepositoryLink="https://github.com/ajaysskumar/pact-net-example"/>
2227

23-
</BlogContainer>
28+
</BlogContainer>

TestArena/Blog/PactNet/handling-events/Index.razor

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
@page "/blog/contract-testing-in-pact-with-events"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/contract-testing-in-pact-with-events");
7+
}
38

49
<BlogContainer>
5-
<Header Title="Intro to PACT for .NET Core: Events based systems"
6-
Image="images/blog/pact/events-demo/contract-testing-events.webp" PublishedOn="@DateTime.Now" Authors="Ajay Kumar">
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
712
</Header>
813

914
<Section Heading="Introduction">

TestArena/Blog/PactNet/pact-broker/Index.razor

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
@page "/blog/integration-with-pactflow"
22
@using TestArena.Blog.Common
3+
@using TestArena.Blog.Common.NavigationUtils
4+
5+
@code{
6+
PageInfo currentPage = SiteMap.Pages.FirstOrDefault(x => x.RelativePath == "/blog/integration-with-pactflow");
7+
}
38

49
<BlogContainer>
5-
<Header
6-
Title="Intro to PACT for .NET Core: Integration with PactFlow"
7-
Image="/images/blog/pact/pact-broker/blog_header.png"
8-
PublishedOn="@DateTime.Now"
9-
Authors="Ajay Kumar" />
10+
<Header Title="@currentPage.Header"
11+
Image="@currentPage.ArticleImage" PublishedOn="@currentPage.PublishedOn" Authors="Ajay Kumar">
12+
</Header>
1013

1114
<Section Heading="Introduction">
1215
<p>This is in continuation of PACT for .NET series where we will be looking into one of the ways to integrate our APIs with PactFlow.</p>

0 commit comments

Comments
 (0)