<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title><![CDATA[Hannes Karask Blog]]></title>
        <description><![CDATA[Sailing on the seven seas of software development]]></description>
        <link>https://karask.com</link>
        <image>
            <url>https://karask.com/uploads/dp.jpg</url>
            <title>Hannes Karask Blog</title>
            <link>https://karask.com</link>
        </image>
        <generator>RSS for Node</generator>
        <lastBuildDate>Sat, 14 Jun 2025 04:42:49 GMT</lastBuildDate>
        <atom:link href="https://karask.com/rss" rel="self" type="application/rss+xml"/>
        <pubDate>Sat, 14 Jun 2025 04:42:49 GMT</pubDate>
        <copyright><![CDATA[2025 Karask.com]]></copyright>
        <language><![CDATA[en]]></language>
        <item>
            <title><![CDATA[Mocking HTTP calls in ASP.NET Integration Tests]]></title>
            <description><![CDATA[
![NuGet and TeamCity](/uploads/asp-net-integration-testing.png)

When working with services that call external APIs, you'll probably want to mock those calls in your tests. This process is straightforward when working with a single service. You typically mock the `HttpHandler` in the `HttpClient` passed to the service:

```csharp
var handlerMock = new Mock<HttpMessageHandler>();

handlerMock
    .Protected()
    .Setup<Task<HttpResponseMessage>>(
        "SendAsync",
        ItExpr.IsAny<HttpRequestMessage>(),
        ItExpr.IsAny<CancellationToken>()
    )
    .ReturnsAsync(new HttpResponseMessage
    {
        StatusCode = HttpStatusCode.OK,
        Content = new StringContent("{\"message\":\"Hello World!\"}")
    });

var httpClient = new HttpClient(handlerMock.Object)
{
    BaseAddress = new Uri("https://api.example.com/")
};
```

How would you go about doing that in an Integration Testing scenario, where services get wired up by the framework?

ASP.NET has a nifty way of hosting your ASP.NET API in memory using the [Microsoft.AspNetCore.Mvc.Testing](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Testing) package. It takes just a few lines of code to fire up an in-memory API, but mocking the external calls becomes tricky unless you want to replace every single service registration with a custom `HttpClient` + mocked handler combo. There's an easier way: you can register a custom `HttpMessageHandlerBuilder`.

]]></description>
            <link>https://karask.com/mocking-http-calls-in-asp-net-integration-tests</link>
            <guid isPermaLink="true">https://karask.com/mocking-http-calls-in-asp-net-integration-tests</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Mon, 09 Jun 2025 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[GitHub Code Search Cheat Sheet]]></title>
            <description><![CDATA[
As a developer, you've probably used to browsing code samples on Stack Overflow and various dev blogs. There's also GitHub, a formidable source of wisdom. You can easily search through all the repositories or narrow it down to your organization by using a couple of modifiers.

In the second half of 2022, GitHub updated their code searching engine and interface. You can use several modifiers and keywords to narrow the search and find what you're after. It even supports regular expressions!

This blog post is meant to be succinct reference for crafting search queries.

]]></description>
            <link>https://karask.com/github-code-search-cheat-sheet</link>
            <guid isPermaLink="true">https://karask.com/github-code-search-cheat-sheet</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Mon, 19 Jun 2023 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[Generate HTML to PDF using AWS Lambda and Wkhtmltopdf]]></title>
            <description><![CDATA[
![Wkhtmltopdf AWS Lambda Typescript](https://s3-ap-southeast-2.amazonaws.com/karask.com/blog/lambda-wkhtmltopdf.jpg)

Almost every system I've ever worked with had to generate PDF files for reporting, statements etc. Finding a good (and free) library can be tricky, especially in the .NET Core space. Many options out there lack documentation and can have unexpected behaviour. Generating larger PDFs can put a lot of pressure on your system, so moving it into a separate service would make sense.

]]></description>
            <link>https://karask.com/generate-html-to-pdf-using-aws-lambda-and-wkhtmltopdf</link>
            <guid isPermaLink="true">https://karask.com/generate-html-to-pdf-using-aws-lambda-and-wkhtmltopdf</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Sun, 12 Mar 2023 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[ASP.NET Core Consistent JSON Problem Details Response]]></title>
            <description><![CDATA[
ASP.NET Core's default template adds [RFC7807](https://datatracker.ietf.org/doc/html/rfc7807) Problem Details response to everything that results in _400: Bad Response_:

```json
{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "One or more validation errors occurred.",
  "status": 400,
  "traceId": "00-3b3e118eb02dac41bcfc5d7c93509896-daaf187e081ea94e-00",
  "errors": {
    "Foo": ["The Foo field is required."]
  }
}
```

(note that the field is Pascal cased, whereas JSON is usually camel-cased).

Other response statuses return an **empty body**. Wouldn't it be nice to receive a nice JSON response, regardless the HTTP status (ie 403, 404, 500 etc)?

]]></description>
            <link>https://karask.com/asp-net-core-consistent-json-problem-details</link>
            <guid isPermaLink="true">https://karask.com/asp-net-core-consistent-json-problem-details</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[Automate Swagger/OpenApi snapshot testing]]></title>
            <description><![CDATA[
Adding OpenApi/Swagger spec generator into an Asp.Net Core app is easy. It even comes preconfigured with the Asp.Net Core 5 template.

Both Swashbuckle and NSwag offer quite easy extension points to further customize the spec generation. For example you can [add 401 and 403 response types automatically](https://www.scottbrady91.com/Identity-Server/ASPNET-Core-Swagger-UI-Authorization-using-IdentityServer4) based on the `[Authorize]` attribute. This saves you from manually decorating all the methods.

]]></description>
            <link>https://karask.com/swagger-openapi-snapshot-testing</link>
            <guid isPermaLink="true">https://karask.com/swagger-openapi-snapshot-testing</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Tue, 16 Mar 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[AWS CloudFront: Access to script has been blocked by CORS policy' description: 'How to fix the CORS issue with AWS CloudFront: Access to script at x from origin y has been blocked by CORS policy: No Access-Control-Allow-Origin header is present on the requested resource.]]></title>
            <description><![CDATA[
`Access to script at 'https://cf.yourdomain.com/script.js' from origin 'https://yourdomain.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.`

Looks familiar? Read on!

[AWS CloudFront](https://aws.amazon.com/cloudfront) is an excellent CDN service when hosting your static assets. If you're referencing your scripts with the `crossorigin="anonymous"` turned on, then the browser sends through an additional header: `Origin: https://yourdomain.com`. Now, the response has to include the header `Access-Control-Allow-Origin`, or otherwise you'll get the error above.

]]></description>
            <link>https://karask.com/fix-the-aws-cloudfront-error-access-to-script-has-been-block</link>
            <guid isPermaLink="true">https://karask.com/fix-the-aws-cloudfront-error-access-to-script-has-been-block</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Mon, 08 Feb 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[Seed Postgres database with Docker Compose]]></title>
            <description><![CDATA[
![Postgres Docker Seed Data](/uploads/postgres-docker-compose-seed-data.jpg)

Provisioning local infrastructure can be a bit cumbersome, at least during the initial setup. Docker to the rescue! If you haven't used Docker yet then get on it ASAP!

With a simple command, you can provision (and seed) different resources like databases, messaging queues and other services. In this article, I'm going to show you how to create a few simple scripts to get you going with **Postgres** AND seed some **data**.

]]></description>
            <link>https://karask.com/seed-postgres-database-with-docker-compose</link>
            <guid isPermaLink="true">https://karask.com/seed-postgres-database-with-docker-compose</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Thu, 04 Feb 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[The new and easy way to debug through NuGet packages with the Source Link]]></title>
            <description><![CDATA[
If you're using your [own NuGet packages](https://karask.com/teamcity-building-nuget-packages) or consuming 3rd party ones, then you've probably faced the pain of stepping (or rather not stepping) through it's source code.

Forget the symbol and source servers, there's a new and friendlier kid on the block: [Source Link](https://github.com/dotnet/core/blob/master/Documentation/diagnostics/source%5Flink.md). Formerly you had to upload your symbol (PDB) and source files to different locations and use several switches during the build. Even that didn't guarantee you success, downloading source files often failed miserably.

Source Link is here to ease your pain, it is a developer productivity feature that allows unique information about an assembly's original source code to be embedded in its PDB during compilation.

]]></description>
            <link>https://karask.com/nuget-packages-and-debugging-with-source-link</link>
            <guid isPermaLink="true">https://karask.com/nuget-packages-and-debugging-with-source-link</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[Retry PowerShell Invoke-WebRequest]]></title>
            <description><![CDATA[
<div class="row" style="margin-bottom: 20px">
<div class="text-center col-sm-2"><img alt="PowerShell" class="img-fluid" src="https://karask.com/uploads/powershell.jpg" style="padding: 20px 20px 20px 0;max-width: 97px"></div>

<div class="col-sm-10">Fetching resources over the network isn’t always reliable. Timeouts and other connections issues are quite common, especially if the server is under stress. If you’re okay with the resource being temporarily unavailable, feel free to use the following retry script:</div>
</div>

]]></description>
            <link>https://karask.com/retry-powershell-invoke-webrequest</link>
            <guid isPermaLink="true">https://karask.com/retry-powershell-invoke-webrequest</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[Simple ELMAH-like web error logging for ASP.NET Core using MongoDB]]></title>
            <description><![CDATA[
![ELMAH-like web error logging for ASP.NET Core dashboard](https://karask.com/uploads/elmah_like_logging_asp_core.jpg)

While making this blog I needed a quick way to log failed requests for later analysis. If you've developed ASP.NET applications in the past, then you've probably used good old ELMAH package, which automagically logs your unsuccessful requests.

Good news, this is easily achievable in ASP.NET Core via something called [middleware](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/middleware?tabs=aspnetcore2x). If you're not familiar with middleware then I suggest you go and take a few minutes with the article.

]]></description>
            <link>https://karask.com/simple-elmah-like-web-error-logging-for-aspnet-core</link>
            <guid isPermaLink="true">https://karask.com/simple-elmah-like-web-error-logging-for-aspnet-core</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
        </item>
        <item>
            <title><![CDATA[TeamCity Building NuGet Packages]]></title>
            <description><![CDATA[
![NuGet and TeamCity](https://karask.com/uploads/TeamCity_NuGet.jpg)

Opening and building large Visual Studio solutions is a pain. A good way to put less stress on your rig is to start moving rarely changing parts of your code into [NuGet](https://www.nuget.org/) packages. NuGet has been around already since 2010, tools are mature and battletested. NuGetizing some of your system makes parts of your code always prebuilt and tested (you are using tests right?). Offloading some of the building and tests will make your overall CI (Continuous Integration) process faster as well.

]]></description>
            <link>https://karask.com/teamcity-building-nuget-packages</link>
            <guid isPermaLink="true">https://karask.com/teamcity-building-nuget-packages</guid>
            <dc:creator><![CDATA[Hannes Karask]]></dc:creator>
            <pubDate>Tue, 02 Feb 2021 00:00:00 GMT</pubDate>
        </item>
    </channel>
</rss>