main
1using System;
2using System.Collections.Generic;
3
4namespace Spec.Dox.Domain
5{
6 public interface ITestContext
7 {
8 string Name { get; }
9 IEnumerable<ITestSpecification> AllSpecifications();
10 }
11
12 public class TestContext : ITestContext
13 {
14 readonly Type type;
15 IMethodIsDecoratedBySpecificationAttribute methodCriteria;
16
17 public TestContext(Type type) : this(type, new MethodIsDecoratedBySpecificationAttribute()) {}
18
19 public TestContext(Type type, IMethodIsDecoratedBySpecificationAttribute methodCriteria)
20 {
21 this.type = type;
22 this.methodCriteria = methodCriteria;
23 Name = type.Name;
24 }
25
26 public string Name { get; private set; }
27
28 public IEnumerable<ITestSpecification> AllSpecifications()
29 {
30 foreach (var method in type.GetMethods())
31 {
32 if (methodCriteria.IsSatisfiedBy(method))
33 yield return new TestSpecification(method);
34 }
35 }
36 }
37}