doc/dev/Using-Azure-TestFramework.md
TestFramework is available on NuGet at https://www.nuget.org/packages/Microsoft.Rest.ClientRuntime.Azure.TestFramework/ .
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.
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.
TEST_CSM_ORGID_AUTHENTICATION
Value of the env. variable is the connection string that determines how to connect to Azure. This includes authentication and the Azure environment to connect to.
AZURE_TEST_MODE
This specifies whether test framework will Record test sessions or Playback previously recorded test sessions.
The default mode is Playback mode, so no setting up of connection string is required.
This is no longer the preferred option because it only works when running on .NET Framework (Full Desktop version of .NET - 4.5.1+) When running on .NET Core you may get an error like Interactive Login is supported only in NET45 projects.
To use interactive login, set the following environment variables before starting Visual Studio:
TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId={SubId};AADTenant={tenantId};Environment={env};HttpRecorderMode=Record;
AZURE_TEST_MODE=Record
This is the preferred option for record because it works with both .NET Framework and .NET Core.
To create a service principal, follow the Azure AD guide to create a Application Service Principal. The application type should be Web app / API and the sign-on URL value is irrelevant (you can set any value).
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 (this is a guid, not the display name of the service principal) substituted in for {clientId}.
New-AzureRmRoleAssignment -ServicePrincipalName {clientId} -RoleDefinitionName Contributor
To use this option, set the following environment variable before starting Visual Studio. The following values are substituted into the below connection string:
clientId: The Service Principal Application ID
clientSecret: A Service Principal Authentication Key
tenantId: The AAD Tenant ID
TEST_CSM_ORGID_AUTHENTICATION=SubscriptionId={SubId};ServicePrincipal={clientId};ServicePrincipalSecret={clientSecret};AADTenant={tenantId};Environment={env};HttpRecorderMode=Record;
AZURE_TEST_MODE=Record
Add new key/value pair
TestEnvironment.ConnectionString.KeyValuePairs.Add("Foo", "FooValue");
Update Existing key/value pair
TestEnvironment.ConnectionString.KeyValuePairs["keyName"]="new value"
Accessing/Updating TestEndpoints
TestEnvironment.Endpoints.GraphUri = new Uri("https://newGraphUri.windows.net");
###Note:### 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.
Ensure that the HttpRecorderMode in the TEST_CSM_ORGID_AUTHENTICATION environment variable is consistent with the value in AZURE_TEST_MODE environment variable.
* ManagementCertificate
* SubscriptionId
* AADTenant
* UserId
* Password
* ServicePrincipal
* ServicePrincipalSecret
* Environment={Prod | Dogfood | Next | Current | Custom}
* RawToken
* RawGraphToken
* HttpRecorderMode={Record | Playback}
* AADAuthEndpoint
* OptimizeRecordedFile={true | false:default}
true: will trim recorded files when long running operations are detected.
* GraphTokenAudienceUri
* BaseUri
* AADAuthUri
* GalleryUri
* GraphUri
* IbizaPortalUri
* RdfePortalUri
* ResourceManagementUri
* ServiceManagementUri
* AADTokenAudienceUri
* GraphTokenAudienceUri
* DataLakeStoreServiceUri
* DataLakeAnalyticsJobAndCatalogServiceUri
AADAuthUri = "https://login.microsoftonline.com"
GalleryUri = "https://gallery.azure.com/"
GraphUri = "https://graph.windows.net/"
IbizaPortalUri = "https://portal.azure.com/"
RdfePortalUri = "http://go.microsoft.com/fwlink/?LinkId=254433"
ResourceManagementUri = "https://management.azure.com/"
ServiceManagementUri = "https://management.core.windows.net"
AADTokenAudienceUri = "https://management.core.windows.net"
GraphTokenAudienceUri = "https://graph.windows.net/"
DataLakeStoreServiceUri = "https://azuredatalakestore.net"
DataLakeAnalyticsJobAndCatalogServiceUri = "https://azuredatalakeanalytics.net"
AADAuthUri = "https://login.windows-ppe.net";
GalleryUri = "https://df.gallery.azure-test.net/";
GraphUri = "https://graph.ppe.windows.net/";
IbizaPortalUri = "http://df.onecloud.azure-test.net";
RdfePortalUri = "https://windows.azure-test.net";
ResourceManagementUri = "https://api-dogfood.resources.windows-int.net/";
ServiceManagementUri = "https://management-preview.core.windows-int.net";
AADTokenAudienceUri = "https://management.core.windows.net";
GraphTokenAudienceUri = "https://graph.ppe.windows.net/";
DataLakeStoreServiceUri = "https://caboaccountdogfood.net";
DataLakeAnalyticsJobAndCatalogServiceUri = "https://konaaccountdogfood.net";
AADAuthUri = "https://login.windows-ppe.net"
GalleryUri = "https://next.gallery.azure-test.net/"
GraphUri = "https://graph.ppe.windows.net/"
IbizaPortalUri = "http://next.onecloud.azure-test.net"
RdfePortalUri = "https://auxnext.windows.azure-test.net"
ResourceManagementUri = "https://api-next.resources.windows-int.net/"
ServiceManagementUri = "https://managementnext.rdfetest.dnsdemo4.com"
AADTokenAudienceUri = "https://management.core.windows.net"
GraphTokenAudienceUri = "https://graph.ppe.windows.net/"
DataLakeStoreServiceUri = "https://caboaccountdogfood.net"
DataLakeAnalyticsJobAndCatalogServiceUri = "https://konaaccountdogfood.net"
AADAuthUri = "https://login.windows-ppe.net"
GalleryUri = "https://df.gallery.azure-test.net/"
GraphUri = "https://graph.ppe.windows.net/"
IbizaPortalUri = "http://df.onecloud.azure-test.net"
RdfePortalUri = "https://windows.azure-test.net"
ResourceManagementUri = "https://api-dogfood.resources.windows-int.net/"
ServiceManagementUri = "https://management-preview.core.windows-int.net"
AADTokenAudienceUri = "https://management.core.windows.net"
GraphTokenAudienceUri = "https://graph.ppe.windows.net/"
DataLakeStoreServiceUri = "https://caboaccountdogfood.net"
DataLakeAnalyticsJoAbndCatalogServiceUri = "https://konaaccountdogfood.net"
When specified, test framework expect all Uri's to be provided by the user as part of the connection string.
What is also supported is as below (connections string example)
SubscriptionId=subId;Environment=Prod;AADAuthUri=customAuthUri;ResourceManagementUri=CustomResourceMgmtUri
Which translates to, all Uri from pre-defined Prod environment will be used, but AADAuthUri and ResourceManagementUri will be overridden by the one provided in the connection string