Skip to content

Commit

Permalink
Merge pull request #2 from felixwa/add-more-apis-2
Browse files Browse the repository at this point in the history
Add more API kinds/skus and model them as string instead of enum
  • Loading branch information
felixwa authored Dec 19, 2016
2 parents c575ec3 + b8aceb3 commit fd8060c
Show file tree
Hide file tree
Showing 9 changed files with 1,688 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ public static class CognitiveServicesManagementTestUtilities

// These are used to create default accounts
public static string DefaultLocation = IsTestTenant ? null : "westus";
public static SkuName DefaultSkuName = SkuName.S1;
public static Kind DefaultKind = Kind.TextAnalytics;
public const string DefaultSkuName = SkuName.S1;
public const string DefaultKind = Kind.TextAnalytics;
public static Dictionary<string, string> DefaultTags = new Dictionary<string, string>
{
{"key1","value1"},
Expand Down Expand Up @@ -133,36 +133,34 @@ public static string CreateResourceGroup(ResourceManagementClient resourcesClien
return rgname;
}

public static string CreateCognitiveServicesAccount(CognitiveServicesManagementClient cognitiveServicesMgmtClient, string rgname, Kind? kind = null)
public static string CreateCognitiveServicesAccount(CognitiveServicesManagementClient cognitiveServicesMgmtClient, string rgname, string kind = null)
{
string accountName = TestUtilities.GenerateName("csa");
CognitiveServicesAccountCreateParameters parameters = GetDefaultCognitiveServicesAccountParameters();
if (kind.HasValue) parameters.Kind = kind.Value;
if (!string.IsNullOrEmpty(kind)) parameters.Kind = kind;
var createRequest2 = cognitiveServicesMgmtClient.CognitiveServicesAccounts.Create(rgname, accountName, parameters);

return accountName;
}

public static CognitiveServicesAccount CreateAndValidateAccountWithOnlyRequiredParameters(CognitiveServicesManagementClient cognitiveServicesMgmtClient, string rgName, SkuName skuName, Kind accountType = Kind.Recommendations)
public static CognitiveServicesAccount CreateAndValidateAccountWithOnlyRequiredParameters(CognitiveServicesManagementClient cognitiveServicesMgmtClient, string rgName, string skuName, string accountType = Kind.Recommendations, string location = null)
{
// Create account with only required params
var accountName = TestUtilities.GenerateName("csa");
var parameters = new CognitiveServicesAccountCreateParameters
{
Sku = new Sku { Name = skuName },
Kind = accountType,
Location = CognitiveServicesManagementTestUtilities.DefaultLocation,
Location = location ?? DefaultLocation,
Properties = new object(),
};
var account = cognitiveServicesMgmtClient.CognitiveServicesAccounts.Create(rgName, accountName, parameters);
CognitiveServicesManagementTestUtilities.VerifyAccountProperties(account, false);
Assert.Equal(skuName, account.Sku.Name);
Assert.Equal(accountType.ToString(), account.Kind);
VerifyAccountProperties(account, false, accountType, skuName, location ?? DefaultLocation);

return account;
}

public static void VerifyAccountProperties(CognitiveServicesAccount account, bool useDefaults)
public static void VerifyAccountProperties(CognitiveServicesAccount account, bool useDefaults, string kind = DefaultKind, string skuName = DefaultSkuName, string location = "westus")
{
Assert.NotNull(account); // verifies that the account is actually created
Assert.NotNull(account.Id);
Expand All @@ -188,6 +186,12 @@ public static void VerifyAccountProperties(CognitiveServicesAccount account, boo
Assert.Equal(account.Tags["key1"], "value1");
Assert.Equal(account.Tags["key2"], "value2");
}
else
{
Assert.Equal(skuName, account.Sku.Name);
Assert.Equal(kind, account.Kind);
Assert.Equal(location, account.Location);
}
}

public static void ValidateExpectedException(Action action, string expectedErrorCode)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/f9b96b36-1f5e-4021-8959-51527e26e6d3/resourcegroups/res3070?api-version=2015-11-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZjliOTZiMzYtMWY1ZS00MDIxLTg5NTktNTE1MjdlMjZlNmQzL3Jlc291cmNlZ3JvdXBzL3JlczMwNzA/YXBpLXZlcnNpb249MjAxNS0xMS0wMQ==",
"RequestMethod": "PUT",
"RequestBody": "{\r\n \"location\": \"westus\"\r\n}",
"RequestHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"28"
],
"x-ms-client-request-id": [
"124717e4-3aba-4073-8825-63440f891055"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.24410.01",
"Microsoft.Azure.Management.Resources.ResourceManagementClient/1.0.0-preview"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/f9b96b36-1f5e-4021-8959-51527e26e6d3/resourceGroups/res3070\",\r\n \"name\": \"res3070\",\r\n \"location\": \"westus\",\r\n \"properties\": {\r\n \"provisioningState\": \"Succeeded\"\r\n }\r\n}",
"ResponseHeaders": {
"Content-Length": [
"167"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Fri, 16 Dec 2016 10:15:07 GMT"
],
"Pragma": [
"no-cache"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1198"
],
"x-ms-request-id": [
"7781665e-7709-481f-b1ec-ef18b7cea0c3"
],
"x-ms-correlation-request-id": [
"7781665e-7709-481f-b1ec-ef18b7cea0c3"
],
"x-ms-routing-request-id": [
"JAPANEAST:20161216T101508Z:7781665e-7709-481f-b1ec-ef18b7cea0c3"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
]
},
"StatusCode": 201
},
{
"RequestUri": "/subscriptions/f9b96b36-1f5e-4021-8959-51527e26e6d3/resourceGroups/res3070/providers/Microsoft.CognitiveServices/accounts/csa4421?api-version=2016-02-01-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZjliOTZiMzYtMWY1ZS00MDIxLTg5NTktNTE1MjdlMjZlNmQzL3Jlc291cmNlR3JvdXBzL3JlczMwNzAvcHJvdmlkZXJzL01pY3Jvc29mdC5Db2duaXRpdmVTZXJ2aWNlcy9hY2NvdW50cy9jc2E0NDIxP2FwaS12ZXJzaW9uPTIwMTYtMDItMDEtcHJldmlldw==",
"RequestMethod": "PUT",
"RequestBody": "{\r\n \"sku\": {\r\n \"name\": \"F0\"\r\n },\r\n \"kind\": \"NonExistAPI\",\r\n \"location\": \"westus\",\r\n \"properties\": {}\r\n}",
"RequestHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"111"
],
"x-ms-client-request-id": [
"a74e2344-0895-450a-8815-28292c138ded"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.24410.01",
"Microsoft.Azure.Management.CognitiveServices.CognitiveServicesManagementClient/0.1.3-preview"
]
},
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidApiSetId\",\r\n \"message\": \"The API set 'NonExistAPI' is invalid.\"\r\n }\r\n}",
"ResponseHeaders": {
"Content-Length": [
"86"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Fri, 16 Dec 2016 10:15:18 GMT"
],
"Pragma": [
"no-cache"
],
"Server": [
"Microsoft-IIS/8.5"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Powered-By": [
"ASP.NET"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1197"
],
"x-ms-request-id": [
"e370d9e1-2b14-4815-944c-4dc1b927249a"
],
"x-ms-correlation-request-id": [
"e370d9e1-2b14-4815-944c-4dc1b927249a"
],
"x-ms-routing-request-id": [
"JAPANEAST:20161216T101518Z:e370d9e1-2b14-4815-944c-4dc1b927249a"
]
},
"StatusCode": 400
},
{
"RequestUri": "/subscriptions/f9b96b36-1f5e-4021-8959-51527e26e6d3/resourceGroups/res3070/providers/Microsoft.CognitiveServices/accounts/csa4421?api-version=2016-02-01-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvZjliOTZiMzYtMWY1ZS00MDIxLTg5NTktNTE1MjdlMjZlNmQzL3Jlc291cmNlR3JvdXBzL3JlczMwNzAvcHJvdmlkZXJzL01pY3Jvc29mdC5Db2duaXRpdmVTZXJ2aWNlcy9hY2NvdW50cy9jc2E0NDIxP2FwaS12ZXJzaW9uPTIwMTYtMDItMDEtcHJldmlldw==",
"RequestMethod": "PUT",
"RequestBody": "{\r\n \"sku\": {\r\n \"name\": \"N0\"\r\n },\r\n \"kind\": \"Academic\",\r\n \"location\": \"westus\",\r\n \"properties\": {}\r\n}",
"RequestHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
],
"Content-Length": [
"108"
],
"x-ms-client-request-id": [
"b5df1fe8-a73d-4b80-8ef2-549665f1feaf"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.24410.01",
"Microsoft.Azure.Management.CognitiveServices.CognitiveServicesManagementClient/0.1.3-preview"
]
},
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"InvalidSkuId\",\r\n \"message\": \"The SKU name 'N0' in API set 'Academic' is invalid.\"\r\n }\r\n}",
"ResponseHeaders": {
"Content-Length": [
"97"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Fri, 16 Dec 2016 10:15:22 GMT"
],
"Pragma": [
"no-cache"
],
"Server": [
"Microsoft-IIS/8.5"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"X-AspNet-Version": [
"4.0.30319"
],
"X-Powered-By": [
"ASP.NET"
],
"x-ms-ratelimit-remaining-subscription-writes": [
"1196"
],
"x-ms-request-id": [
"e5fb9183-6a03-4149-b41d-4c9d08efd024"
],
"x-ms-correlation-request-id": [
"e5fb9183-6a03-4149-b41d-4c9d08efd024"
],
"x-ms-routing-request-id": [
"JAPANEAST:20161216T101523Z:e5fb9183-6a03-4149-b41d-4c9d08efd024"
]
},
"StatusCode": 400
}
],
"Names": {
"CreateResourceGroup": [
"res3070"
],
"CognitiveServicesCreateAccountErrorTest2": [
"csa4421"
]
},
"Variables": {
"SubscriptionId": "f9b96b36-1f5e-4021-8959-51527e26e6d3"
}
}
Loading

0 comments on commit fd8060c

Please sign in to comment.