Blog Posts for: 5

Unit testing ASP.NET 5 Controllers with Entity Framework 7 In-Memory Database

24 November 2015

Introduction A number of months ago I wrote about how you could unit test with Entity Framework using a fake DbSet and NBuilder. It’s been almost 4 months since that post and I have done quite a lot of work using ASP.NET 5 in the meantime. So I thought I would write an updated version of that blog post, using ASP.NET 5 and Entity Framework 7. In this blog post I am going to show you a very simple scenario where I have a ProductsController class which displays a list of products, and also allows the user to select a product and navigate to a details page.

Allowing user to set culture settings in ASP.NET 5: Part 2

10 November 2015

Introduction In my previous blog post I demonstrated how we can allow the user to save their culture preferences, and then apply the correct culture preferences once the user has signed in. We allowed the user to set the Culture and the UI Culture, but I think in a real world scenario that is not very realistic. Typically we will want to give the user more fine-grained control to set their language, date format, time format, currency etc.

Allowing user to set culture settings in ASP.NET 5: Part 1

03 November 2015

In a previous blog post I demonstrated how ASP.NET 5 determines which Culture settings to use when serving a request. That is fine for many cases, but in some instances you want to allow users to save their culture settings preferences in their user profile. This is Part 1 in a 2 part series when I will demonstrate how you can do this. In this blog post I will show you how we can allow a user to pick a specific culture and then save that against their user profile.

Moving your Entity Framework 7 models to an external project

27 October 2015

Introduction In most of my projects - except perhaps for the most basic ones - I like to keep my Entity Framework data context and models in a separate project from my main ASP.NET application, so I can easily share it amongst other projects in the solution. I had to figure out how to do this in a new ASP.NET 5 project recently, and could not find any sort of guidance for this available on the web.

How ASP.NET 5 determines the culture settings for localization

20 October 2015

Introduction In ASP.NET 5, the Localization middleware can be used to ensure the correct culture settings are applied when serving a request. In this blog post I will walk you through the process which the Localization middleware takes to determine the correct culture settings to use when serving a request. I am using Beta 8, and have created a simple web application using the ASP.NET 5 Yeoman generator. Configuring the Localization middleware The first thing you will need to do is to enable the Localization middleware inside your application.

Unit testing controllers in ASP.NET 5 (MVC 6)

13 October 2015

Introduction Part of my journey in working with ASP.NET is figuring out how to replace the way in which I did things before with a more appropriate way of doing it in ASP.NET 5. One of these is figuring out how to test my controllers. Previously in ASP.NET MVC 5 I used the awesome FluentMVCTesting library, but currently it does not support ASP.NET 5, so I had to revert back to the old ways of doing things.

Setting the thread culture in ASP.NET 5

06 October 2015

Introduction I recently had to figure out how to set the Culture in an ASP.NET 5 application to a specific setting. The documentation on this is still non-existing, so this is how I figured out doing it by looking at Damian Edwards’ i18nStarterWeb sample project on Github. This information is current as of Beta 7. It may change in the future. The ASP.NET 4.6 way In ASP.NET 4.6 and before there were two typical ways in which you would be able to set the Culture and UI Culture to a specific value for a website.

Using enums with the ASP.NET 5 (MVC 6) Select TagHelper

29 September 2015

Introduction In a previous blog post I demonstrated the support for option groups in the new Select TagHelper in MVC 6. Someone asked about using enums with the Select TagHelper, so let us look at how you can use enums with the TagHelper. This blog post is based on ASP.NET 5 Beta 7. Basic binding For demonstration purposes, let us assume that we have an enum type with the list of possible relationship types:

Using Option Groups with the Select TagHelper in MVC 6

15 September 2015

Introduction In MVC 6 we are switching away from the use of the classical HTML Helpers in our Razor views to use TagHelpers instead. Various posts have been written about the new TagHelpers in MVC 6. If you are not familiar with them, then a good place to start would be Dave Paquette’s Complete Guide to the MVC 6 Tag Helpers or Matthew Jones’ Tag Helpers in ASP.NET 5 - An Overview.