web 2.0

Building a Nuget Server with gold plating

Last week, Phil Haack wrote a post on how to build a NuGet Server. A NuGet server is really easy to build because 90% of the work is done by running a NuGet command. Just for fun, I decided to add some extra functionality to my NuGet Server such as a package upload form and a formatted list of packages.  In preparing my NuGet server, I followed Phil’s direction to a tee except for the fact that I used a “empty MVC 3 app with Razor support” instead of using a “ASP.NET Empty Web Application”. Out of the box, you will get a barebones, but fully functional NuGet server that provides the package list in Atom Format. For each package in the repository you will get access to properties such as the version number, license information, tags and etcetera. However, since I am not a fan of reading XML I thought it would be useful to transform that XML into HTML using XSLT. This way I can see the list of available packages without opening up Visual Studio. XSLT is one of those technologies t... [More]

Using RavenDB with ASP.NET MVC

Traditionally when you think about a database you think of tables, views, indexes and stored procedures. If you have made a career out of developing database centric applications like I have, then chances are that you have spent a great deal of time dealing with issues around referential integrity, normalization and performance. Unless you have been living underneath a rock, then you have probably heard of the newest database trend named NoSQL. NoSQL refers to non relational document databases that help address issues like performance and scalability which are often hard to achieve when using traditional database systems such as SQL or Oracle.  NoSQL replaces the old “scale up” mantra of database management  with a new one: “scale out.” Instead of adding bigger servers to handle more data load, a NoSQL database allows a company to distribute the load across multiple hosts as the load increases. In case you are wondering many successful companies such ... [More]

Charting with JavaScript

Last week a co-worker of mine sent me a link for the gRaphaël charting library. gRaphaël is a full fledged charting library written entirely in JavaScript. Normally when I need to do charting on a website I resort to using the Microsoft Chart Controls. Unfortunately the MS Chart Controls run on the server side, rely on IIS and tend to a require a slight learning curve before you can become efficient with them. Since the gRaphaël library is written in JavaScript it is lightweight, easy to use and it will run in almost any browser. Since seeing is believing, here is a walkthrough on how to create your first pie chart with gRaphaël:   Step One - add a script reference to the raphael.js and g.raphael.js. These two files are required no matter what type of chart you are trying to render. <script src="http://raphaeljs.com/raphael.js" type="text/javascript" charset="utf-8"></script> <script src="http://g.raphaeljs.com/g.raphael.js&qu... [More]

Automatic Resource File Translation via Google Translate

One of the features that I support in WeBlog is localization. That means that all the labels, buttons and text within the application are stored in a resource file. So if you switch from English to Spanish, the text will be automatically displayed in the right language. For more information about how this magic happens, read this article. Since I am only fluent in English I depend on Google translator to make the translations for me. After about 10 minutes of manually translating a spanish resource file, I decided that I needed a way to automate the process. I did a quick Google search and discovered that the translator service utilizes a JSON based API. A little more searching and I found a class library written by Alex Meyer-Gleaves which takes care of making the service calls to the translator API and parsing the results. So the only work I had to do was read the resource file, invoke the translator via Alex’s C# library and save the translated data to a new resource file. Turns o... [More]

Unit Testing Secure Controller Actions with Moq

One of the hardest things to unit test in MVC is security. Security is tough to test because there is a lot of setup involved in mocking the HttpContext, the Principal and the Identity. For example, in WeBlog I am using the following code in the Edit Post action. Post post = Repository.FirstOrDefault<Post>(x => x.ID == id); if (post == null) return View("NotFound"); if (!HttpContext.User.CanEditPost(post)) return View("PermissionDenied"); In order to make sure this code works properly I need to test it with an authorized and unauthorized user. Unfortunately, the HttpContext.User will not automatically be created for your tests so you have to mock one for each test that your perform. So lets start this journey by reviewing the code required to mock the HttpContext using the popular opensource library Moq. This code is a combination of code I discovered on Stackoverflow and Scott Hanselman’s MvcMockHelpers: MockContext public static Mock<Htt... [More]