Knowit Experience Tech Fika & .NET Aspire sprinkler

Since I returned to Knowit Experience as the new Head of Tech we’ve introduced a new speaker format called ”Tech Fika” in Gothenburg. This is a bi-weekly opportunity for anyone in the tech skill to share whatever they like in an unpretentious ”mini-sprinkler” format.…

5 minute introduction to Message-Based Communication with Azure Service Bus

In this short blogpost we're diving into the world of message-based communication, particularly focusing on Azure Service Bus. If you've primarily worked with request-response communication models, you're in for a treat. Message-based communication can be an extremely powerful addition to your toolbox and Azure Service Bus makes it exceptionally straightforward.…

Tutorial: How to migrate an existing Umbraco website to .NET Aspire

In my previous article I shared a tutorial on how you can get started with .NET Aspire with a brand new Umbraco 13 website running on .NET 8. In this follow-up tutorial I'll cover how you can make the same transition to .NET Aspire but with an existing pre-Umbraco 13 website.…

Tutorial: How to get started with .NET Aspire & Umbraco 13

.NET Aspire, the latest iteration in the .NET family, offers a modular, high-performance framework for building web applications.…

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.…

Trust your tests!

Tests are meant to replace our browser clicking and instead give us instant and reliable feedback if our code is working or not. The browser is just a presentation layer. Trust your tests!…

Comparing different UI Testing frameworks (Selenium, Cypress and Microsoft Playwright)

So I decided that 2022 would be the year when I will start to implement more UI Testing in my projects. But, which framework should I choose?…

Using Microsoft Playwright and NUnit to automate search behaviour

I have been experimenting a lot with different UI testing frameworks such as Selenium, Cypress and Playwright in a public GitHub project and I’ve really come to fancy Microsoft.Playwright for .NET in combination with NUnit.…

Umbraco v9 findings

This week I had a little room left in my schedule for studying new tech and obviously I took that time to get up to speed on Umbraco’s new major version built on dotnet core.…

Testing the untestable with the Adapter Design Pattern

During my session at last weeks Codegarden on ‘Getting started with Unit Testing in Umbraco’ I got a really good question in the Q&A afterwards, and I thought I would share the question and elaborate on my answer: -“What tips do you have for mocking services that are overly complex or have lots of dependencies that can't be null?”…

Showing a maintenance banner on your Umbraco site

Something we do for most of our sites is setting what we call a deploy flag during our deployments and then have our frontend render a maintenance banner at the top of the website. By showing a maintenance banner we can inform the visitor that at the moment we are performing planned maintenance and that they might experience disturbances.…

Starting to Unit Test: Not as Hard as You Think

I thought I would share a recommendation for a really great book that I think anyone who is new to Unit Testing should read: Starting to Unit Test: Not as Hard as You Think by Erik Deitrich. I read this book many years ago but I remember it to this day because it was an eye opener to what Unit Testing essentially is.…

Parallelism: NUnit vs. xUnit

Running your tests in parallel can significantly improve the speed of your test runs, but it could give you occasional problems especially if you're working on static implementations. Also turns out that depending on which testing framework you're using parallelism might be handled differently.…

How to test internal classes

When you're writing unit tests you may sometimes find yourself in a situation where you need to be able to access an internal class from within another project such as your *.Tests project.…