Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class GivenThereArePurchaseOrdersForTheProduct
{
[Fact]
public async Task ShouldCreateValidSuggestion()
{
var productId = {use a dummy id};
// set up the stub to already have a purchase order stored
var poStore = new PurchaseOrderStoreStub()
.WithPurchaseOrder(...);
var productStore = new ProductStoreStub();
var suggestionStore = new SuggestionStoreStub();
// initialise the System Under Test passing in all the stubbed dependencies
var handler = new ProductInformationHandler(
new ReviewUseCase(
suggestionStore,
productStore,
poStore),
poStore,
productStore
);
// invoke the handle method (It doesn't matter if its invoked
// via an event arriving in a queue or by a test suite like this one)
// create a test event with canned values
await handler.Handle(
CreateTestEvent(...));
// Time to assert on the output of handling the test event.
var savedProduct = await productStore.GetByProductId(productId);
var suggestionForProduct = await suggestionStore.GetFor(productId);
// Assert that incoming product was saved successfully
savedProduct.Should().NotBeNull();
// Assert that as a result of an appropriate event, the suggestion was also created
// and stored in the "database"
suggestionForProduct.Should().NotBeNull();
// various other assertions on suggestion attributes.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.