Created
June 26, 2015 09:29
-
-
Save westonal/8e30aad8b6e01edb98bb to your computer and use it in GitHub Desktop.
Specs from fields
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 readonly object Spec = "Public spec field" | |
.Assert(() => Assert.Pass("It works!")); | |
private object Spec2 = "Private spec field" | |
.Assert(() => Assert.Pass("It works!")); | |
private object Spec3 = new[] | |
{ | |
"Collection spec field" | |
.Assert(() => Assert.Pass("It works!")), | |
"Collection spec field" | |
.Assert(() => Assert.Pass("It works!")) | |
}; |
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 abstract class SpecificationFromFields : Specification | |
{ | |
protected override ISpecification[] TestCases() | |
{ | |
var values = GetType() | |
.GetFields(BindingFlags.NonPublic | | |
BindingFlags.Public | | |
BindingFlags.Instance) | |
.Select(f => f.GetValue(this)).ToList(); | |
var specs = values.OfType<ISpecification>(); | |
var enumSpecs = values.OfType<ICollection<ISpecification>>().SelectMany(e => e); | |
return specs.Concat(enumSpecs).ToArray(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment