AutoMocking in xUnit.BDDExtensions
Automocking in xUnit.BDDExtensions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class when_an_automatically_resolved_instance_with_a_single_dependency_is_used_in_a_fixture : InstanceContextSpecification<AutomaticallyCreatedInstance>
{
  private object actualResult;
  private IDependency dependency;
  private object expectedResult;
  
  protected override void EstablishContext()
  {
      expectedResult = new object();
      dependency = AutoDependency<IDependency>();
      dependency.WhenToldTo(x => x.Invoke()).Return(expectedResult);
  }
  
  protected override void Because()
  {
      actualResult = Sut.Invoke();
  }
 
 [Observation]
  public void should_be_able_to_verify_calls_made_to_the_dependency()
  {
      dependency.WasToldTo(x => x.Invoke());
  }
 
 [Observation]
  public void should_execute_the_configured_behavior_on_the_dependency()
  {
      actualResult.ShouldBeEqualTo(expectedResult);
  }
}

This little feature was added to the trunk today. Yes, no CreateSut() call. You can omit it for most of the simple scenarios. You can still override it, if you need/have to. It uses the AutoMocking capabilities of StructureMap internally.

I’m going to merge the different involved assemblies to a single assembly soon in order to make deployment a bit easier …

Comments