diff --git a/Source/Machine.Specifications.Specs/Factories/ContextFactorySpecs.cs b/Source/Machine.Specifications.Specs/Factories/ContextFactorySpecs.cs index 04967f9f4..3087bd0d0 100644 --- a/Source/Machine.Specifications.Specs/Factories/ContextFactorySpecs.cs +++ b/Source/Machine.Specifications.Specs/Factories/ContextFactorySpecs.cs @@ -236,4 +236,23 @@ public class and_the_nested_context_is_generic } } } + + [Subject(typeof(ContextFactory))] + public class when_creating_behavior_specifications_and_tracking_original_behavior_field + { + static Context newContext; + + Establish context = () => + { + var factory = new ContextFactory(); + newContext = factory.CreateContextFrom(new context_with_behaviors()); + }; + + It should_create_behavior_specs_with_original_behavior_field = + () => newContext.Specifications + .OfType() + .First() + .BehaviorFieldInfo.Name.Should().BeEquivalentTo("behavior"); + + } } diff --git a/Source/Machine.Specifications/Factories/BehaviorFactory.cs b/Source/Machine.Specifications/Factories/BehaviorFactory.cs index ebba31672..548884cb6 100644 --- a/Source/Machine.Specifications/Factories/BehaviorFactory.cs +++ b/Source/Machine.Specifications/Factories/BehaviorFactory.cs @@ -34,7 +34,7 @@ public Behavior CreateBehaviorFrom(FieldInfo behaviorField, Context context) var behavior = new Behavior(behaviorField.FieldType, behaviorInstance, context, isIgnored); var itFieldInfos = behaviorType.GetInstanceFieldsOfUsage(new AssertDelegateAttributeFullName()); - CreateBehaviorSpecifications(itFieldInfos, behavior); + CreateBehaviorSpecifications(itFieldInfos, behaviorField, behavior); return behavior; } @@ -126,11 +126,13 @@ static void EnsureContextFieldIsCompatibleType(Context context, FieldInfo contex } void CreateBehaviorSpecifications(IEnumerable itFieldInfos, + FieldInfo behaviorField, Behavior behavior) { foreach (var itFieldInfo in itFieldInfos) { var specification = _specificationFactory.CreateSpecificationFromBehavior(behavior, + behaviorField, itFieldInfo); behavior.AddSpecification(specification); } diff --git a/Source/Machine.Specifications/Factories/SpecificationFactory.cs b/Source/Machine.Specifications/Factories/SpecificationFactory.cs index 9dca2a577..8046d0fd3 100644 --- a/Source/Machine.Specifications/Factories/SpecificationFactory.cs +++ b/Source/Machine.Specifications/Factories/SpecificationFactory.cs @@ -19,13 +19,13 @@ public Specification CreateSpecification(Context context, FieldInfo specificatio return new Specification(name, specificationField.FieldType, it, isIgnored, specificationField); } - public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo specificationField) + public Specification CreateSpecificationFromBehavior(Behavior behavior, FieldInfo behaviorField, FieldInfo specificationField) { bool isIgnored = behavior.IsIgnored || specificationField.HasAttribute(new IgnoreAttributeFullName()); var it = (Delegate)specificationField.GetValue(behavior.Instance); string name = specificationField.Name.ToFormat(); - return new BehaviorSpecification(name, specificationField.FieldType, it, isIgnored, specificationField, behavior.Context, behavior); + return new BehaviorSpecification(name, specificationField.FieldType, behaviorField, it, isIgnored, specificationField, behavior.Context, behavior); } } } diff --git a/Source/Machine.Specifications/Model/BehaviorSpecification.cs b/Source/Machine.Specifications/Model/BehaviorSpecification.cs index 098cfb98e..40f99cc79 100644 --- a/Source/Machine.Specifications/Model/BehaviorSpecification.cs +++ b/Source/Machine.Specifications/Model/BehaviorSpecification.cs @@ -8,12 +8,14 @@ namespace Machine.Specifications.Model { public class BehaviorSpecification : Specification { + readonly FieldInfo _behaviorfield; readonly object _behaviorInstance; readonly object _contextInstance; readonly ConventionMapper _mapper; public BehaviorSpecification(string name, Type fieldType, + FieldInfo behaviorfield, Delegate it, bool isIgnored, FieldInfo fieldInfo, @@ -21,12 +23,18 @@ public BehaviorSpecification(string name, Behavior behavior) : base(name, fieldType, it, isIgnored, fieldInfo) { + _behaviorfield = behaviorfield; _contextInstance = context.Instance; _behaviorInstance = behavior.Instance; _mapper = new ConventionMapper(); } + public FieldInfo BehaviorFieldInfo + { + get { return _behaviorfield; } + } + protected override void InvokeSpecificationField() { _mapper.MapPropertiesOf(_contextInstance).To(_behaviorInstance); diff --git a/appveyor.yml b/appveyor.yml index 6c784c24e..b5425909e 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,14 +1,14 @@ environment: - nuget_version: '0.11.1' + nuget_version: '0.12.0' nuget_prerelease: false - assembly_version: '0.11.0.0' + assembly_version: '0.12.0.0' image: Visual Studio 2017 deploy: - provider: GitHub description: | - * Fix ArgumentOutOfRangeException thrown when tests are concurrently writing diagnostic output. (#224 - thanks to dannyvincent) + * Track behavior field from context in behavior specification on: appveyor_repo_tag: true