In this step we will create a PetStoreTest project to perform an integration test against the PetStoreDev stack. We will test:
The automated tests we will create in this step require an IMAP account with subaddressing capabilities. For example, Gmail, Outlook or AWS WorkMail will work just fine. AWS Cognito will email authorization codes to an email account during the tests. For instance, the sign-up process will email the new user a authorization code. Our sign-up process test must log into the user's email account, find the email containing the authorization code and then use that code to finalize the sign-up process.
AWS Cognito requires each user to have a unique email address. We don't want to create a new email address each time we run the tests and deleting users from the Cognito User Pool is not convenient or always what we what.
Lucky for us, email subaddressing is a nifty feature that allows you to use a dynamic email address alias. For example, if you email address is myemail@gmail.com, you can send email to that address with the alias myemail+01@gmail.com. As far as AWS Cognito is concerned, this alias is a unique email address. This means we can use a single Gmail account to create and test multiple AWS Cognito accounts where each of the AWS Cognito accounts is associated with a unique Gmail address alias.
For the purposes of this demo we will use the AWS WorkMail service. AWS WorkMail accounts currently cost $4/mo but you get a free 30 day trail. One nice feature of the AWS WorkMail service is that it offers a "free" subdomain so you don't have to configure any domains or spend a lot of time setting things up.
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<ProjectReference Include="..\PetStoreClientSDK\PetStoreClientSDK.csproj" />
<EmbeddedResource Include="..\Stacks\Dev\AwsSettings.json" />
</ItemGroup>
Note the inclusion of the "..\Stacks\Dev\AwsSettings.json" file as an embedded resource. This file contains the information necessary for a client app to connect to and use the AWS Stack. We generated this file earlier with using Tools → LazyStack - Generate Stacks\Dev\AwsSettings.json.
{
"EmailAccount": {
"Domain":"imap.mai.us-east-1.awsapps.com",
"Port":993,
"UseSSL": true,
"Email": "test@alias.awsapps.com",
"Password": "mypassword"
}
}
Note: For our testing process, we don't need to "send" email from this AWS WorkMail "test" account so we skip configuring an outgoing SMTP server for this AWS WorkMail service. If you are using WorkMail for more than this simple testing scenario, you should setup an outgoing SMTP server as well.
You can use any imap compatible mail service that supports subaddressing. I like using AWS WorkMail because it is simple to setup and inexpensive to use as a dedicated testing component.
In this step we created a Integration test project and ran our first tests against the published stack.
Reviewing the contents of the PetStoreIntegrationTest.cs class may yield valuable insights into how you should use the libraries in your client apps. Take note of the following implementation elements: