Sorting By Attribute Doesn't Seem to be Working

I believe I've followed the patterns already in the "File Layout" to attempt to order my methods based on their attribute.  The goal is to order by a "Given" attribute, then by a "When" attribute and then by a "Then" attribute just to keep my SpecFlow Step Definitions in order.  Here's what I have so far:



Static Fields and Constants is a copy from the Default Layout

"When" and "Then" follow the same pattern as above and "All Other Members" is the same as in the "Default Layout"

If it makes it easier the XAML section looks like this:

 

  <TypePattern DisplayName="SpecFlow Classes" RemoveRegions="All">
    <TypePattern.Match>
      <And>
        <Kind Is="Class" />
        <HasAttribute Name="TechTalk.SpecFlow.Binding" />
      </And>
    </TypePattern.Match>
    <Entry DisplayName="Static Fields and Constants">
      <Entry.Match>
        <Or>
          <Kind Is="Constant" />
          <And>
            <Kind Is="Field" />
            <Static />
          </And>
        </Or>
      </Entry.Match>
      <Entry.SortBy>
        <Kind Is="Member" />
      </Entry.SortBy>
    </Entry>
    <Entry DisplayName="Given">
      <Entry.Match>
        <And>
          <Kind Is="Method" />
          <HasAttribute Name="TechTalk.SpecFlow.GivenAttribute" />
        </And>
      </Entry.Match>
      <Entry.SortBy>
        <Name />
      </Entry.SortBy>
    </Entry>
    <Entry DisplayName="When">
      <Entry.Match>
        <And>
          <Kind Is="Method" />
          <HasAttribute Name="TechTalk.SpecFlow.WhenAttribute" />
        </And>
      </Entry.Match>
      <Entry.SortBy>
        <Name />
      </Entry.SortBy>
    </Entry>
    <Entry DisplayName="Then">
      <Entry.Match>
        <And>
          <Kind Is="Method" />
          <HasAttribute Name="TechTalk.SpecFlow.ThenAttribute" />
        </And>
      </Entry.Match>
      <Entry.SortBy>
        <Name />
      </Entry.SortBy>
    </Entry>
    <Entry DisplayName="All Other Members" />
  </TypePattern>

 

The issue is that the "When" methods never sort before the "Then" methods.  Am I missing something or is this a bug?

In case you need to see some example code this is a simple case pretty much direct from the default code in SpecFlow.  I just cleaned it up a little:

 

namespace MySpecFlow.StepDefinitions
{
  using TechTalk.SpecFlow;

  [Binding]
  public class SpecFlowFeatureSteps
  {
    [Given(@"I have entered (.*) into the calculator")]
    public void GivenIHaveEnteredIntoTheCalculator(int p0) => ScenarioContext.Current.Pending();

    [Then(@"the result should be (.*) on the screen")]
    public void ThenTheResultShouldBeOnTheScreen(int p0) => ScenarioContext.Current.Pending();

    [When(@"I press add")]
    public void WhenIPressAdd() { ScenarioContext.Current.Pending(); }
  }
}

 

1 comment

What ReSharper version do you use? I've tried applying your File Layout using ReSharper 2018.3.3, and it reordered methods in the way provided in the "SpecFlow Classes" pattern.

0

Please sign in to leave a comment.