Mocking ADAL for Unit Tests

Active Directory Authentication Library (ADAL) provides developers with great experiences to easily integrate Azure Active Directory (AAD) with their application for authentication and authorisation. With minimum efforts, we can implement OAuth authentication against AAD, using ADAL. However, in the unit testing world, it’s not that easy to test application when the application uses ADAL because ADAL is not unit-testable. We don’t test ADAL itself, but we do need mock it to test applications using ADAL. In this post, we are going to implement how to implement wrapper classes for ADAL’s AuthenticationContext, AuthenticationResult and DeviceCodeResult.… [Keep reading] “Mocking ADAL for Unit Tests”

Converting Web.config values into enum or List

While developing .NET applications, we always look for configuration values stored in either Web.config or App.config. We can simply use the <appSettings>…</appSettings> section which is converted to a dictionary or key/value pair object. Can we use a strongly-typed object for the configuration? Yes, we can. With the <configSections>…</configSections> node, we can convert configuration values into strongly-typed objects. This is a very useful feature in most cases. However, what if we have requirements like:

  • I want to convert a string value into an enum value, regardless of the case sensitivity.
[Keep reading] “Converting Web.config values into enum or List”

Azure WebJobs with .NET Core RC2

With .NET Core RC2, publishing Azure WebJob is a little bit different from the traditional(?) way, even it’s different from what RC1 does. In this post, we’ll walk through how to publish Azure WebJob using a .NET Core RC2 console application.

Sample code can be found at https://github.com/devkimchi/.NET-Core-for-Azure-WebJob-Sample.

Sample Hello World Console Application

OK. First thing’s first. Let’s create a console app using .NET Core RC2. Take the latest copy from the repository above and build it on your local machine.… [Keep reading] “Azure WebJobs with .NET Core RC2”

Building .NET Core Application on Amazon Linux

In order to run .NET applications on Linux operating systems, Mono used to be the only option. Now, Microsoft has released .NET Core that can build and run .NET applications on any OS including Windows, OSX and Linux. In this post, we are going to install both .NET Core Framework RC1 and RC2, build and run a simple Hello World application, and compare RC1 to RC2.

Installing .NET Core RC1

By following the official document, Installing ASP.NET[Keep reading] “Building .NET Core Application on Amazon Linux”

Installing Mono into Amazon Linux

There are a couple of ways to run C# applications on Linux operating systems. Before .NET Core, Mono used to be the only way for C# applications running on Linux machine. Each Linux distro has a different method to install Mono. In this post, we’ll walk through how to install Mono on Amazon Linux.

NOTE: Amazon Linux 2016.03.1 was used for this post.

According to the official document, we can follow the CentOS way.… [Keep reading] “Installing Mono into Amazon Linux”

Entity Framework 7 Data Migration through KUDU

From DevOps perspective, everything needs to be automated in regards to application setup and deployment. There’s no exception for database migration. If database schema change occurs, it should be automatically applied before/after the application deployment. Unlike Entity Framework 6.x using PowerShell cmdlets for database migration, Entity Framework 7 (EF7) uses DNX for it.

Applying Database Migration with EF7

In EF7, updating database change can be done by running the following command:

[Keep reading] “Entity Framework 7 Data Migration through KUDU”

Long Path Error While Publishing ASP.NET Core Applications

If you are writing an ASP.NET Core application, there are chances to publish your app to either a Azure Website or another place, by right-mouse clicking in Visual Studio.

In most cases, it should be alright. However, if your app has a NuGet package with a long name, it would be an issue. You might be seeing an error like this:

DNU(0,0): Error : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.

[Keep reading] “Long Path Error While Publishing ASP.NET Core Applications”

Creating Accounts on Azure SQL Database through PowerShell Automation

In the previous post, Azure SQL Pro Tip – Creating Login Account and User, we have briefly walked through how to create login accounts on Azure SQL Database through SSMS. Using SSMS is of course the very convenient way. However, as a DevOps engineer, I want to automate this process through PowerShell. In this post, we’re going to walk through how to achieve this goal.

Step #1: Create Azure SQL Database

First of all, we need an Azure SQL Database.… [Keep reading] “Creating Accounts on Azure SQL Database through PowerShell Automation”

Azure SQL Pro Tip – Creating Login Account and User

With Azure Resource Manager (ARM), while creating an Azure SQL Database instance, we can only set up an admin account. As we all know, using this admin account is not safe in most cases. Therefore, we need to create another accounts with fewer privileges.

However, unlike MS SQL Server, Azure SQL Database has some restrictions. Those restrictions also apply to create login accounts and users. In this post, we are going to create login accounts with limited permissions on Azure SQL Database.… [Keep reading] “Azure SQL Pro Tip – Creating Login Account and User”

ASP.NET Core Tips & Tricks – Global Exception Handling

Exception handling is one of most important but irritating jobs for developers. There are tons of articles about the importance of exception handling. Fortunately, ASP.NET Core application has got a lot of improvement for exception handling through the request/response pipeline. In this article, we’re going to have a brief look how we can handle exceptions.

Sample application can be found here: https://github.com/devkimchi/ASP.NET-Core-Tips-and-Tricks-Sample

Global Exception Filter – OWIN Pipeline

Unlike ASP.NET MVC applications, ASP.NET Core applications only use OWIN pipelines to handle requests and responses.… [Keep reading] “ASP.NET Core Tips & Tricks – Global Exception Handling”