In this step we will create a PetStoreTest project to perform an integration test against the
PetStoreDev stack. We will test:
- Application SignUp - using the LazyStackAuth library.
- Application SignIn - using the LazyStackAuth library.
- Calling the stack using the PetStore - defined in the PetStoreClientSDK library.
8.1 Configure a Gmail Account
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 a dynamic email address
alias. For example, if you email address is email@example.com, you can send email to that address with
the alias firstname.lastname@example.org. 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.
- Create a new Gmail account. We suggest you create a Gmail account just for this purpose and not use
any existing Gmail account.
- Open your Google Account Settings.
- Select Security from menu.
- Select "Less secure app access" and turn on access.
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.
8.2 Create PetStoreTests Project
- Right Click on "Solution PetStore" in the Solution Explorer pane. The Context Menu appears.
- Select "Add → New Project" from the context menu. The "Choose a template for your new
project" dialog appears.
- Select "Web and Console → Tests → MSTest Project".
- Click on the Next button. The "Configure your MSTest Project" dialog appears.
- Select ".NET6" for the Target Framework and press the Next button. The second "Configure your
MSTest Project" page appears.
- Edit project name to read "PetStoreTests".
- Click the Create button. The test project is added to your solution.
8.3 Add Project Dependencies
- Open the PetStoreTests.csproj file.
- Copy the following ItemGroup into the .csproj file.
<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" />
- Save the file.
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.
8.4 Configure Microsoft User Secrets
Visual Studio for Mac does not currently support editing User Secrets from the IDE.
Since we have the .NET CLI installed we can use that to set up our secrets.
- Generate User-Secrets GUID
- Open a Terminal.
- CD to the solution folder (LazyStackTutorial\PetStore) and install the dotnet
GUID tool if it is not already installed:
dotnet tool install -g dotnet-guid
- Use the guid tool to generate a new GUID:
A guid is printed to the console. Make a note of this GUID as you will need it in the next step.
- Replace the PropertyGroup with the following content in the PetStoreTests.csproj file,
then replace the UserSecretsId value
with the guid you generated in the previous step:
- Set User Secret Values
- Open a Terminal Window
- CD into the LazyStackTutorial/PetStore folder.
- Set Gmail:Email user secret value:
dotnet user-secrets -p PetStoreTests set "Gmail:Email" "email@example.com"
- Set Gmail:Password user secret value:
dotnet user-secrets -p PetStoreTests set "Gmail:Password" "maypassword"
8.5 Implement Tests
- Delete the PetStoreTests UnitTest1.cs file.
- Download PetStoreIntegrationTest.cs and
then move it into the PetStoreTests project.
8.6 Run Tests
- Select View → Tests. The Test Explorer panel appears.
- Run Tests. The integration test completes successfully.
8.7 Step Summary
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:
- AwsSettings.json is an embedded resource that is loaded by
ConfigurationBuilder. This embedded resource
references \Stacks\Dev\AwsSettings.json. In a client app, you would introduce condition logic in the
csproj file to use \Stacks\Prod\AwsSettings.json for release builds or just distribute the AwsSettings.json
file separately to developers using the PetStoreentSDK.
- AuthMessages.json is a embedded resource that
is loaded by ConfigurationBuilder. Extend
this file with new message sets by language to localize the messages emitted by the AuthProcess class.
This test does not demonstrate the use of AuthProcess messages but later Tutorial steps will.
- Dependency injection is used in this test to demonstrate the service registration of
IAuthProcess and IAuthProvider.
- This test only exercises the simple Happy Path SignUp and SignIn process. If you want
to see much more extensive integration tests for AuthProcess, view the LazyStack solution
on GitHub. Also read the LazyStackAuth documentation for
- The LzHttpClient class implements the logic necessary for
your client to make secure calls to the AWS Stack ApiGateways. The LzHttpClient class uses the Aws, LoadApis and
MethodMap sections in the appConfig.