You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/Using-Azure-TestFramework.md
+76-63Lines changed: 76 additions & 63 deletions
Original file line number
Diff line number
Diff line change
@@ -4,14 +4,13 @@
4
4
2. Accquring TestFramework
5
5
3. Setup prior to Record/Playback tests
6
6
1. Environment Variables
7
-
2. Connection string
8
-
3. Defaults
7
+
2. Playback Test
8
+
3. Record Test with Interactive login using OrgId
9
+
4. Record Test with ServicePrincipal
9
10
4. Record/Playback tests
10
-
1. Playback Tests
11
-
2. Record tests using interactive login (using orgId)
12
-
3. Record tests using Service Principal
13
11
5. Change Test Environment settings at run-time
14
-
12
+
6. Troubleshooting
13
+
7. Environment Variable Reference
15
14
16
15
## 1. Getting Started
17
16
1. Launch .\tools\PS-VSPrompt shortcut
@@ -28,6 +27,7 @@ TestFramework is available on NuGet at https://www.nuget.org/packages/Microsoft.
28
27
Instructions to manually download it are available on NuGet. However TestFramework will be downloaded automatically as part of the build process, so manually downloading it should generally be unnecessary.
29
28
30
29
## 3. Setup prior to Record/Playback of tests
30
+
31
31
In order to Record/Playback a test, you need to setup a connection string that consists various key/value pairs that provides information to the test environment.
32
32
33
33
#### 3.1 Environment Variables
@@ -40,7 +40,74 @@ This is the connection string that determined how to connect to Azure. This incl
40
40
41
41
This specifies whether test framework will `Record` test sessions or `Playback` previously recorded test sessions.
42
42
43
-
#### 3.2. Supported Keys in connection string
43
+
#### 3.2 Playback Test
44
+
45
+
The default mode is Playback mode, so no setting up of connection string is required. You can optionally set environment variables:
46
+
47
+
TEST_CSM_ORGID_AUTHENTICATION=
48
+
AZURE_TEST_MODE=Playback
49
+
50
+
#### 3.3 Record Test with Interactive login using OrgId
51
+
52
+
This is no longer the preferred option because it only works when running on .NET Framework. When running on .NET Core you may get an error like `Interactive Login is supported only in NET45 projects`.
53
+
54
+
To use this option, set the following environment variables before starting Visual Studio:
This is the preferred option for record because it works with both .NET Framework and .NET Core.
62
+
63
+
To create a service principal, follow the [Azure AD guide to create a Application Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#create-an-active-directory-application). The application type should be `Web app / API` and the sign-on URL value is irrelevant (you can set any value).
64
+
65
+
After the service principal is created, you will need to give it access to Azure resources. This can be done with the following PowerShell command, with the [Service Principal Application ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key) (this is a guid, not the display name of the service principal) substituted in for `{clientId}`.
To use this option, set the following environment variable before starting Visual Studio. The following values are substituted into the below connection string:
70
+
71
+
`clientId`: The [Service Principal Application ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key)
72
+
73
+
`clientSecret`: A [Service Principal Authentication Key](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key)
74
+
75
+
`tenantId`: The [AAD Tenant ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-tenant-id)
1. Run the test and make sure that you got a generated .json file that matches the test name in the bin folder under *SessionRecords folder
84
+
2. Copy SessionRecords folder inside the test project and add all *.json files in Visual Studio setting "Copy to Output Directory" property to "Copy if newer"
85
+
3. To assure that the records work fine, delete the connection string (default mode is Playback mode) OR change HttpRecorderMode within the connection string to "Playback"
86
+
87
+
## 5. Change Test Environment settings at run-time
88
+
#### 1. Once you set your connection string, you can add or update key/value settings
TestEnvironment.Endpoints.GraphUri = new Uri("https://newGraphUri.windows.net");
98
+
99
+
###Note:###
100
+
Changing the above properties at run-time has the potential to hard code few things in your tests. Best practice would be to use these properties to change values at run-time from immediate window at run-time and avoid hard-coding certain values.
101
+
102
+
## 6. Troubleshooting
103
+
104
+
#### Issue: exceptions in Microsoft.Azure.Test.HttpRecorder
105
+
106
+
Ensure that the `HttpRecorderMode` in the `TEST_CSM_ORGID_AUTHENTICATION` environment variable is consistent with the value in `AZURE_TEST_MODE` environment variable.
107
+
108
+
## 7. Environment Variable Reference
109
+
110
+
#### 7.1. Supported Keys in connection string
44
111
* ManagementCertificate
45
112
* SubscriptionId
46
113
* AADTenant
@@ -62,7 +129,8 @@ This specifies whether test framework will `Record` test sessions or `Playback`
62
129
* AADAuthEndpoint
63
130
* GraphTokenAudienceUri
64
131
65
-
#### 3.3. Environment Defaults
132
+
133
+
#### 7.2 Environment Defaults
66
134
67
135
Setting `Environment` in the connection string will result in the following default values:
68
136
@@ -121,58 +189,3 @@ Setting `Environment` in the connection string will result in the following defa
The default mode is Playback mode, so no setting up of connection string is required.
130
-
131
-
#### Record Test with Interactive login using OrgId
132
-
133
-
This is no longer the preferred option because it only works when running on .NET Framework. When running on .NET Core you may get an error like `Interactive Login is supported only in NET45 projects`.
134
-
135
-
To use this option, set the following environment variable before starting Visual Studio:
This is the preferred option because it works with both .NET Framework and .NET Core.
142
-
143
-
To create a service principal, follow the [Azure AD guide to create a Application Service Principal](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#create-an-active-directory-application). The application type should be `Web app / API` and the sign-on URL value is irrelevant (you can set any value).
144
-
145
-
After the service principal is created, you will need to give it access to Azure resources. This can be done with the following PowerShell command, with the [Service Principal Application ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key) (this is a guid, not the display name of the service principal) substituted in for `{clientId}`.
To use this option, set the following environment variable before starting Visual Studio. The following values are substituted into the below connection string:
150
-
151
-
`clientId`: The [Service Principal Application ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key)
152
-
153
-
`clientSecret`: A [Service Principal Authentication Key](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key)
154
-
155
-
`tenantId`: The [AAD Tenant ID](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-tenant-id)
2. Run the test and make sure that you got a generated .json file that matches the test name in the bin folder under *SessionRecords folder
162
-
3. Copy SessionRecords folder inside the test project and add all *.json files in Visual Studio setting "Copy to Output Directory" property to "Copy if newer"
163
-
4. To assure that the records work fine, delete the connection string (default mode is Playback mode) OR change HttpRecorderMode within the connection string to "Playback"
164
-
165
-
## 5. Change Test Environment settings at run-time
166
-
#### 1. Once you set your connection string, you can add or update key/value settings
TestEnvironment.Endpoints.GraphUri = new Uri("https://newGraphUri.windows.net");
176
-
177
-
###Note:###
178
-
Changing the above properties at run-time has the potential to hard code few things in your tests. Best practice would be to use these properties to change values at run-time from immediate window at run-time and avoid hard-coding certain values.
0 commit comments