-
-
Save AlexZeitler/927605 to your computer and use it in GitHub Desktop.
| public class ListOfAValidAndAInvalidRequirement { | |
| OnEstablish context = | |
| fakeAccessor => | |
| { | |
| IRequirement validRequirement = fakeAccessor.An<IRequirement>(); | |
| validRequirement.WhenToldTo(r => r.Validate()).Return(true); // throws ex here | |
| IRequirement invalidRequirement = fakeAccessor.An<IRequirement>(); | |
| invalidRequirement.WhenToldTo(r=>r.Validate()).Return(false); | |
| IList<IRequirement> requirements = new List<IRequirement> | |
| { | |
| validRequirement, | |
| invalidRequirement | |
| }; | |
| fakeAccessor.Configure(config => config.For<IList<IRequirement>>().Use(()=>requirements)); | |
| }; | |
| } | |
| public interface IRequirement { | |
| bool Validate(); | |
| } | |
| throws "Can't create mocks of sealed classes" |
| the complete spec: | |
| public class When_validating_a_valid_requirement_and_a_invalid_requirement : WithSubject<RequirementsValidator> | |
| { | |
| static bool _isValid; | |
| Establish context = () => { With<ListOfAValidAndAInvalidRequirement>(); }; | |
| Because of = () => { _isValid = Subject.Validate(); }; | |
| It should_not_be_valid = () => { _isValid.ShouldBeFalse(); }; | |
| } | |
| public class ListOfAValidAndAInvalidRequirement { | |
| OnEstablish context = | |
| fakeAccessor => | |
| { | |
| IRequirement validRequirement = fakeAccessor.An<IRequirement>(); | |
| validRequirement.WhenToldTo(r => r.Validate()).Return(true); | |
| IRequirement invalidRequirement = fakeAccessor.An<IRequirement>(); | |
| invalidRequirement.WhenToldTo(r=>r.Validate()).Return(false); | |
| IList<IRequirement> requirements = new List<IRequirement> | |
| { | |
| validRequirement, | |
| invalidRequirement | |
| }; | |
| fakeAccessor.Configure(config => config.For<IList<IRequirement>>().Use(()=>requirements)); | |
| }; | |
| } | |
| public class RequirementsValidator { | |
| readonly IList<IRequirement> _requirements; | |
| public RequirementsValidator(IList<IRequirement> requirements) { | |
| _requirements = requirements; | |
| } | |
| public bool Validate() { | |
| return _requirements.Where(r => r.Validate()).Count() == _requirements.Count; | |
| } | |
| } | |
| public interface IRequirement { | |
| bool Validate(); | |
| } |
While not getting the exception - does the test turn red or green?
Thanks for investigation, though.
Will have to dig into a test I wrote yesterday against the latest code base where I also used Configure and IList in BehaviorConfigs - weird stuff ;-)
So in all cases I tried Moq/Rhino/FakeItEasy --> merged/unmerged I didn't run into the exception. The specification fails because IList<IRequirement> contains no elements (explanation above ;-().
Maybe you did enable "Just my Code" in Debugging options?
This was enabled, however disabling it didn't change the outcome
Ok, could isolate it a little bit more:
using:
Subject = new RequirementsValidator(The<IList<IRequirement>>());
everything works fine - including BCs and Configure from above code
When letting Machine.Fakes inject The<IList<IRequirement>>() the exception is thrown.
Ok, I'm going to try that with the merged mfakes assembly