Skip to content

Instantly share code, notes, and snippets.

View rally25rs's full-sized avatar

Jeff Valore rally25rs

View GitHub Profile
@rally25rs
rally25rs / AssertMvc.cs
Created January 8, 2012 15:16
MSTest Assert Utility for MVC3 Controller Unit Testing
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
/// <summary>
/// MSTest Asserts for unit testing MVC3 Controllers.
/// </summary>
public static class AssertMvc
{
public static T ResultIs<T>(object result)
where T : ActionResult
@rally25rs
rally25rs / FakeDbSet.cs
Created December 18, 2011 02:11
Fake implementation of Entity Framework IDbSet to use for unit testing.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
namespace Rally25rs.Gist.Data
{
@rally25rs
rally25rs / HtmlHelperDisplayNameExtensions.cs
Created November 20, 2011 03:29
Extension methods for ASP.NET MVC3 that provide helpers for getting display names from IEnumerable models.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Web.Mvc;
namespace Web.Extensions
{
public static class HtmlHelperDisplayNameExtensions
{
/// <summary>
@rally25rs
rally25rs / CodeSample2.cs
Created May 10, 2011 00:47
Code Sample 2 (factory pattern)
/* ***
* This sample is again from an ORM tool that I had been working on.
*
* This is simply an example of a "factory" pattern that I wrote a few years ago.
* This factory is designed to return the same IDataBinder instance when the same
* database connection string is passed in.
* *** */
@rally25rs
rally25rs / CodeSample1.cs
Created May 10, 2011 00:27
Code Sample 1 (DynamicMethods and ILEmit)
/* ***
* This is a method from an object-relation-mapping (ORM) tool that I had started to write.
* I eventually stopped working on it, ad instead contributed time to the open source
* SubSonic project instead.
*
* This method is an example of generating DynamicMethods to be used at runtime to check and
* set some properties any an arbitrary type. This was used over straight reflection every time
* because reflection can be fairly slow. The use of a DynamicMethod is much quicker.
* *** */