Created
December 12, 2011 02:57
-
-
Save MattHoneycutt/1464500 to your computer and use it in GitHub Desktop.
SpecsFor.FAQ
This file contains hidden or 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 when_creating_the_SUT_manually : SpecsFor<ReallyComplexAndHardToCreateType> | |
{ | |
protected override void InitializeClassUnderTest() | |
{ | |
SUT = ReallyComplexAndHardToCreateType.CreateMyType("some", "params", 536); | |
} | |
... | |
} |
This file contains hidden or 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 when_injecting_into_a_service_that_depends_on_IEnumerable : SpecsFor<ConsumeEnumerableService> | |
{ | |
private IEnumerable<IWidget> _testWidgets; | |
protected override void ConfigureContainer(StructureMap.IContainer container) | |
{ | |
base.ConfigureContainer(container); | |
container.Inject(typeof (string), "blah"); | |
var mocks = GetMockForEnumerableOf<IWidget>(10); | |
var widgets = new IWidget[10]; | |
for (var i = 0; i < mocks.Length; i++) | |
{ | |
var widget = mocks[i]; | |
widget.Setup(w => w.Name).Returns("Widget " + i); | |
widgets[i] = widget.Object; | |
} | |
_testWidgets = widgets; | |
} | |
[Test] | |
public void then_it_provides_the_enumerable() | |
{ | |
SUT.Widgets.Count().ShouldEqual(_testWidgets.Count()); | |
} | |
[Test] | |
public void then_expectations_set_up_on_the_mocks_are_preserved() | |
{ | |
SUT.Widgets.All(w => w.Name.StartsWith("Widget ")).ShouldBeTrue(); | |
} | |
[Test] | |
public void then_I_can_retrieve_the_equivalent_mock_enumerable() | |
{ | |
var mocks = GetMockForEnumerableOf<IWidget>(10); | |
var injectedNames = SUT.Widgets.Select(w => w.Name); | |
var mockNames = mocks.Select(m => m.Object.Name); | |
mockNames.ShouldEqual(injectedNames); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment