Last active
January 31, 2018 10:17
-
-
Save abenedykt/12d409cf3001055c80d4 to your computer and use it in GitHub Desktop.
AutoNSubstitute Attrubite to create objects with nsubstitute and populate propperties
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
public class AutoNSubstituteAttribute : AutoDataAttribute | |
{ | |
public AutoNSubstituteAttribute() | |
: base(()=>new Fixture() | |
.Customize(new AutoPopulatedNSubstitutePropertiesCustomization()) | |
) | |
{ | |
} | |
} | |
internal class AutoPopulatedNSubstitutePropertiesCustomization | |
: ICustomization | |
{ | |
public void Customize(IFixture fixture) | |
{ | |
fixture.ResidueCollectors.Add( | |
new Postprocessor( | |
new NSubstituteBuilder( | |
new MethodInvoker( | |
new NSubstituteMethodQuery())), | |
new AutoPropertiesCommand( | |
new PropertiesOnlySpecification()))); | |
} | |
private class PropertiesOnlySpecification : IRequestSpecification | |
{ | |
public bool IsSatisfiedBy(object request) | |
{ | |
return request is PropertyInfo; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment