Sunday, July 14, 2013

Use XUnit to Run QUnit Tests

I read a great article recently about Unit testing JavaScript in VisualStudio with ReSharper, written by Chris Seroka. As cool as this feature is, it left me with two questions:

  1. What about developers that do not have ReSharper?
  2. How do I run my JavaScript unit tests on a builder server?

It is no secret that I, absolutely, love, xUnit! Thus I decided to extend xUnit theories to be able to run QUnit tests by implementing a new DataAttribute.

Introducing XUnit.PhantomQ

XUnit.PhantomQ is a little NuGet package you can install to get access to the QUnitDataAttribute (see below for an example). This library will allow you to execute your QUnit tests as XUnit tests.

XUnit.PhantomQ supports both library and web projects, and features the ability to easily specify test files and their dependencies by real relative path to the root of your project.

XUnit.PhantomQ on NuGet
XUnit.PhantomQ Source on GitHub

QUnitData Attribute

Here is an example of writing some JavaScript, a file of QUnit tests, and then using an xUnit theory and a QUnitData Attribute to execute all of those tests right inside of Visual Studio.

// Contents of Demo.js
function getFive() {
    return 5;
// Contents of Tests.js
test('Test Five', function() {
    var actual = getFive();
    equal(actual, 5);
test('Test Not Four', function () {
    var actual = getFive();
    notEqual(actual, 4);
// Contents of QUnitTests.cs
public class QUnitTests
    [Theory, QUnitData("Tests.js", "Demo.js")]
    public void ReturnFiveTests(QUnitTest test)

Integrating XUnit, PhantomJS, and QUnit

So, how does this thing work under the hood? Below is the complete pipeline, step by step, of whenever the tests are executed:

  1. The XUnit test runner identifies your theory tests.
  2. The QUnitDataAttribute is invoked.
  3. A static helper locates PhantomJS.exe and the root folder of your project.
    • It will automatically walk up the folder structure and try to find PhantomJS.exe in your packages folder. However, you can override this and explicitly set the full path by adding an AppSetting to your config file:
      <add key="PhantomQ.PhantomJsExePath" value="C:/PhantomJS.exe" />
    • The same goes for the root of your project, you can override this location with another AppSetting to your config:
      <add key="PhantomQ.WorkingDirectory" value="C:/Code/DemoProject" />
  4. PhantomJS.exe is invoked as a separate process.
  5. The server loads up XUnit.PhantomQ.Server.js
  6. The server now opens XUnit.PhantomQ.html
  7. QUnit is set to autoRun false.
  8. Event handlers are added to QUnit for testDone and done.
  9. All of the dependencies are now added to the page as script tags.
  10. The test file itself is loaded.
  11. QUnit.start is invoked.
  12. The server waits for the test to complete.
  13. Upon completion the server reads the results out of the page.
  14. The tests and their results are serialized to a JSON dictionary.
  15. The result dictionary is written to the standard output.
  16. The resulting JSON string is read in from the process output.
  17. The results are deserialized using Newtonsoft.JSON
  18. The results are loaded into QUnitTest objects.
  19. The QUnitTest array is passed back from the DataAttribute
  20. Each test run finally calls the AssertSuccess and throws on failure.

...and that's (finally) all folks! If you have any questions, comments, or thoughts on how this could be improved, please let me know!

Shout it


Sunday, July 7, 2013

Lucene.Net Analyzer Viewer for RavenDB

To query your data in RavenDB you need to write queries in Lucene.Net.

To know which documents your queries are going to return means that you need to know exactly how your query is being parsed by Lucene.Net. Full text analysis is a great baked in feature of RavenDB, but I have found that they Lucene.NET standard analyzer that parses full text fields can sometimes return surprising results.

This Lucene.Net 3.0 Analyzer Viewer is an update of Andrew Smith's original version for Lucene.Net 2.0. This update now allows you to view the results of text analysis for the same version of Lucene that RavenDB is using. This simple tool can be invaluable to debugging full text searches in RavenDB!

Download Raven.Extensions.AnalyzerViewer from GitHub

This tool also comes with my Alphanumeric Analyzer built in.

Shout it


Final Fantasy XIV: A Realm Reborn - Beta Review

Last month I had said that this blog would return to it's normal .NET ramblings, and I meant it...but then I got into the Final Fantasy XIV: A Realm Reborn Beta. To anyone checking in here for tech articles, do not despair; I will write extra posts this month to make up for yet another gaming distraction!

Also, please remember that this review is strictly my personal opinion about a product that has not even been released yet. Anything can change, even my stubborn opinions. Enjoy!

What is back?

There are two things returning to the franchise in a Realm Reborn that die hard Final Fantasy fans have not seen in a long time.

  1. Fantasy

Final Fantasy fans, this MMO is for you. In a desperate attempt to recapture their past glory, Square Enix has pulled out all of the classic Final Fantasy elements out of storage and put them on parade. Best of all, it really works.

There is Chocobo song plays when you mount up and ride. Old school combat music kicks off every fight, and the classic victory theme plays after you defeat bosses. There are moogles, airships with balloons, and mages with robes. Heck, there is even Magitech armor from FF VI! This game has become an overdue homage to the long since past golden era of Final Fantasy.

A realm reborn succeeds in reminding me not just how much I enjoyed the classic Final Fantasy games, but also how much I have missed them.

  1. Panties

There are an absurd amount of mini skirts and panty shots in this game, to the point where even I start to think that it is in bad taste...and believe me, that is saying a lot. The starting outfits make it seem like either all adventures bought their armor from a Victoria's Secret catalog, or that they are escaping a life of servitude from their home country's red light district.

For a long time now I have said that Square Enix can make amazing artwork, but that I dislike the art style they have chosen. Their landscapes, spells, and monsters all look great, but their character models have have boobs, underwear, and pectoral muscles popping out everywhere. You could argue that this is just an innocent cultural difference, but I don't see how that would make a battle thong (yes, that is in the game) any more practical.

What is new?

Not much. However what is new does work very well, and these strengths are what the game is betting on to succeed in an over crowded MMO market.

  1. A fresh take on the class system.

Your character may change class and level simply by swapping out your primary weapon. This means that you are free to play as many classes as you would like without have to redo your skills or professions. It also means that you may then take select abilities from one class and add them to another. Thus your archers may heal, and your tanks may cast fire. It is an absolutely fantastic system that I am sure will provide untold amounts of customization and experimentation for hard core and casual players alike.

  1. Some dynamic new questing mechanisms.

The fate system adds a fun and spontaneous social aspect to group PVE combat. Levequests, while horribly named, are a great new way to offer more dynamic single player oriented question. These are both great additions to the game play that go a long way towards helping distract players from the MMO grind.

  1. Good story telling.

I will give Final Fantasy XIV credit, the main quest line is filled with cut scenes that actually make you feel like you are playing a Final Fantasy game. The primary story provides a nice sense of both progression and grounding, offering up a relatively personal touch to an otherwise generic save the world plot.

  1. A much needed UI overhaul.

I really do not have to say much about the new interface other than it is not the old one. Menus no longer lock the game. Questing is easy to follow and includes mini map tracking. Character creation is second to none. You can, for the most part, figure out how to do anything with a few extra exploratory clicks.

What is old?

As I hinted above, a lot of things have become stale in the world of Eor...Eorzea...Eor see why I'm not gonna want to pay for this stuff anymore?

  1. The standard MMO formula.

Do you love fetch quests? Do you love fetch quests that send you running back and forth? Do you love fetch quests that send you running back and forth through the forest? Do you love fetch quests that send you running back and forth through the forest just to deliver notes? Then boy howdy do we have the perfect game for you!

Despite my singing the praises of their new dynamic quest mechanisms, the game on whole feels static and stale. You move from node to node through your zones, taking quests, killing monsters, collection items, and watching your experience bar raise ever so slowly.

This is a time tested game design formula that works, and it does work here; but it continuously gives me a feeling of deja vu, as I have already been there and done that.

  1. Static combat mechanics.

While I really like the new customizable class system, the combat abilities feel very static. For the most part you will stand in one place and press buttons. Your characters won't jump around the battle field, you wont nimbly dodge attacks, you just kinda stand there; there is no action in this adventure.

Let me be clear: the PACE of the battle is fine, the global cool downs are usually generally around two and a half seconds, and I actually LIKE that quite a bit! I am criticizing the MOTION of combat and the lack of fluid action or movement. You don't leap to your enemies, you do not drag them to you, you do not jump over or around incoming attacks. You push buttons and try not to stand in the fire.

Perhaps this is part of the classic Final Fantasy feel that they aiming for, but again I feel like they could have done more to spice things up.

  1. The behind the scenes technology.

Zoning. The year is 2013, and a brand new, triple A development, massively multiplayer online role playing game, still has zoning. You have got to be kidding me.

Nothing says dated quite like loading screens. Worse yet, the zones are not even that big! The capital cities are each split up into multiple zones. Worse still, the mini maps are broken into these zones too, forcing you to zoom in and out to find quest objects. You have got to be kidding me!

There are other technology problems too. Characters live on specific servers instead of dynamically re-sizing due to population. The install client can not stream game content, you must be fully installed and patched to play. Their log in screen always has a temporary password prompt, what is up with that?

Square Enix is very clearly a game company, not a software company.


It may seem like I have been ragging on a Realm Reborn pretty hard through the course of this review, so let me be very clear regarding my conclusion:

Final Fantasy XIV: A Realm Reborn is a GOOD game, but it is not a great game.

What Square Enix has done to revamp XIV after it's failed launch is very impressive, but the few new mechanics that are here do not try to change the tired old MMO formula in any significant way. Square Enix is playing it safe; they have merely added a much needed fresh coat of paint to an otherwise old car. However, if you are a Final Fantasy fan then you will enjoy a Realm Reborn, at least for a while.

All that being said, a Realm Reborn is undoubtedly above average in an over saturated MMO market. It's greatest strengths are...

  1. It is all new content
  2. It unapologetically harkens back to it's classic roots.
    (For which, I will specifically give it a plus one to the final score below).

If I had to give it a number, it would be: 7/10

Game on,

Friday, July 5, 2013

Microsoft Build 2013 for Web Developers

Build 2013 was a whole lot of fun!

The big reveals at Build 2013 was Windows 8.1 and Visual Studio 2013. Admittedly Microsoft's big focus was on the Windows 8 store, but that does not mean that they are not delivering great tools for the fastest growing development environment in the world: the web!

Before we discuss web development, let's first take a moment to talk about Windows.

Windows 8.1 actually looks really good! Like all Microsoft products, the first major patch manages to iron out most of the kinks. The new UI updates and inclusion of the start button make the modern UI and desktop seem much less polarizing. Additionally, I am very optimistic about seeing Windows 8 applications come to PC, table, and phone. Microsoft has always had great potential for creating a homogeneous ecosystem consumer devices, and I am finally getting excited about the product line up that they are delivering.

New Editors in Visual Studio 2013

The Visual Studio Team has completely rewritten the HTML and JavaScript editors from scratch in Visual Studio 2013. This is great news; not only are the new editors faster, more responsive, and have much better intellisense, but they also come with a set of fun new features.

  • The overall Razor experience has been greatly improved.
  • Intellisense now include expandable groups to keep drop downs from getting cluttered.
  • CSS intellisense now displays browser compatibility for each rule.
  • New shift alt keys allows you to select content from tree structures.

Microsoft has yet to announce how they will charge for Visual Studio 2013. Will it be a stand alone install, will it be full price, we just do not know yet. Personally, I would love to see Visual Studio more to incremental update system, but obviously there would be lot of technical limitation to doing so...but hey, a dev can dream!

HTML Editing Features in Visual Studio 2013 Preview

Browser Link

Visual Studio 2013 comes with a built in feature called Browser Link. This is where Visual Studio opens a socket connection directly to your browsers (yes, plural) via SignalR that allows your IDE to send commands directly to the browser itself. The most basic use of this a simple refresh button that allows you to refresh all your browser windows on command.

The potential of this feature is fun to think about! Right now the Visual Studio team is intentionally keeping their default feature set for Browser link very simple, but also open source; as they want to see what us developers come up with. Remember that this is a two way channel of communication between the browser and the IDE, so sending error messages back to Visual Studio is just the first thing that comes to my mind.

A cool demo that they showed us at Build was keeping multiple browser windows in sync, this included form elements and page navigation. The cool part was that these browsers included Chrome, Firefox, and IE running on a virtualized windows phone. It was a very compelling demo!

Browser Link feature in Visual Studio Preview 2013

Web API 2.0

Web API was a great addition to Microsoft's web development library, and 2.0 looks like a great incrimental update to that framework. Forgive me if it seems that I do not have much to say about Web API 2, it just seems like a very simple but very welcome update to the framework; but don't let that fool you, I am stoked!

  • Attribute based routing.
  • Integrated OAuth 2 authentication.
  • OWIN Web hosting (run your APIs outside of IIS)
  • Cross-Origin Resource Sharing


TypeScript 0.9

I am SO excited about TypeScript!

TypeScript is a development language that is a super set of JavaScript. It adds type checking, interfaces, and inheritance to JavaScript. The idea is that you develop in TypeScript and then compile that language down to JavaScript for deployment on the web. The key here is that TypeScript is a super set of JavaScript, so all JavaScript code is already valid TypeScript, making it very easy for you to start your migration from language to the other.

There are essentially two ways that you could choose to use TypeScript:

  1. Use TypeScript for simple type checking and enhanced refactoring.

This is probably the more ideal use of TypeScript, or at least the simplest. The idea being that you can constrain your function parameters by type and interface, and make use of TypeScripts more strick declarations for easier refactoring. You would also get significantly improved intellisense both for your code and other frameworks, as a very active open source community has been creating interface wrappers for everything from JQuery to Knockout.

  1. Go full monty, and make your JavaScript completely Object Oriented.

Using TypeScript would allow you to define and extend both classes and interfaces, just as you would a language like C#. This opens the possibility for polymorphism, dependency injection, mocking, testing, the whole object oriented play book. While this does go against many principals of a very functional programming language like JavaScript, it also enables a lot of best practices that help simplify large scale application development. far you want to go using TypeScript is up to you, but regardless of which side of the fence you are on, I definitely feel that TypeScript is worth looking into!

Shout it

The future looks bright,

Real Time Web Analytics