Skip to content

Instantly share code, notes, and snippets.

@ignu
Created August 13, 2010 14:54
Show Gist options
  • Save ignu/523003 to your computer and use it in GitHub Desktop.
Save ignu/523003 to your computer and use it in GitHub Desktop.
namespace FakeIt.Specs
{
public class Customer
{
public string Name { get; set; }
}
[TestFixture]
public class BluePrintSpecs
{
[Test]
public void can_set_up_a_blueprint()
{
Factory.Strategy<Customer>(c => c.Name = "Len");
var customer = Factory.Create<Customer>();
Assert.AreEqual(customer.Name, "Len");
}
}
public class Factory
{
public static Dictionary<string, object> factories = new Dictionary<string, object>();
public static void Strategy<T>(Action<T> func)
{
factories[typeof (T).ToString()] = func;
}
public static T Create<T>() where T : new()
{
var rv = new T();
(factories[typeof (T).ToString()] as Action<T>)(rv);
return rv;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment