Write (arrange) Act and Assert in your automatic tests

November 14th, 2020

It is a good custom to write out Act and Assert in test as it helps to write the test in a clean way; and helps the next reader to understand where Arrange stops and Act begins. It helps the writer to not involuntarily write Act statements in Assert.
Like so:

sut = setup()

// Act.

// Assert.

The above code is too simple to make the upside of this coding standard visible but soon tests get a few lines long and commentning Act and Assert is a good idea.

I don’t bother to write out // Arrange any more as all tests start with Arrange anyway.

Well… that was not true. I have stumbled upon tests with several Arrange, Act and Assert in them. Typically for integration tests.

Tip: fail explicitly during developing a test

August 17th, 2020

When figuring out how to write a test – add an assert that always fails in the bottom. Remove it when you know the test works as it should.

Why: Because you might get interrupted to spend energy on something else. When you get back the test shines red and you know where to continue. No risk of sending sub par test code to a PR.

I start Domain names with capital letter

July 12th, 2020

When writing comments, and documentation, I usually write domain names with a capital start letter.

// Persist the Customer in the next layer.

// Group all Orders by their Packaging-type.

The Customer database is co-located with the Project database. The common key is a string.

Running the Adobe XD viewer gives me 9! new processes

June 4th, 2020

I wondered why my laptop fan kicked in whenever I started the Adobe XD viewer. So I checked Task managter and found 9 processes!
When I killed the processes another one, a crash recovery process started.

To top it of I got 3 processes for autostart, running whether I have started the XD viewer or not.
Or maybe 6, depending on where you look and what you look for.

I have disabled 3 tasks in Task manager->Startup
but whenever I start the machine there are 3 processes from Adobe running.
So, through Sysinternals’ autoruns I find 6+2+5 autostarts and various settings. I have not delved into what is running processes and what “just another” setting.

As a viewer it is quite hefty.

As if the computer, Dell, with latest version of Windows, and Microsoft bloat ware was not enough…

I am running Windows10. I don’t know what the XD viewer looks like on MacOS.

In Adobe’s defence I have not measured the memory and cpu and power consumption impact.
On the other hand I have not checked what else Adobe has done, like installing programs that are not so easily linked to adobe (svchost) or bogging down the machine in other ways (hard disk, changing order of processes in the network pipe) or what it does when it calls home.

tags: , , | categories: Miscellaneous | no comments »

Starting an Aspnet core site on IISExpress

April 16th, 2020

One cannot point at a folder and just start, as we did with the full framework. There seems to be several solutions for Core and the one described here requires a publish. (Visual studio 2017:menu->Build->Publish)

Publishing a dotnet core site copies relevant parts to a folder

"path\iisexpress.exe" /path:"path\site\bin\Debug\netcoreapp2.2\publish" /port:betweenmagicalnumbers

Here is the exact command I recently used.

"C:\Program Files\IIS Express\iisexpress.exe" /path:"C:\DATA\PROJEKT\Lagardsdorren\Lagardsdorren\bin\Debug\netcoreapp2.2\publish" /port:44342

The port number is limited to 44300 to 44399 to avoid having to start Visual studio with elevated privileges. Reference.

Do not walk the path with “..” as you get an “Invalid physical path.” error.

Set an environment variable to give better debug output. Reference.


Change background colour in vscode

March 14th, 2020

It should be easy, and is, but the information is hard to find.

Go to Settings (ctrl-,), search for “color customizations”, select “Edit in settings.json”.

A file like this is opened.

    "editor.minimap.enabled": false,
    "editor.fontFamily": "Selfelected1337 Regular", Consolas, "Courier New", monospace,
    "window.zoomLevel": 0,
    "editor.lineNumbers": "off",
    "typescript.updateImportsOnFileMove.enabled": "always",
    "editor.unfoldOnClickAfterEndOfLine": true,
    "editor.columnSelection": false,
    "workbench.colorTheme": "Tomorrow Night Blue",
    "workbench.preferredDarkColorTheme": "Default Light+",

(yupp, that’s my own font, Selfelected1337)

Add your setting.

    "workbench.preferredDarkColorTheme": "Default Light+",

    "workbench.colorCustomizations": {
        "editor.background": "#005ccc"

If found the answer github repo which led to official docs.
How to change other colours still eludes me.


I have found documentation for all? colours and now my theme overide is:

"workbench.colorCustomizations": {
    "editor.background": "#005ccc",
    "sideBar.background": "#0073ff",
    "activityBar.background": "#1a81ff",

Cosmosdb change feed and deleted items

October 23rd, 2019

Until Microsoft implements change feed notifications for deletions we have to soft delete items in Cosmosdb if we use change feed notifications.


Cosmosdb has a handy feature where it journals changes which can then be read in another process. My use was for updating an Azure search index (Elastic search variant) whenever I made a change.

But… how do we handle deletions?

Hidden in the documentation is the information that ,,albeit all changes (within a shard) is guaranteed to be in chronological order it is always the last (present) item handed to the change feed process. So when an item is deleted there is no item and, due to implementation, also no event.

Remedy 1: Soft delete the item by marking it as “deleted”. This is a common approach in many a system.
A drawback is that the repository will end up with stale data.

Remedy 2: Soft delete the item as above. Then make sure this information has been conveyed (in my case the item should be deleted from the search database) before properly deleting it.
This is a more complex solution where the logic still has to handle soft deleted items while also adding the complexity of yet a process to scan(?) the repo for items to delete.

Your turn

I have found no uservoice, github or azurefeedback item for voting on getting a delete event; the closest is an item for getting a event for it in Azurefunctions.
In lack of better place I voted there; so can you if you have the need.


I wrote a suggestion of my own here at azurefeedback.
I did try to find an existing suggestion but failed. Am I the only one deleting data? Or the guys at Microsoft will find an already existing suggestion where I can move my votes.


The functionality is on its way
Support for deletes on Change feed is planned. Do not have an exact ETA but we are targeting some time in 2020.

Possibly possible to install Powershell with one line of code

July 27th, 2019

Scott Hanselman wrote about installing Powershell as a global tool here.

It goes something like:

dotnet tool install --global PowerShell


As Windows10 nowadays comes with Powershell this is not so much of a problem any more.

Dotnet framework design guidelines

July 7th, 2019

There is an MSDN article a book on the subject but since it is more than 10 pages only few have read it.

Alas the Corefx team created a short list with stuff here: https://github.com/dotnet/corefx/blob/master/Documentation/coding-guidelines/framework-design-guidelines-digest.md

It is much easier to read

Comments about rules I have found but often not followed

“Do not postfix enums with Enum.” To be honest – I have often found it the best solution to postfix with Enum.

“Do not organise namespaces after company hierarchy.” Even though Conway’s law is a thing, a system should not keep the history of a changed organisation chart.

“Do not use List<T> on public methods.” List<T> is a complex beast. But using IEnumerable<T> might have some reiteration performance impact, that is when you have to loop through the same collection twice.

Other comments

“Carefully choose names for your types, methods, and parameters.” Naming things can be hard so take your time and discuss with your colleagues.

“Do not create mutable value types.” I totally agree. It is easier to debug imutable. Often when I track down a but I have only a (bad) call stack and the name of a public method and some source code. Then it is very important the code is easy to follow by hand.

“Do not throw

.” I can count on the fingers on one hand the people, beside me, that bother with writing a proper exception. Visual studio makes it easy, just write ‘exception’ and then tab and you get the full template.

“Members returning arrays should return copies of an internal master array.” I is good OOP practice to not publish internal stuff. Correction, it is cruical OOP practice to not expose the innards of a class.

Other other comments

“Prefer classes over interfaces.” Why? Context please.

IMO the linked article forgot to mention that public methods should not have optional parameters as they are compiled into the caller and not callee.

Avoid public as any change to them might break the API. Unfortunately Visual studio defaults new classes (and methods?) to public so I see them everywhere.

Experimenting with setting up a new machine every third month

April 3rd, 2019

I am currently experimenting with using a virtual machine for my development. I have earlier done it through OSX/Win by the means of Parallells but now I am trying a Win/Win solution with Hyper-V.

Every 30 days or third month, I have seen both, is for how long the license is valid, I do a Hyper-V Manager->Quick create->Windows 10 dev environment and 30 minutes later, or so, the new VM is up and running.

Microsoft packages and delivers the new download on the very day of expiry so it is not possible to download a VM a day before and prep it.
It means the VM is out of date the moment you have installed the new one.

But there is a work around, open a console in admin and

slmgr –rearm
and you have 90(?) new days. This can only be done once per VM.

Also note that the Hyper-V manager gui, as depicted below, does not refresh its “Create virtual-machine”-content so the date of the template might be old. Restart (the host machine?) to refresh it.

The mandatory screen shot.

It comes with Visual studio, Visual studio code, Powershell 6 and some dotnet preinstalled. All I have to do is start VS and tell it to update itself..

Then I need Git, Notepad++, VSCode, Posh-git Keyboard1337 and BecerroInamovible. Ergo I need Chocolatey too.

Here is how I do it, the explained way

Fire up a console with elevated priveges.

Window-button, cmd, ctrl-shift-enter. Enter.

Window-button, cmd, ctrl-shift-enter. Enter.

Install Chocolatey.

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" &amp;&amp; SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Restart console.

I have checked that all chocolatey packages I reference are “trusted package”. I cannot know if they packages remain “trusted package” at the time you are reading this. The choice is yours.

Exit. Enter.
Window-button, cmd, ctrl-shift-enter. Enter.

Install Git.

choco install git.install

Install Notepad++.

choco install notepadplusplus.install

Install Posh-Git

PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
Add-PoshGitToProfile -AllHosts

To make it even cooler one can install more stuff, like oh-my-posh. For it to work one needs a new font “Cascadia Code”, and Windows terminal has to be updated to use it.

"fontFace":  "Cascadia Code PL"

Import-Module oh-my-posh


Install Powershell core

choco install powershell-core


winget install --name PowerShell --exact

Install Keyboard1337.

I believe Keyboard1337 is a zip if you git clone BecarroInamovible. If so, you don’t have to download Keyboard1337.

Otherwise download

Keyboad 1337.zip
. Unblock. Unpack. Install.
Run Keyboard 1337\l337\setup.exe (yupp. there’s a typo there)
Language preferences -> Keep English(Sweden) and English(United States). The latter is Keyboard1337


It has a dependency on Autohotkey.

choco install autohotkey

Copy contents of


As an alternative do ”

git clone https://github.com/LosManos/keyboard1337.git

As short as possible:

@”%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe” -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command “iex ((New-Object System.Net.WebClient).DownloadString(‘https://chocolatey.org/install.ps1’))” && SET “PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin”

choco install git.install -y & choco install notepadplusplus.install -y & choco install autohotkey -yt

winget install –name PowerShell –exact

Start a powershell terminal:

PowerShellGet\Install-Module posh-git -Scope CurrentUser -Force ; Add-PoshGitToProfile -AllHosts

In a powershell terminal:

mkdir c:\DATA ; mkdir c:\DATA\PROJEKT ; pushd c:\DATA\PROJEKT ; git clone https://github.com/LosManos/keyboard1337.git ;

& ‘C:\Program Files\AutoHotkey\AutoHotkeyU64.exe’ C:\DATA\PROJEKT\keyboard1337\BecerroInamovible.ahk ; popd

Expand-Archive ‘C:\DATA\PROJEKT\keyboard1337\Keyboard 1337.zip’ -DestinationPath C:\DATA\PROJEKT\keyboard1337\ ; C:\DATA\PROJEKT\keyboard1337\l337\setup.exe