Created
March 30, 2012 08:27
-
-
Save valentinzberea/2249611 to your computer and use it in GitHub Desktop.
Using FactoryGirl.Net with MSTest http://codebetter.com/jameskovacs/2012/03/20/building-factorygirl-net/
This file contains hidden or 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
[TestClass] | |
public static class Initializer | |
{ | |
[AssemblyInitialize] | |
public static void InitFactories(TestContext context) | |
{ | |
var factoryTypes = Assembly.GetExecutingAssembly() | |
.GetTypes().Where(x => x.Name.EndsWith("Factory")) | |
.ToList(); | |
FactoryGirl.ClearFactoryDefinitions(); | |
foreach (var factoryType in factoryTypes) | |
{ | |
factoryType.GetMethod("Init").Invoke(null, new object[]{}); | |
} | |
} | |
} | |
public static class UserFactory | |
{ | |
public static void Init() | |
{ | |
FactoryGirl.Define(() => | |
new User | |
{ | |
Id = Guid.NewGuid(), | |
FirstName = "Test", | |
LastName = "User", | |
Email = "[email protected]", | |
Password = MongoMembershipProvider.GetMD5Hash("p@ssw0rd") | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment