Skip to content

Category: C#

Contract Testing with Pact in .NET Core

When working in a microservice architecture it can be hard to verify the whole system end to end due to all the moving parts involved. Often the purported solution to this is to write integration tests which verify a couple bits of the system at the same time with the test mocked out. If all these subsections of the system pass their respective integration tests we can be confident in the system, right? The Problem with Integration Tests Integration tests are a good way of verifying our system as they use real (not mocked out) components but quite a lot…

Selenium Solved: Null Responses for HTTP Session Requests

Recently I was updating the UI tests in a project now Selenium Webdriver plays nice with .NET Core. And came across a strange error: View the code on Gist. What made this a strange error is it is a failure to communicate with the Webdriver Server, not my underlying application and because of this failure in communication Webdriver could not manipulate my website. The Fix After some googling, this turns out to be a straightforward fix – my project uses the Chromedriver server as it’s Webdriver for tests and simply the Chromedriver server executable I had locally was out of date when…

ASP.NET Core 2 Solved: Authorization was successful for user: (null).

While I was migrating an ASP.NET Core 1 project to version 2 my authentication code stopped working. After some investigation I kept running across this info message in my application logs which seemed unusual: View the code on Gist. The Fix Turns out this is a simple issue to fix. Just make sure that in the Configure() method in the Startup class contains a call to app.UseAuthentication() before the call to app.UseMvc() for example: View the code on Gist. With this method updated to include the Authentication middleware, the issue should be resolved.      

Implementing a Teardown Method in XUnit

XUnit is a free open source unit testing tool for .NET written by the original inventor of NUnit v2 which is great to work with and supports .NET Core, however, how it handles clean up is slightly different to other test frameworks you may have used. What is a TearDown Method? If you haven’t done much-automated testing before then you may not know what a TearDown method is. Typically its the method responsible for cleaning up after your test(s) have run. For example, an integration test might create data which is persisted to a database. Afterwards, this needs to be purged of data…

Ignoring Folders During Compilation in a ASP.NET Core RC2 Project

ASP.NET Core RC2 – DNX is dead. Introducing the DotNet CLI Until RC2 of ASP.NET Core, the responsibility for building a project was handled by DNX which has now been retired. This has been replaced by the .NET CLI. Part of the motivation for this is to have one tool fulfilling the roles of DNX, DNU and DNVM to try to make things less confusing for developers when they set up their environments. Ignoring a Folder in .NET CLI Compilation One of the quirks during the transition to the .NET CLI from DNX was my project failed to compile. This was due to a node package that didn’t support .NET…