That’s Why I Like Open Source . . .

Today I received a really nice feature for xUnit.BDDExtensions from a former colleague and friend of mine. It came to me completely with a spec demonstrating and documenting its usage. Completely awesome. I wish day to day software development would always be like that.

The feature deals with chained properties on interfaces. Consider the following example: A presenter working against a composed passive view.

A complex MVP view interface
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public interface IComplexView
{
  ISubView Header {get;set;}
}

public interface ISubView
{
  string Description {get;set;}
}
public class Presenter
{
  private IComplexView _view;
  
  public Presenter(IComplexView view)
  {
      _view = view;
  }
  
  public void Initialize()
  {
      _view.Header.Description = "Some caption . . ."
  }
}

A spec documenting the behavior of the presenter can now look like this if you’re using xUnit.BDDExtensions.

Using the HasProperties() extension method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[Concern(typeof(Presenter))]
public class When_the_presenter_is_initialized : InstanceContextSpecification<Presenter>
{
  protected override EstablishContext()
  {
      The<IComplexView>().HasProperties();
  }
  
  protected override void Because()
  {
      Sut.Initialize();
  }
 
 [Observation]
  public void It_should_set_the_headers_caption()
  {
      The<IComplexView>().Header.Description.ShouldBeEqualTo("Some caption ... ");
  }
}

A really large portion of the necessary glue code has been removed for that scenario. Only the HasProperties() extension method remains.

Great work, Sergey. I really like the implementation of that feature …

Comments