Search code examples
c#unit-testingbddstoryq

StoryQ When() calling task C#


I want to convert this unit test into BDD using storyQ working unit test

       [Test]
        public async void CreateNewProjectAndDatabase()
        {
            StartParametersAndAteEngineDlls();
            await TheNewDatabaseAndProjectIsCreated();
            TheDataBaseViewModelIsCreated();
            TheMainViewModelIsCreated();
        }




 private async Task TheNewDatabaseAndProjectIsCreated()
{
....
}

converted to BDD

   [Test]
    public async Task CreateNewProjectAndDatabase()
    {
        _story.WithScenario("Create a new bla bla")
            .Given(StartParametersAndAteEngineDlls)
            .When(async ()=> await TheNewDatabaseAndProjectIsCreated())
            .Then(TheDataBaseViewModelIsCreated)
            .And(TheMainViewModelIsCreated)
            .Execute();
    }

the code is code is compiling however I get an ArgumentException If you use 2 underscores in your method name, make sure there's 2 arguments (found 0)


Solution

  • I know I'm a bit late. I had the same problem I fixed it changing the way I execute the When method. Instead of using await and having a Task I used the oldSchool function "Wait" inside the When method. In that way we can have a private void function that StoryQ understand.

    Something like this.

    private void MyWhenMethod()
    {
        _sut.AsyncMethodRun().Wait()
    }