Tag Archives: asp.net

Development

Mocking users in ASP.NET MVC 5

So historically unit testing has been a constant non-starter for me. It seems every time I start to write unit tests (whether it’s in an attempt to do some TDD, or just trying produce unit tests for an existing piece of code), I struggle to get over the hump of dependencies that I’ve incidentally placed in my way without even thinking.

Things as simple as getting the current user’s ID using User.Identity.GetUserId() seem harmless, until you realise that in your test the User object will be null.

When dealing with dependencies in the code that you are testing, a common method is to replace these dependencies with a mock. For example, say you have a service which calls off to an external API to get some data; in your test code, you could mock (aka “fake”) that service to just return some fake data rather than calling to the external API.

Read More
Development

Moving Entity Framework migrations to another project

This happens to me quite often, because of the way I tend to work with new projects: I’ve created a new web application, got it up and running and set up my initial code first migration, start working on the model (maybe another few migrations for new tables etc) and then realise that I want to move the database to a separate “data layer” project AFTER I’ve already started running the migrations.

So I move my Entity Framework DB context, my model POCOs and my Migrations folder out to the new project, and update all the namespaces to be right (e.g. “SiteName.Data” rather than “SiteName.Web”).

Read More
Development

Setting up SendGrid 7.0.0 in ASP.NET

Screenshot 2016-06-29 13.51.30

Today I was starting up a new ASP.NET Web Application using the ASP.NET Identity membership system, for a micro site I’m building, and my first task was to get the email confirmation working for accounts (and subsequently to prevent logging in until email has been confirmed). I decided to try out SendGrid rather than using my own SMTP server, mostly because, well, Microsoft told me I should 😉

Read More
Development

ASP.NET WebForms ScriptResource error

You know those days when you wonder how you stay sane in this line of work?!  I’ve just come across a little gotcha that I’ve just spent almost an hour trying to nut out, so thought I’d share a potential time saver with others!

Read More
Development

Developer Tip: ASP.NET Configuration in Visual Studio 2010

I’ve just come across a strange issue in Visual Studio 2010, when trying to launch and access the ASP.NET Configuration tool (used for configuring security settings).

When I tried to access the site by selecting it from the Project menu, it would start the local web server on whatever port it chose, but wouldn’t open the page in my browser automatically. So I manually opened the link by right-clicking the icon for the web server in the system tray and choosing “Open in Web Browser”.

Read More