LazyStack

Create a .NET Console App

In this step we will create a simple PetStoreConsoleApp. This console app will support all the features of AuthProcess running against AWS Cognito, initialize the PetStore library and make a simple call against the stack.

7.1 Create PetStoreConsoleApp Project

  1. Right Click on "Solution PetStoreMac" in the Solution Explorer. The context menu appears.
  2. Select "Add → New Project" from the context menu. The "Choose a template for your new project" dialog appears.
  3. Select "Web and Console → App → Console Application" in the search field.
  4. Click on the Next button. The "Configure your new Console Application" dialog appears.
  5. Select ".NET 5.0" as the Target Framework and click the Next button. The next "Configure your new Console Application" dialog page appears.
  6. Edit the project name to read "PetStoreConsoleApp" and click the Create button. The project is added to the solution.

7.2 Configure PetStoreConsoleApp Project

  1. Add the following project References:
    • PetStoreMacClientSDK
  2. Add the following package reference:
    • Microsoft.Extensions.Configuration.Json
  3. Add embedded AwsSettings.json resource.
    1. Double Click on the PetStoreConsoleApp project in the Solution Explorer. The csproj file opens in an editor tab.
    2. Insert the following Item Group into the csproj file.
      
        <ItemGroup>
          <EmbeddedResource Include="..\Stacks\Dev\AwsSettings.json" />
          <EmbeddedResource Include="..\LocalApis.json" />
        </ItemGroup>                        
                          
    3. Save the file.

7.3 Implement Program

  1. Download Program.cs and move it into your project, replacing the existing Program.cs.
  2. Build project.

Run Project

7.4 Run Against Stack
  1. Right Click "PetStoreConsoleApp" project in solution explorer. The context menu appears.
  2. Select Set as Startup Project.
  3. Debug program. A command window opens.

    Here is a sample command window session:

    You can use any login, password and email you want in this tutorial step. The email must be valid so you can receive the authentication code sent to that email in the sign up step. You can sign up only once with the same email address.

    Welcome to the PetStoreConsoleApp program
    Use LocalApi? y/n:n
    1. Sign Up
    2. Sign In
    3. Reset Password
    4. Quit
    >1
    Enter your Login: MyLoginName
    Enter your Password: MyPassword!
    Enter your Email address: myemail@gmail.com
    Enter authentication code: 984185
    You are Signed Up! You can now SignIn.
    1. Sign Up
    2. Sign In
    3. Reset Password
    4. Quit
    >2
    Enter your Login: MyLoginName
    Enter your current Password: MyPassword!
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    6. Get Pet 1
    7. Quit
    >5
    Pets added to database
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    6. Get Pet 1
    7. Quit
    >6
    pet: 1 Alf Available
    1. Sign Out
    2. Update Password
    3. Update Phone
    4. Update Login
    5. Seed Pets data
    6. Get Pet 1
    7. Quit
    >7
7.5 Run Against Local WebApi

In this step we launch a second instance of Visual Studio for Mac and open the

  1. This assumes you have an instance of Visual Studio for Mac open on the PetStoreMac solution.
  2. Right click on the Visual Studio icon in the MacOS dockbar. The context menu appears.
  3. Select "New Instance". The Visual Studio launch dialog appears.
  4. Open the PetStoreMac solution. You now have two instances of Visual Studio for Mac opened on the PetStoreMac solution.
  5. In the new instance, right click on the (WebApi) PetStoreMac project. The context menu appears.
  6. Select "Start Debugging Project". The PetStoreMac project launches. This is your local WebApi.
  7. In the other instance, start debugging the PetStoreConsoleApp.
  8. In the PetStoreConsoleApp command window. Answer 'y' to the "Use LocalApi?" prompt.

    Your authentication process still runs against the AWS stack but your calls to the PetStore library will call the Local WebApi (PetStoreMac) project. You can set debug breakpoints in both the PetStoreConsoleApp and PetStoreMac projects!

  9. Stop debugging in both Visual Studio instances. Close the second instance you used to run the PetStoreMac project.

Step Summary

In this step we created a Console App project and used it to run against both the AWS Application Stack and the local WebApi (PetStoreMac) project. When running locally, we can simultaneously debug the client and WebApi projects.