Small reminder how to fake User.Identity.IsAuthenticated and User.Identity.Name inside unit tests, while testing controller code. It’s not so obvious and I often forget this small trick, which is also important when writing user authentication code (login).

In unit test we want to validate model properties, specially CanWriteStory which has to be True if user is authenticated.

Simple unit test for this controller:

This test will pass (User.Identity.IsAuthenticated will be True) because we configured authentication type “someAuthTypeName” (here and here)! Without looking at MVC source code it would take me a long time to figure that out, and to be honest correlation between IsAuthenticated and AuthenticationType is still little bit confusing.

The test also shows how simple it is to set HttpContext to controller, without need of using some mocking framework. If I’m brave enough, I would try to write similar test for WebForms and Page class, but I’m not

Same rule, with setting of authentication type applies when writing custom login code, which looks probably something like this:

If you try to install latest .NET Core SDK 1.0.1 on Mint 18 or Elementary OS Loki (based on Ubuntu 14.04 and 16.04 LTS) by following instructions on http://get.asp.net, you might see this error:

mint-vbox hudo # sudo apt-get install dotnet-dev-1.0.0-preview2-003131Reading package lists... DoneBuilding dependency tree Reading state information... DoneSome packages could not be installed. This may mean that you haverequested an impossible situation or if you are using the unstabledistribution that some required packages have not yet been createdor been moved out of Incoming.The following information may help to resolve the situation:

The following packages have unmet dependencies:dotnet-dev-1.0.0-preview2-003131 : Depends: dotnet-sharedframework-microsoft.netcore.app-1.0.1 but it is not going to be installedE: Unable to correct problems, you have held broken packages.

dotnet-sharedframework-microsoft.netcore.app-1.0.1 is missing, but if you try to apt-get that, then dependent libicu52 is missing, only libicu55 is in Ubuntu repository.

Since we can’t just execute this .deb by double-clicking on it (at least on Elementary OS), we have to move it to repo cache and use apt-get install, or better, use gdebi utility (Mint 18 already includes it):

sudo apt-get install gdebi

If we double-click to downloaded .deb file now, a window will appear offering:

After that, executing last .net core installation step takes us to the happy place :

Setting up dotnet-sharedframework-microsoft.netcore.app-1.0.1 (1.0.1-1) ...Setting up dotnet-dev-1.0.0-preview2-003131 (1.0.0-preview2-003131-1) ...This software may collect information about you and your use of the software, and send that to Microsoft.Please visit http://aka.ms/dotnet-cli-eula for more information.Processing triggers for libc-bin (2.23-0ubuntu4) ...hudo-VirtualBox hudo # dotnet

Visual Studio Code and Omnisharp support

Since elementary OS 0.4 Loki, platform Id changed from “elementary OS” to “elementary”. To fix Omnisharp problem of not recognizing this version of OS, edit platform.js file in /home/username/.vscode/extensions/ms-vscode.csharp-1.4.1/out/ by changing line (I removed “OS” in line 76):

case 'elementary':

on mint, this case branch needs to be added to the end of switch statement: