Skip to content

Instantly share code, notes, and snippets.

public class Task<T>
{
readonly T something;
public Task(T something)
{
this.something = something;
}
}
var result = Controller.Create(...);
result.ShouldBeRedirectTo("Customers", "Index");
// instead of:
var result = Controller.Create(...);
var redirectResult = result as RedirectResult;
@jagregory
jagregory / ArrayModelBinder.cs
Created January 4, 2011 13:29
Custom MVC1 model binder that handles array properties
public class ArrayModelBinder : IFilteredPropertyBinder
{
private static readonly Regex IdRegex = new Regex("(?<=_)[0-9]+(?=_)");
public bool IsMatch(Type modelType)
{
return modelType.IsArray;
}
public void BindProperty(IModelBinder binder, ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)
@jagregory
jagregory / validate.js
Created December 7, 2010 17:04
Custom ajax "unique" validator with reason in response
var validator = $('form').validate({
rules: {
number: {
remote: {
url: 'UniqueNumber',
dataType: 'json',
success: function(data) {
if (data.unique == true) {
return;
}
public class SomeService
{
public string GetValues()
{
return "huzzah";
}
}
public class Person
{
Fluently.Configure()
.Mappings(...)
.Database(...)
.Diagnostics(dia =>
{
dia.Enable();
dia.OutputToConsole();
})
.BuildSessionFactory();
Fluent Mappings
---------------
Sources scanned:
Examples.FirstProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Mappings discovered:
EmployeeMap | Examples.FirstProject.Mappings.EmployeeMap, Examples.FirstProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
public static class RhinoMocksExtensions
{
public static IMethodOptions<IEnumerable<T>> ReturnEmptySet<T>(this IMethodOptions<IEnumerable<T>> options)
{
return options.Return(new T[0]);
}
}
public class MyAutomappingConfiguration : DefaultAutomappingConfiguration
{
public override bool ShouldMap(Member member)
{
return base.ShouldMap(member) && member.CanWrite;
}
}
// boom
public class Ex
{
public static readonly Ex Foo = Parse('f');
public static readonly Ex Bar = Parse('b');
Dictionary<char, string> validValues = new Dictionary<char, string>
{
{ 'f', "Foo" },
{ 'b', "Bar" },