Skip to content

Instantly share code, notes, and snippets.

View MattHoneycutt's full-sized avatar

Matt Honeycutt MattHoneycutt

View GitHub Profile
@MattHoneycutt
MattHoneycutt / DecorateThis.cs
Created September 9, 2012 21:12
StructureMap Decorator
public static class StructureMapDecoratorHelperExtension
{
public static DecoratorHelper<TTarget> Decorate<TTarget>(this SmartInstance<TTarget> instance)
{
return new DecoratorHelper<TTarget>(instance);
}
}
public class DecoratorHelper<TTarget>
@MattHoneycutt
MattHoneycutt / ModularConventionViewEngine.cs
Created May 2, 2013 02:09
A Razor view engine that supports several methods of organizing views and controllers within the same folder.
public class ModularConventionViewEngine : RazorViewEngine
{
//This needs to be initialized to the root namespace of your MVC project.
//Usually, the namespace of your Global.asax's codebehind will do the trick.
private static readonly string RootNamespace = typeof(MvcApplication).Namespace;
private static IEnumerable<string> GetPath(ControllerContext controllerContext, string viewName)
{
var paths = new List<string>();
@MattHoneycutt
MattHoneycutt / GridTag.cs
Created November 14, 2015 02:59
Updated MvcGridDirective and GridTag that allows for cell templates.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.UI;
using HeroicCRM.Web.Utilities;
using HtmlTags;
namespace HeroicCRM.Web.Helpers
{
@MattHoneycutt
MattHoneycutt / UserRegistrationSpecs.cs
Created March 18, 2012 05:02
SpecsFor.Mvc Examples
public class UserRegistrationSpecs
{
public class when_a_new_user_registers : SpecsFor<MvcWebApp>
{
protected override void Given()
{
SUT.NavigateTo<AccountController>(c => c.Register());
}
protected override void When()
@MattHoneycutt
MattHoneycutt / gist:1529690
Created December 28, 2011 20:54 — forked from jalchr/gist:1528815
SpecFor Sample
[Given(typeof(the_entity_is_available))]
public class When_entity_is_on_hold : SpecsFor<Entity>
{
public When_entity_is_on_hold(Type[] contexts) : base(contexts) { }
protected override void InitializeClassUnderTest()
{
SUT = new Entity("test");
}
public class when_creating_the_SUT_manually : SpecsFor<ReallyComplexAndHardToCreateType>
{
protected override void InitializeClassUnderTest()
{
SUT = ReallyComplexAndHardToCreateType.CreateMyType("some", "params", 536);
}
...
}
protected override void Given()
{
//Access Moq objects easily
GetMockFor<IInventory>()
.Setup(i => i.IsQuantityAvailable("TestPart", 10))
.Returns(true)
.Verifiable();
}
protected override void When()
@MattHoneycutt
MattHoneycutt / DemoWebAppConfig.cs
Created November 27, 2011 18:43
SpecsFor.Mvc examples
[SetUpFixture]
public class DemoWebAppConfig : SpecsForMvcConfig
{
public DemoWebAppConfig()
{
UseIISExpressWith(Project("SpecsFor.Mvc.Demo"));
BuildRoutesUsing(r => MvcApplication.RegisterRoutes(r));
UseBrowser(BrowserDriver.InternetExplorer);
//TODO: Open questions to be answered:
public class InvoiceProcessorSpecs
{
public class when_processing_an_invoice_with_helpers : SpecsFor<InvoiceProcessor>
{
...
[Test]
public void then_it_publishes_an_event()
{
GetMockFor<IPublisher>()
public static class given
{
public abstract class the_default_state : SpecsForWithData<AddIssueController>
{
}
}