Tag Archives: asp.net mvc

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

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

Bootstrap validation in ASP.Net MVC

I use Bootstrap in almost every project I build these days. I build up a custom Bootstrap configuration to reduce bloat, and have my workflow down-pat for updating those configurations (which I’ll write about in the near future). I have familiarised myself with it’s ins-and-outs to help ensure I use it to it’s full potential without being overkill, and it has sped up my HTML build time immensely.

One issue I’ve come across before is finding harmony between ASP.Net MVC’s validation and Bootstrap’s validation classes.

Read More