Tue, Apr 30, 2013

Mocking HttpContext with Fake It Easy

Lets start with the conclusion first and say “use Nancy for your web applications and APIs” as its brilliant!

If you want to continue reading lets crack on.

I’m currently working on a ASP.Net MVC project and one of the controller methods writes directly to the Response, eg. Response.Write(“How will I mock thee?”);

Having moved over to xUnit and FakeItEasy recently I wanted to write a unit or integration test depending how you see it to assert against the Http Response.

Doing this is no easy feat with MVC (with Nancy its all done for you) and you have to mock a lot of things. I’m hoping that in later releases this will be fixed because I know that ASP.Net Web API has made things a bit easier for testing (and wrote a testing library for it) so I assume the two projects will use bits of each other or their roadmap will merge.

Wed, Apr 17, 2013

Up & Running with TypeScript and WebStorm

I love my iMac and I’m on a mission to find a language I enjoy that I can use my Mac for (no Windows fan boy jokes please). There’s something in my mind I associate with work and my Windows laptop. Therefore, I don’t feel to excited about getting my laptop out of my bag in the evenings/weekends to play with other stuff.

As I want to broaden my knowledge I wanted to find something ideally statically typed (although I’m currently looking into Python) that would work on OS X. I’ve said previously that JavaScript seems the way to go in my current situation so I thought I’d take a look at TypeScript and also use WebStorm from Jetbrains as my IDE seeing as I’ve heard so many great things about them and their products (don’t worry I use ReSharper).

TypeScript

So I went over to TypeScript’s website and followed the Hello World type code examples under the “Learn” tab.

Mon, Apr 8, 2013

Using a Markdown ViewEngine with Nancy

Whilst using stackoverflow.com and Github gists I’ve become a frequent user of Markdown.

For those of you that don’t know what Markdown is, its essentially a shorter/cleaner syntax that can be parsed to produce HTML. Below are a few examples:

#Hello World!
## You're awesome!
The quick brown fox jumped over the lazy coder
What the **hell** is this?
This is an [example link](http://example.com/)

<h1>Hello World!</h1>
<h2>You're awesome!</h2>
<p>The quick brown fox jumped over the lazy coder</p>
What the <strong>hell</strong> is this?
This is an <a href="http://example.com/"> example link</a>

You can see more examples in the earlier link.

When you’re writing a blog post or a lengthy page in your web app with lots of HTML it maybe easier to use Markdown as your preferred syntax. I currently use WordPress for my blog, it’s ok but its quite bloated for probably what I need. I looked into Calepin and Scriptogr.am as alternative blogging platforms but I felt it didn’t quite offer what I wanted but the approach was a good idea. It meant you could write a blog post and simply put the file in dropbox and it would appear on your blog.

Mon, Apr 8, 2013

Using DateTime in C# and SQL

I’m sure there are millions of blog posts out there that already discuss this but I think its worth noting down even if its just something for me to remember.

Store your datetimes in UTC format into the database. Unfortunately this mean executing something like: myObject.ExpiryDate = TimeZoneInfo.ConvertTimeToUtc(dateTime, TimeZoneInfo.FindSystemTimeZoneById(“timezoneid of users”)

In every central place where you update/insert DateTime values on your objects you will need the above.

When you display any DateTime information it must display as a local datetime value. You can do this by using myObject.ExpiryDate.ToLocalTime()

Tue, Apr 2, 2013

The Old Development Language Switcheroo

As a C# developer I think I’m pretty safe in saying that its not going away any time soon however, its my opinion that to not become irrelevant you need to have options. Some may argue that its better to be master of one than a Jack of all trades but lets just say you can’t find your next job in the primary language you want to work in. What do you do?

I have looked more into JavaScript recently and with that comes server and client scope for the use of the language so with some understanding of JS that would be probably the best bet for me however, as much as this may annoy some I think I actually prefer statically typed languages.

Now I know there is TypeScript that I could use for my node.js apps but I see that as more of a workaround and not a core feature of JavaScript. I’m not saying anything bad against JS and the libraries/frameworks that I have used I like but I just find it easier to learn and know what I can do when I have decent intellisense showing me what I can do with my code.

Mon, Mar 4, 2013

The many approaches to Entity Framework

I recently had a need to look into using Entity Framework (EF) for a ASP.NET MVC project. In the past I have always used PetaPoco as my ORM of choice and with hearing nothing but bad things about EF I was a little sceptical. There are various ways to use EF, Code First being one of them and the easiest from what I can gather and luckily the approach I needed to get up to speed on. This means you can define your model in code and EF will turn that into tables in your database.

The way I was going to see how EF could be architected in an application was to create a MVC application that provided CRUD capabilities for Customers, Orders and Products. Nothing complicated but something enough to see how EF could be fitted in with a MVC application. I would also like to use a unit of work pattern such as instantiate a model class, set some properties and call a save method. I would also like to keep the architecture well enough abstracted so that another ORM could take its place easily enough if needs be.

I will list the various approaches I took investigating the how EF could be integrated. They are not in any chronological order.

Tue, Feb 5, 2013

Evaluating KnockoutJS and AngularJS – Part 1

As I stated in my earlier post “JavaScript is the future…maybe” so with that in mind I had to brush up my JS skills and get more involved with the language’s core concepts so after watching some videos and reading some articles I was ready to look at KnockoutJS and AngularJS.

Before I actually looked at these two I spent some time with SammyJS but realised afterwards it was mainly MVC based and not around 2-way binding that Knockout and Angular offer. However, I really liked it and it seemed very familiar and easy to use, the reason being it was inspired by Sinatra which we all know Nancy was also inspired by and we also know how much I like Nancy!

Getting to grips with any language or frameworks is tricky and the best way to do it is to write an application using it. The next difficult thing to overcome is an idea for writing an application. ToDo list’s are very common with JavaScript frameworks and there is a whole website for you to peruse but after looking at SammyJS and their docs they walk through writing a simple shopping basket so I thought I’d use that.

Menu