How do I configure the auto mocker?
See original GitHub issueI was previously using SpecsFor 5.0.1, in which I could do this:
public interface IBar : ISpecs
{
IBaz Baz { get; set; }
}
public class Foo : Behavior<IBar>
{
public override void SpecInit(IBar instance)
{
instance.MockContainer.Configure(cfg => cfg.For<IBaz>().Use(instance.Baz));
}
}
After updating to SpecsFor 7.0.0, this is no longer available, and there is no documentation or summary of changes to consult regarding these breaking changes.
Where would I find the facility to configure the automocker’s behaviour?
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Improving Unit Tests With AutoMocker
When AutoMocker creates the ViewModel it will use the specified dependencies and create loose mocks for all other dependencies. In this manner, you...
Read more >moq/Moq.AutoMocker: An auto-mocking IoC container for ...
Simplest usage is to build an instance that you can unit test. var mocker = new AutoMocker(); var car = mocker. CreateInstance<Car>(); car....
Read more >Auto mocking Explained
The automocker will keep track of all the mocks it creates, and allows you to retrieve them if you need to stub a...
Read more >Sparky's Tool Tips: Moq.AutoMock
Verify mock behavior, you can get the auto-generated mock via AutoMocker's "GetMock<TMock>" method: autoMocker.GetMock<IFormatter>.Setup( ...
Read more >Moq — Autofac 7.0.0 documentation
You can configure the automatic mocks and/or assert calls on them as you would normally with Moq. [Test] public void Test() { using...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Ugh, I’ve really dropped the ball on supporting SpecsFor lately. If anyone still cares, here’s the approach I’m considering for resolving this issue.
I’m planning to add a new extension method,
GetMockContainer(), to each implementation of SpecsFor (StructureMap and Autofac for now). Calling this on an ISpecs instance will return the underlying automocking container for the library you’re using.Here’s an implementation of the extension method for StructureMap:
@bandoyer, if you’re still interested, you should be able to drop this in to your project, then update your spec like this:
Let me know if that approach works for your use case and makes sense. If so, I’ll get it added to the package.
Hi @psyren89! I apologize for not having the docs updated yet.
In SpecsFor 7, you can do the following:
I’m going to leave this issue open to remind me that we need to add an easier way of getting to this functionality.