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 a Gmail account. AWS Cognito will email authorization codes to that Gmail 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 Gmail 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, Gmail has a nifty feature that allows you to use an 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.
Warning: Google really doesn't like your account to allow "less secure app access". They will regularly reset this setting to "on" without your permission, without warning, and without notification. Before running this test suite in the future, you must check your Google account settings to make sure this setting is off.
dotnet new mstest -o PetStoreTests
dotnet sln add PetStoreTests\PetStoreTests.csproj
The new PetStoreTests project is added to your solution.
dotnet sln add PetStoreTests/PetStoreTests.csproj
dotnet tool install -g dotnet-guid
A guid is printed to the console. Make a note of this GUID as you will need it in the next step.
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <IsPackable>false</IsPackable> <UserSecretsId>66025cbf-84df-4bb8-b739-175a8d130e36</UserSecretsId> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" /> <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" /> <PackageReference Include="MSTest.TestFramework" Version="2.1.1" /> <PackageReference Include="coverlet.collector" Version="1.3.0" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.1" /> <ProjectReference Include="..\PetStoreClientSDK\PetStoreClientSDK.csproj" /> <EmbeddedResource Include="..\Stacks\Dev\AwsSettings.json" /> </ItemGroup> </Project>
dotnet user-secrets -p PetStoreTests set "Gmail:Email" "myemail@Gmail.com"
dotnet user-secrets -p PetStoreTests set "Gmail:Password" "maypassword"
dotnet test PetStoreTests
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: