Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Alternative test base class created for really async specs (like xUnit async specs) #50

Closed
wants to merge 1 commit into from

Conversation

IharBury
Copy link
Contributor

The existing Chill specs allow specifying async givens and whens but run them synchronously via blocking waits. However some test frameworks (for example, xUnit) do support really async specs without any blocking. This PR adds an experimental base class for such specs. That should avoid problems mentioned in #48.

Also only one base class is used for all the scenarios (with and without subject, with and without result). That solves #44.

@Erwinvandervalk, @dennisdoomen, what do you think?

@IharBury
Copy link
Contributor Author

IharBury commented Nov 22, 2016

See https://github.com/Erwinvandervalk/Chill/pull/50/files#diff-65ca5fe8309f5fa6dcf408c7e554e566 for the resulting syntax.

In short, with subject and result:

public void Test : AsyncTest<IGiven<Subject>, IWhen<Result>>
{
  public Test()
  {
    this.Given(async () =>
    {
      var subject = new Subject();
      await subject.PrepareAsync();
      return subject;
    });

    this.When(async subject =>
    {
      return await subject.DoIt();
    });
  }

  [Fact]
  public async void Then_it_rules()
  {
    Subject subject = await ExecuteGiven;
    Result result = await ExecuteWhen;
    result.Should().BeGreat();
  }
}

@IharBury IharBury force-pushed the XUnitAsync branch 2 times, most recently from 179faaf to 767ec76 Compare November 29, 2016 11:40
@IharBury
Copy link
Contributor Author

IharBury commented Nov 29, 2016

I've modified the proposed architecture further to allow the subjects and the results to be not publicly visible (#49). See https://github.com/Erwinvandervalk/Chill/pull/50/files#diff-65ca5fe8309f5fa6dcf408c7e554e566 for the resulting syntax.

In short, with subject and result:

public void Test : TestBase
{
  private readonly AsyncTestContext<Subject, Result> test;

  public Test()
  {
    test = new AsyncTestContext<Subject, Result>(this);

    test.Given(async () =>
    {
      var subject = new Subject();
      await subject.PrepareAsync();
      return subject;
    });

    test.When(async subject =>
    {
      return await subject.DoIt();
    });
  }

  [Fact]
  public async Task Then_it_rules()
  {
    Subject subject = await test.ExecuteGiven();
    Result result = await test.ExecuteWhen();
    result.Should().BeGreat();
  }
}

@IharBury IharBury closed this May 2, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant