Spark in the field - Rich Pictures

, , , , 1 Comment »

Dave the Ninja recently announced the launch of Rich Pictures.

DaveTheNinja: @haacked @loudej - just launched www.richpictures.co.uk (mvc.net, mvc-contrib, castle, nhibernate, spark)

It’s a very beautiful site. That’s a nice stack of technologies to build on top of too. I use a similar combination myself.

I just have to say it has been an amazing past few years. The toolset that’s available to .net based web developers has leapt forward an order of magnitude in quality, power, and simplicity.

Using Xpark.exe to transform Xml

, , , , 2 Comments »

A little while ago James Gregory introduced Docu - a simple doc gen for .Net.

From the Docu project site:

What’s so special about docu?
* One command to build your entire documentation
* Static html, nothing fancy, no dependencies
* Templates built using the Spark view engine
* No GAC, no hard-coded paths; completely redistributable

I thought the use of Spark in a command line utility was remarkably clever. I was inspired into adding a utility to the Spark project, Xpark.exe, for transforming any xml using spark templates.
Read the rest of this entry »

Where’s Spark

, , 2 Comments »

There has been a significant shuffle in the location and hosting of some parts of the Spark view engine. I’m quite happy with the results. They’re hopefully a net improvement.

Short list in advance:

Read the rest of this entry »

Remarkably smooth migration from .aspx to .spark

, , , 1 Comment »

One of the things I did looking at the MVC RC2 was see what’s involved in converting the “New Project” template from .aspx to .spark - it’s an exceptionally smooth migration.

For starters all of the the view files are standalone files with no code behind, which let’s you change the extension as a starting point.

The biggest difference is Shared/Site.Master was renamed and moved to Layouts/Application.spark… It could have stayed in Shared, but it seems a bit more specific to me. You’d also probably throw an underscore onto the file that’s used as a partial.

Because <% stmt %> and <%= expr %> are supported, if you’re using the Html helpers number of things you need to change in a view is remarkably small. Getting rid of the page declaration, and altering the named content parts, more or less covers it.

Before:

After:

The layout itself can be changed nearly as easily.

Before:

After:

Well, you get the idea. You’ll also need to add the namespace System.Web.Mvc.Html using a shared/_global.spark file, or the section in web.config, or by adding it to the template files.

Eventually you would also want to switch from a aspx-centric file appearance to a spark-centric one, but from the standpoint of migrating an existing app it probably gets you off the ground pretty quickly.

In the interest of completeness here’s the LogOnUserControl partial.

Before:

After:

Spark in the field - ALT.NET Seattle

, , No Comments »

Aaron Jenson recently gave an overview of the Spark View Engine during the ALT.NET Seattle conference. I learned about it from this post in the discussion group.

I had no idea if anyone was even using the client-side rendering, so it was nice to see what he was doing with that. The use as a code generator is also very cool - Spark generates source code for class which is then compiled and used to generate source code for class which is then compiled. :) Near the end some great Q/A points also come up.


AltNetSeattle: Spark View Engine (Part 1 of 2) - Aaron Jensen from Weston M. Binford III on Vimeo.


AltNetSeattle Spark View Engine (Part 2 of 2) - Aaron Jensen from Weston M. Binford III on Vimeo.

Special thanks to the Ben Scheirman who recorded it live, Chris Missal who provided a heads-up in the discussion group, and Weston M. Binford III who posted this higher quality recording.

Testing with the Castle IoC and Rhino

, , , , , 3 Comments »

To keep the dust off the blog I thought I would throw a quick post out about something that’s been working pretty well for tdd controllers.

This project is using ASP.NET MVC with some components from Castle Project. It’s using nunit and Rhino mocks.

The controllers are created from the Castle IoC container, so their constructors take service by interface. This can cause a certain churn in the unit testing so we use an instance of DefaultKernel to handle the details of correct ctor parameters and order and whatnot.

The especially nice thing is you can put mock interfaces in the microkernel as well, and they are used to satisfy all dependencies. There’s a simple extension method to make that easier.

public static class MockExtensions
{
    public static T Mock<T>(this IKernel kernel) where T : class
    {
        if (!kernel.HasComponent(typeof(T)))
            kernel.AddComponentInstance<T>(MockRepository.GenerateMock<T>());
        return kernel.Resolve<T>();
    }
}

And you can throw everything you’re testing and all of the mocks into a kernel on test setup.

[TestFixture]
public class AuthorizationControllerTests
{
    private DefaultKernel _kernel;

    [SetUp]
    public void Init()
    {
        _kernel = new DefaultKernel();
        _kernel.Mock<IRepository<UserRecord>>();
        _kernel.Mock<IAuthorizationService>();
        _kernel.AddComponent<AuthorizationController>();
    }
}

Because the kernel will return the same instance of the mocked interface each time it’s needed, the tests themselves can get them from the kernel to set expectations and verify results.

[Test]
public void Model_from_users_action_should_list_user_records()
{
    var users = new[]
                {
                    new UserRecord {Name = "foo"},
                    new UserRecord {Name = "bar"},
                };

    _kernel.Mock<IRepository<UserRecord>>()
        .Expect(x => x.FindAll())
        .Return(users);

    var controller = _kernel.Resolve<AuthorizationController>();
    var result = controller.Users();

    Assert.That(result, Is.InstanceOfType(typeof (ViewResult)));

    var model = ((ViewResult) result).ViewData.Model;
    Assert.That(model, Is.InstanceOfType(typeof(IEnumerable<UserRecord>)));

    _kernel.Mock<IRepository<UserRecord>>()
        .VerifyAllExpectations();
}

Nice and tidy.

Design by j david macor.com.Original WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in