Created
August 13, 2010 14:54
-
-
Save ignu/523003 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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