Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I just allow my tests to have a dependency on Autofac, although I encapsulate it. All of my TestFixtures inherit from Fixture, which is defined as such:</p> <pre><code>public class Fixture { private static readonly IContainer MainContainer = Ioc.Build(); private readonly TestLifetime _testLifetime = new TestLifetime(MainContainer); [SetUp] public void SetUp() { _testLifetime.SetUp(); } [TearDown] public void TearDown() { _testLifetime.TearDown(); } protected TService Resolve&lt;TService&gt;() { return _testLifetime.Resolve&lt;TService&gt;(); } protected void Override(Action&lt;ContainerBuilder&gt; configurationAction) { _testLifetime.Override(configurationAction); } } public class TestLifetime { private readonly IContainer _mainContainer; private bool _canOverride; private ILifetimeScope _testScope; public TestLifetime(IContainer mainContainer) { _mainContainer = mainContainer; } public void SetUp() { _testScope = _mainContainer.BeginLifetimeScope(); _canOverride = true; } public void TearDown() { _testScope.Dispose(); _testScope = null; } public TService Resolve&lt;TService&gt;() { _canOverride = false; return _testScope.Resolve&lt;TService&gt;(); } public void Override(Action&lt;ContainerBuilder&gt; configurationAction) { _testScope.Dispose(); if (!_canOverride) throw new InvalidOperationException("Override can only be called once per test and must be before any calls to Resolve."); _canOverride = false; _testScope = _mainContainer.BeginLifetimeScope(configurationAction); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload