Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrewjpoole/039ae07be0bc3534cda6383780d5a945 to your computer and use it in GitHub Desktop.
Save andrewjpoole/039ae07be0bc3534cda6383780d5a945 to your computer and use it in GitHub Desktop.
Empty Given, When and Then classes for component testing
public class Given
{
private readonly XyzApiWebApplicationFactory context; // replace this type with your specific WebApplicationFactory etc
public Given(XyzApiWebApplicationFactory context)
{
this.context = context;
}
public static Given UsingThe(XyzApiWebApplicationFactory context) => new(context);
public Given And => this;
public Given TheServerIsStarted()
{
apiWebApplicationFactory.Start();
return this;
}
}
public class When
{
private readonly XyzApiWebApplicationFactory context; // replace this type with your specific WebApplicationFactory etc
public When(XyzApiWebApplicationFactory context)
{
this.context = context;
}
public static When UsingThe(XyzApiWebApplicationFactory context) => new(context);
public When And => this;
}
public class Then
{
private readonly XyzApiWebApplicationFactory context; // replace this type with your specific WebApplicationFactory etc
public Then(XyzApiWebApplicationFactory context)
{
this.context = context;
}
public static Then UsingThe(XyzApiWebApplicationFactory context) => new(context);
public Then And => this;
public Then Assert(Action inlineAssertion)
{
inlineAssertion();
return this;
}
public Then And(Action inlineAssertion) => Assert(inlineAssertion);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment