Using The Builder Pattern to improve Testability and Readability

Sometimes setting things up can get a bit messy, especially when we want to test coupled code with a lot of dependencies. This is where the Builder Pattern comes in handy - it helps us create objects in an easier and cleaner way, especially when they are a bit complex to set up.…

Custom Umbraco NotificationHandlers

Whenever a content item is published in Umbraco a ContentPublishingNotification event will be triggered. By creating our own NotificationHandler we can hijack this event and cancel or extend the default notification when a user is publishing a content node in Umbraco.…

Asserting Equal vs Same vs Equivalent

In this article, I'm going to demonstrate three very common but possibly confusing assertion differences in the world of C# testing: Assert.AreEqual, Assert.AreSame and Should().BeEquivalentTo.…

Unit Testing with ChatGPT

Don't like writing unit tests or simply don't have the time for it? Good news – now you don't have to! As a newbord AI enthusiast with a long-time obsession with unit testing, I couldn't resist the urge to try and combine these two topics. Check out my latest blog post "Unit Testing with ChatGPT," to discover how you can use ChatGPT to generate test cases and code for you.…

Unit vs. Integration Testing

By understanding the essential differences between unit and integration testing, we as developers can make better decisions about when and how to use each type of testing to ensure the quality and reliability of our software.…

Getting started with Snapshot Testing using NUnit and Snapper

Snapshot testing is a valuable technique for testing software applications. Using this technique we can capture the state of an application at a specific point in time and compare it to a previously recorded state, known as a snapshot.…

Add a reference to ".NETFramework,Version=x" in the "TargetFrameworks" property of your project file and then re-run NuGet restore?

Sometimes when upgrading .NET framework versions you might get this really strange error in Visual Studio: -"Add a reference to ".NETFramework,Version=v4.8" in the "TargetFrameworks" property of your project file and then re-run NuGet restore?"…

Unit Testing private methods in C#

Should private methods in C# be Unit Tested? Generally you don’t write unit tests for private methods since they are not accessed from outside the implementation class (private methods are considered implementation detail).…

Using the Fluent Builder Pattern to improve test readability and maintenance

Using this pattern we create an test object builder that will centralize redundant (and sometimes complex) logic that we don’t want to have in each and every one of our tests. This will make our tests slimmer and more focused on what is actually important for the state of which is being tested.…

Adding an API Security Definition and Requirement using Swagger UI

In this tutorial I will cover how you can setup an API with Swagger and then add security definition and requirement to pass an api token as an http header with every API request. Lets get to it!…

Tutorial: How to setup a .NET Minimal API with integration testing using WebApplication Factory and NUnit

In this article I will share how you can setup an API using less than 20 lines of code using .NET Minimal API. Next we are going to setup an NUnit test project and using .NET WebApplicationFactory we will call the API endpoint and parse the resonse as an products array and compare the actual response to an expected json file embedded in our source code.…

Moq vs. NSubstitute vs. FakeItEasy

Today I though I would do some syntax comparison between a few of the biggest Mocking Framework in .NET: Moq, NSubstitute and FakeItEasy. Although these framework have slight functional differences they pretty much do the same thing but in different syntax and lingo.…

Loose vs. Strict mocking behaviour

I thought I would demonstrate the difference between Loose and Strict mocking behaviour when using the Moq Framework. By default when you create a new mock and don't specify a MockBehaviour it will be assigned MockBehaviour.Default, which equals to MockBehaviour.Loose.…

How to set TransactionScope timeout in code, application and server wide

The other day we got a bunch of these transaction exceptions logged on some of our production servers: "The operation is not valid for the state of the transaction". At first this exception was a bit cryptic, but when investigating it further is had this following inner exception: "Transaction Timeout".…

Loading this assembly would produce a different grant set from other instances

The other day one of our legacy applications threw this strange error during a production deploy: "Loading this assembly would produce a different grant set from other instances". This .NET 4.6 application is a load balanced SOAP API and strangely this only occured on 1 of the 3 frontend servers so when browsing the frontend it initially seems healty but every other random request would fail and show this error.…

Comparing mocking frameworks: How to handle optional parameter with NSubstituite, Moq and FakeItEasy

Depending on which mocking framework you are using you might have to handle optional parameters differently and in this short article I will compare and demonstrate the differences in the three major mocking frameworks NSubstitute, Moq and FakeItEasy.…

NUnit tests is not found or do not run in Visual Studio's Test Explorer

Having problems with your NUnit tests not running as expected in Visual Studio's Test Explorer? Even wiered, the tests might work for other members of your team but for some reason not for you?…

5th year teaching .NET Testing at local university college YRGO

Today I had the privilege of lecturing for the 5th year at Yrgo University college on the subject of .NET Testing. As always, the goal has been to give students a positive impression of testing early in their career and that writing tests is not something you "should" or "must" do but something you WANT to do because it is a fun and challenging part of being a developer.…

Logging HttpRequests using DelegatingHandler with a named HttpClient and HttpMessageHandlers in Umbraco

Ever found yourself logging the same things over and over again in your Umbraco application when doing HttpClient requests? Wouldn't it be nice (if we could wake up) and all of our request where automatically logged for us in one unified way throughout our entire application?…

Using TestRunParameters in your NUnit tests using .runsettings

I've been getting a lot of traffic lately related to the google search phrase "nunit runsettings example" which at the moment leads to this blogpost I wrote on how to use Playwright with NUnit, which doesn't really cover how to set up .runsettings but rather how you can toggle headless mode in Playwright (totally different topic). So I thought I would share a little tutorial on how you can set up a new NUnit project and use .runsettings and TestRunParameters in your tests.…

C# 8.0 Default interface methods in under 60 seconds!

Last week I noticed a new feature in C# 8.0 called Default Interface Methods. Although the official documentation is great, it's quite extensive so I thought I would do this really short and simple breakdown of what this feature enables.…

Moving smoothly between Optimizely and Umbraco CMS

As I mentioned in one of my previous posts, I had a presentation planned at a lunch meetup in the Knowit Gothenburg office, called "The Optimizely developers guide to Umbraco".…

Guest on tech Podcast 'Digitalterapi'

Last week I was a guest on tech podcast “Digitalterapi” talking about Umbraco, Open Source, Community and much much more..…

THE OPTIMIZELY DEVELOPERS GUIDE TO UMBRACO

Next week I'll be doing a talk at Knowit on how to move smoothly between Optimizely (Episerver) and Umbraco from a developers perspective. This is a presentation I've planned on doing for years and finally got around to.…

Integrating Papertrail logging in a .NET (NLog) application

I’ve really come to enjoy Papertrail as an online log viewer. It’s super quick to setup and I can manage and view logs from multiple project and environments in one simple UI with searching, filtering etc.…