public void IfAnAccountIsCreatedWithAutoStorage_ThenTheAutoStorageAccountIdMustNotBeNull()
        {
            var handler = new RecordedDelegatingHandler();

            var client = BatchTestHelper.GetBatchManagementClient(handler);

            // If storageId is not set this will throw an ValidationException
            var ex = Assert.Throws <ValidationException>(() => client.BatchAccount.Create("resourceGroupName", "acctName", new BatchAccountCreateParameters
            {
                Location    = "South Central US",
                AutoStorage = new AutoStorageBaseProperties()
            }));

            Assert.Equal("StorageAccountId", ex.Target.ToString());
        }
示例#2
0
        public void GetApplicationPackageValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(@"{
                    'id': 'foo',
                    'storageUrl': '//storageUrl',
                    'state' : 'Pending',
                    'version' : 'beta',
                    'format':'zip',
                    'storageUrlExpiry':'" + utcNow.ToString("o") + @"',
                    'lastActivationTime':'" + utcNow.ToString("o") + @"',
                    }")
            };


            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = Task.Factory.StartNew(() =>
                                               client.Application.GetApplicationPackageWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName",
                                                   "id",
                                                   "VER")).Unwrap().GetAwaiter().GetResult();

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            //Validate result
            Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);

            Assert.Equal("foo", result.Body.Id);
            Assert.Equal("//storageUrl", result.Body.StorageUrl);
            Assert.Equal(PackageState.Pending, result.Body.State);
            Assert.Equal("beta", result.Body.Version);
            Assert.Equal("zip", result.Body.Format);
            Assert.Equal(utcNow, result.Body.LastActivationTime);
            Assert.Equal(utcNow, result.Body.StorageUrlExpiry);
        }
        public void ListDetectorsValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'value': [
                        {
                            'type': 'Microsoft.Batch/batchAccounts/detectors',
                            'id': '/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/detectors/poolsAndNodes',
                            'name': 'poolsAndNodes',
                            'properties': {
                                'value': 'ew0KICAibWV0YWRhdGEiOiB7DQogICAgImlkIjogInBvb2xzQW5kTm9kZXMiLA0KICAgICJuYW1lIjogIlBvb2xzIGFuZCBOb2RlcyIsDQogICAgImRlc2NyaXB0aW9uIjogbnVsbCwNCiAgICAiYXV0aG9yIjogIiIsDQogICAgImNhdGVnb3J5IjogbnVsbCwNCiAgICAic3VwcG9ydFRvcGljTGlzdCI6IFsNCiAgICAgIHsNCiAgICAgICAgImlkIjogIjMyNjM1MDc3IiwNCiAgICAgICAgInBlc0lkIjogIjE1NjE0IiwNCiAgICAgICAgInR5cGVJZCI6ICJEaWFnbm9zdGljcy5Nb2RlbHNBbmRVdGlscy5BdHRyaWJ1dGVzLlN1cHBvcnRUb3BpYywgRGlhZ25vc3RpY3MuTW9kZWxzQW5kVXRpbHMsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsIg0KICAgICAgfSwNCiAgICAgIHsNCiAgICAgICAgImlkIjogIjMyNjM1MDYxIiwNCiAgICAgICAgInBlc0lkIjogIjE1NjE0IiwNCiAgICAgICAgInR5cGVJZCI6ICJEaWFnbm9zdGljcy5Nb2RlbHNBbmRVdGlscy5BdHRyaWJ1dGVzLlN1cHBvcnRUb3BpYywgRGlhZ25vc3RpY3MuTW9kZWxzQW5kVXRpbHMsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsIg0KICAgICAgfSwNCiAgICAgIHsNCiAgICAg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0lkIjogIjE1NjE0IiwNCiAgICAgICAgInR5cGVJZCI6ICJEaWFnbm9zdGljcy5Nb2RlbHNBbmRVdGlscy5BdHRyaWJ1dGVzLlN1cHBvcnRUb3BpYywgRGlhZ25vc3RpY3MuTW9kZWxzQW5kVXRpbHMsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsIg0KICAgICAgfSwNCiAgICAgIHsNCiAgICAgICAgImlkIjogIjMyNjM1MDk0IiwNCiAgICAgICAgInBlc0lkIjogIjE1NjE0IiwNCiAgICAgICAgInR5cGVJZCI6ICJEaWFnbm9zdGljcy5Nb2RlbHNBbmRVdGlscy5BdHRyaWJ1dGVzLlN1cHBvcnRUb3BpYywgRGlhZ25vc3RpY3MuTW9kZWxzQW5kVXRpbHMsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsIg0KICAgICAgfQ0KICAgIF0sDQogICAgImFuYWx5c2lzVHlwZXMiOiBudWxsLA0KICAgICJ0eXBlIjogIkFuYWx5c2lzIiwNCiAgICAic2NvcmUiOiAwLjANCiAgfSwNCiAgImRhdGFzZXQiOiBbXSwNCiAgInN0YXR1cyI6IHsNCiAgICAibWVzc2FnZSI6IG51bGwsDQogICAgInN0YXR1c0lkIjogNA0KICB9LA0KICAiZGF0YVByb3ZpZGVyc01ldGFkYXRhIjogbnVsbCwNCiAgInN1Z2dlc3RlZFV0dGVyYW5jZXMiOiBudWxsDQp9'
                            }
                        },
                        {
                            'type': 'Microsoft.Batch/batchAccounts/detectors',
                            'id': '/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/detectors/anotherDetector',
                            'name': 'otherDetector',
                            'properties': {
                                'value': 'ew0KICAibWV0YWRhdGEiOiB7DQogICAgImlkIjogInBvb2xzQW5kTm9kZXMiLA0KICAgICJuYW1lIjogIlBvb2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E0IiwNCiAgICAgICAgInR5cGVJZCI6ICJEaWFnbm9zdGljcy5Nb2RlbHNBbmRVdGlscy5BdHRyaWJ1dGVzLlN1cHBvcnRUb3BpYywgRGlhZ25vc3RpY3MuTW9kZWxzQW5kVXRpbHMsIFZlcnNpb249MS4wLjAuMCwgQ3VsdHVyZT1uZXV0cmFsLCBQdWJsaWNLZXlUb2tlbj1udWxsIg0KICAgICAgfQ0KICAgIF0sDQogICAgImFuYWx5c2lzVHlwZXMiOiBudWxsLA0KICAgICJ0eXBlIjogIkFuYWx5c2lzIiwNCiAgICAic2NvcmUiOiAwLjANCiAgfSwNCiAgImRhdGFzZXQiOiBbXSwNCiAgInN0YXR1cyI6IHsNCiAgICAibWVzc2FnZSI6IG51bGwsDQogICAgInN0YXR1c0lkIjogNA0KICB9LA0KICAiZGF0YVByb3ZpZGVyc01ldGFkYXRhIjogbnVsbCwNCiAgInN1Z2dlc3RlZFV0dGVyYW5jZXMiOiBudWxsDQp9'
                            }
                        }
                    ]
                }"
                                            )
            };

            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            BatchManagementClient client = BatchTestHelper.GetBatchManagementClient(handler);

            IPage <DetectorResponse> result = client.BatchAccount.ListDetectors("default-azurebatch-japaneast", "sampleacct");

            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            Assert.Equal(2, result.Count());

            DetectorResponse response1 = result.ElementAt(0);

            Assert.Equal("poolsAndNodes", response1.Name);

            DetectorResponse response2 = result.ElementAt(1);

            Assert.Equal("otherDetector", response2.Name);
        }
示例#4
0
        public void AccountUpdateValidateMessage()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname',
                                'location': 'South Central US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            }")
            };

            var handler = new RecordedDelegatingHandler(response);

            var client = BatchTestHelper.GetBatchManagementClient(handler);
            var tags   = new Dictionary <string, string>();

            tags.Add("tag1", "value for tag1");
            tags.Add("tag2", "value for tag2");

            var result = client.BatchAccount.Update("foo", "acctname", new BatchAccountUpdateParameters
            {
                Tags        = tags,
                AutoStorage = new AutoStorageBaseProperties()
                {
                    StorageAccountId = "//StorageAccountId"
                }
            });

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal("South Central US", result.Location);
            Assert.NotEmpty(result.AccountEndpoint);
            Assert.Equal(ProvisioningState.Succeeded, result.ProvisioningState);

            Assert.Equal(2, result.Tags.Count);
        }
示例#5
0
        public void AccountGetValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctName',
                    'type' : 'Microsoft.Batch/batchAccounts',
                    'name': 'acctName',
                    'location': 'South Central US',
                    'properties': {
                        'accountEndpoint' : 'http://acctName.batch.core.windows.net/',
                        'provisioningState' : 'Succeeded',
                        'coreQuota' : '20',
                        'poolQuota' : '100',
                        'activeJobAndJobScheduleQuota' : '200'
                    },
                    'tags' : {
                        'tag1' : 'value for tag1',
                        'tag2' : 'value for tag2',
                    }
                }")
            };

            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = client.Account.Get("foo", "acctName");

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal("South Central US", result.Location);
            Assert.Equal("acctName", result.Name);
            Assert.Equal("/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctName", result.Id);
            Assert.NotEmpty(result.AccountEndpoint);
            Assert.Equal(20, result.CoreQuota);
            Assert.Equal(100, result.PoolQuota);
            Assert.Equal(200, result.ActiveJobAndJobScheduleQuota);

            Assert.True(result.Tags.ContainsKey("tag1"));
        }
示例#6
0
        public void CreateAccountWithAutoStorageAsyncValidateMessage()
        {
            var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content = new StringContent(@"")
            };

            acceptedResponse.Headers.Add("x-ms-request-id", "1");
            acceptedResponse.Headers.Add("Location", @"http://someLocationURL");
            var utcNow = DateTime.UtcNow;

            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                                'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'accountname',
                                'location': 'South Central US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded',
                                    'autoStorage' :{
                                        'storageAccountId' : '//storageAccount1',
                                        'lastKeySync': '" + utcNow.ToString("o") + @"',
                                    }
                                },
                            }")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { okResponse });

            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = client.BatchAccount.Create("resourceGroupName", "accountname", new BatchAccountCreateParameters
            {
                Location    = "South Central US",
                AutoStorage = new AutoStorageBaseProperties()
                {
                    StorageAccountId = "//storageAccount1"
                }
            });

            // Validate result
            Assert.Equal("//storageAccount1", result.AutoStorage.StorageAccountId);
            Assert.Equal(utcNow, result.AutoStorage.LastKeySync);
        }
示例#7
0
        public void AccountDeleteOkValidateMessage()
        {
            var noContentResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"")
            };

            noContentResponse.Headers.Add("x-ms-request-id", "1");

            var handler = new RecordedDelegatingHandler(noContentResponse);

            var client = BatchTestHelper.GetBatchManagementClient(handler);

            client.BatchAccount.Delete("resGroup", "acctname");

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
        }
示例#8
0
        public void AddApplicationValidateMessage()
        {
            var utcNow = DateTime.UtcNow;
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.Created,
                Content    = new StringContent(@"{
                    'id': 'foo',
                    'allowUpdates': 'true',
                    'displayName' : 'displayName',
                    'defaultVersion' : 'beta',
                    'packages':[
                        {'version':'fooVersion', 'state':'pending', 'format': 'betaFormat', 'lastActivationTime': '" + utcNow.ToString("o") + @"'}],

                    }")
            };

            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = Task.Factory.StartNew(() =>
                                               client.Application.AddApplicationWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName",
                                                   "appId",
                                                   new AddApplicationParameters
            {
                AllowUpdates = true,
                DisplayName  = "display-name"
            })).Unwrap().GetAwaiter().GetResult();


            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(HttpMethod.Put, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(HttpStatusCode.Created, result.Response.StatusCode);
        }
示例#9
0
        public void AddApplicationPackageValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.Created,
                Content    = new StringContent(@"{
                    'id': 'foo',
                    'storageUrl': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctName',
                    'version' : 'beta',
                    'storageUrlExpiry' : '" + utcNow.ToString("o") + @"',
                    }")
            };


            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = Task.Factory.StartNew(() =>
                                               client.Application.AddApplicationPackageWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName",
                                                   "appId",
                                                   "beta")).Unwrap().GetAwaiter().GetResult();

            // Validate headers - User-Agent for certs, Authorization for tokens
            Assert.Equal(HttpMethod.Put, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(utcNow, result.Body.StorageUrlExpiry);
            Assert.Equal("foo", result.Body.Id);
            Assert.Equal("beta", result.Body.Version);
            Assert.Equal("/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctName", result.Body.StorageUrl);
            Assert.Equal(HttpStatusCode.Created, result.Response.StatusCode);
        }
        public async Task PrivateEndpointConnectionUpdate()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'properties': {
                            'provisioningState': 'Succeeded',
                            'privateEndpoint': {
                                'id': '/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Network/privateEndpoints/privateEndpointName'
                            },
                            'privateLinkServiceConnectionState': {
                                'status': 'Pending',
                                'description': 'Its pending'
                            }
                        }
                    }")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { okResponse });

            var client = BatchTestHelper.GetBatchManagementClient(handler);
            var result = await client.PrivateEndpointConnection.UpdateAsync(
                "rg",
                "myaccount",
                "privateEndpointName",
                new PrivateEndpointConnection(
                    privateLinkServiceConnectionState : new PrivateLinkServiceConnectionState(
                        status : PrivateLinkServiceConnectionStatus.Pending,
                        description : "It's pending")));

            // Validate result
            Assert.Equal(PrivateEndpointConnectionProvisioningState.Succeeded, result.ProvisioningState);
            Assert.Equal("/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Network/privateEndpoints/privateEndpointName", result.PrivateEndpoint.Id);
            Assert.Equal(PrivateLinkServiceConnectionStatus.Pending, result.PrivateLinkServiceConnectionState.Status);
            Assert.Equal("Its pending", result.PrivateLinkServiceConnectionState.Description);
            Assert.Null(result.PrivateLinkServiceConnectionState.ActionRequired);
        }
示例#11
0
        public void AccountDeleteValidateMessage()
        {
            var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content = new StringContent(@"")
            };

            acceptedResponse.Headers.Add("x-ms-request-id", "1");
            acceptedResponse.Headers.Add("Location", @"http://someLocationURL");

            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { acceptedResponse, okResponse, okResponse });

            var client = BatchTestHelper.GetBatchManagementClient(handler);

            client.BatchAccount.Delete("resGroup", "acctname");

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
        }
        public async Task PrivateLinkResourceGet()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'properties': {
                            'groupId': 'batchAccount',
                            'requiredMembers': [
                                'batchAccount'
                            ]
                        }
                    }")
            };

            var handler = new RecordedDelegatingHandler(new HttpResponseMessage[] { okResponse });

            var client = BatchTestHelper.GetBatchManagementClient(handler);
            var result = await client.PrivateLinkResource.GetAsync("rg", "myaccount", "privateLinkResource");

            // Validate result
            Assert.Equal("batchAccount", result.GroupId);
            Assert.Single(result.RequiredMembers, "batchAccount");
        }
示例#13
0
        public void AccountListByResourceGroupValidateMessage()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'value':
                        [
                            {
                                'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname',
                                'location': 'West US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded',
                                    'dedicatedCoreQuota' : '20',
                                    'lowPriorityCoreQuota' : '50',
                                    'poolQuota' : '100',
                                    'activeJobAndJobScheduleQuota' : '200'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            },
                            {
                                'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname1',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname1',
                                'location': 'South Central US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname1.batch.core.windows.net/',
                                    'provisioningState' : 'Failed',
                                    'dedicatedCoreQuota' : '10',
                                    'lowPriorityCoreQuota' : '50',
                                    'poolQuota' : '50',
                                    'activeJobAndJobScheduleQuota' : '100'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1'
                                }
                            }
                        ],
                        'nextLink' : 'originalRequestURl?$skipToken=opaqueStringThatYouShouldntCrack'
                    }")
            };

            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = client.BatchAccount.List();

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(2, result.Count());

            var account1 = result.ElementAt(0);
            var account2 = result.ElementAt(1);

            Assert.Equal("West US", account1.Location);
            Assert.Equal("acctname", account1.Name);
            Assert.Equal(@"/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname", account1.Id);
            Assert.Equal(@"http://acctname.batch.core.windows.net/", account1.AccountEndpoint);
            Assert.Equal(ProvisioningState.Succeeded, account1.ProvisioningState);
            Assert.Equal(20, account1.DedicatedCoreQuota);
            Assert.Equal(50, account1.LowPriorityCoreQuota);
            Assert.Equal(100, account1.PoolQuota);
            Assert.Equal(200, account1.ActiveJobAndJobScheduleQuota);

            Assert.Equal("South Central US", account2.Location);
            Assert.Equal("acctname1", account2.Name);
            Assert.Equal(@"/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname1", account2.Id);
            Assert.Equal(@"http://acctname1.batch.core.windows.net/", account2.AccountEndpoint);
            Assert.Equal(ProvisioningState.Failed, account2.ProvisioningState);
            Assert.Equal(10, account2.DedicatedCoreQuota);
            Assert.Equal(50, account2.LowPriorityCoreQuota);
            Assert.Equal(50, account2.PoolQuota);
            Assert.Equal(100, account2.ActiveJobAndJobScheduleQuota);

            Assert.Equal(2, account1.Tags.Count);
            Assert.True(account1.Tags.ContainsKey("tag2"));

            Assert.Equal(1, account2.Tags.Count);
            Assert.True(account2.Tags.ContainsKey("tag1"));

            Assert.Equal(@"originalRequestURl?$skipToken=opaqueStringThatYouShouldntCrack", result.NextPageLink);
        }
示例#14
0
        public void AccountListValidateMessage()
        {
            var allSubsResponseEmptyNextLink = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                            'value':
                            [
                                {
                                    'id': '/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname',
                                    'type' : 'Microsoft.Batch/batchAccounts',
                                    'name': 'acctname',
                                    'location': 'West US',
                                    'properties': {
                                        'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                        'provisioningState' : 'Succeeded',
                                        'dedicatedCoreQuota' : '20',
                                        'lowPriorityCoreQuota' : '50',
                                        'poolQuota' : '100',
                                        'activeJobAndJobScheduleQuota' : '200'
                                    },
                                    'tags' : {
                                        'tag1' : 'value for tag1',
                                        'tag2' : 'value for tag2',
                                    }
                                },
                                {
                                    'id': '/subscriptions/12345/resourceGroups/bar/providers/Microsoft.Batch/batchAccounts/acctname1',
                                    'type' : 'Microsoft.Batch/batchAccounts',
                                    'name': 'acctname1',
                                    'location': 'South Central US',
                                    'properties': {
                                        'accountEndpoint' : 'http://acctname1.batch.core.windows.net/',
                                        'provisioningState' : 'Succeeded',
                                        'dedicatedCoreQuota' : '20',
                                        'lowPriorityCoreQuota' : '50',
                                        'poolQuota' : '100',
                                        'activeJobAndJobScheduleQuota' : '200'
                                    },
                                    'tags' : {
                                        'tag1' : 'value for tag1',
                                        'tag2' : 'value for tag2',
                                    }
                                }
                            ],
                            'nextLink' : ''
                        }")
            };

            var allSubsResponseNonemptyNextLink = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'value':
                        [
                            {
                                'id': '/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname',
                                'location': 'West US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded',
                                    'dedicatedCoreQuota' : '20',
                                    'lowPriorityCoreQuota' : '50',
                                    'poolQuota' : '100',
                                    'activeJobAndJobScheduleQuota' : '200'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            },
                            {
                                'id': '/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname1',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname1',
                                'location': 'South Central US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname1.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            }
                        ],
                        'nextLink' : 'https://fake.net/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname?$skipToken=opaqueStringThatYouShouldntCrack'
                    }
                 ")
            };


            var allSubsResponseNonemptyNextLink1 = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'value':
                        [
                            {
                                'id': '/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname',
                                'location': 'West US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded',
                                    'dedicatedCoreQuota' : '20',
                                    'lowPriorityCoreQuota' : '50',
                                    'poolQuota' : '100',
                                    'activeJobAndJobScheduleQuota' : '200'

                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            },
                            {
                                'id': '/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname1',
                                'type' : 'Microsoft.Batch/batchAccounts',
                                'name': 'acctname1',
                                'location': 'South Central US',
                                'properties': {
                                    'accountEndpoint' : 'http://acctname1.batch.core.windows.net/',
                                    'provisioningState' : 'Succeeded',
                                    'dedicatedCoreQuota' : '20',
                                    'lowPriorityCoreQuota' : '50',
                                    'poolQuota' : '100',
                                    'activeJobAndJobScheduleQuota' : '200'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            }
                        ],
                        'nextLink' : 'https://fake.net/subscriptions/12345/resourceGroups/resGroup/providers/Microsoft.Batch/batchAccounts/acctname?$skipToken=opaqueStringThatYouShouldntCrack'
                    }
                 ")
            };

            allSubsResponseEmptyNextLink.Headers.Add("x-ms-request-id", "1");
            allSubsResponseNonemptyNextLink.Headers.Add("x-ms-request-id", "1");
            allSubsResponseNonemptyNextLink1.Headers.Add("x-ms-request-id", "1");

            // all accounts under sub and empty next link
            var handler = new RecordedDelegatingHandler(allSubsResponseEmptyNextLink)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = Task.Factory.StartNew(() => client.BatchAccount.ListWithHttpMessagesAsync())
                         .Unwrap()
                         .GetAwaiter()
                         .GetResult();

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // Validate result
            Assert.Equal(HttpStatusCode.OK, result.Response.StatusCode);

            // Validate result
            Assert.Equal(2, result.Body.Count());

            var account1 = result.Body.ElementAt(0);
            var account2 = result.Body.ElementAt(1);

            Assert.Equal("West US", account1.Location);
            Assert.Equal("acctname", account1.Name);
            Assert.Equal("/subscriptions/12345/resourceGroups/foo/providers/Microsoft.Batch/batchAccounts/acctname", account1.Id);
            Assert.Equal("/subscriptions/12345/resourceGroups/bar/providers/Microsoft.Batch/batchAccounts/acctname1", account2.Id);
            Assert.NotEmpty(account1.AccountEndpoint);
            Assert.Equal(20, account1.DedicatedCoreQuota);
            Assert.Equal(50, account1.LowPriorityCoreQuota);
            Assert.Equal(100, account1.PoolQuota);
            Assert.Equal(200, account2.ActiveJobAndJobScheduleQuota);

            Assert.True(account1.Tags.ContainsKey("tag1"));

            // all accounts under sub and a non-empty nextLink
            handler = new RecordedDelegatingHandler(allSubsResponseNonemptyNextLink)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            client = BatchTestHelper.GetBatchManagementClient(handler);

            var result1 = client.BatchAccount.List();

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));

            // all accounts under sub with a non-empty nextLink response
            handler = new RecordedDelegatingHandler(allSubsResponseNonemptyNextLink1)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            client = BatchTestHelper.GetBatchManagementClient(handler);

            result1 = client.BatchAccount.ListNext(result1.NextPageLink);

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.NotNull(handler.RequestHeaders.GetValues("User-Agent"));
        }
        public void ListOutboundNetworkDependenciesEndpointsValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'value': [
                    {
                      'category': 'Azure Batch',
                      'endpoints': [
                        {
                          'domainName': 'japaneast.batch.azure.com',
                          'description': 'Applicable to all Azure Batch pools.',
                          'endpointDetails': [
                            {
                              'port': 443
                            }
                          ]
                        }
                      ]
                    },
                    {
                      'category': 'Azure Storage',
                      'endpoints': [
                        {
                          'domainName': 'sampleautostorageaccountname.blob.core.windows.net',
                          'description': 'AutoStorage endpoint for this Batch account. Applicable to all Azure Batch pools under this account.',
                          'endpointDetails': [
                            {
                              'port': 443
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }")
            };

            response.Headers.Add("x-ms-request-id", "1");
            var handler = new RecordedDelegatingHandler(response)
            {
                StatusCodeToReturn = HttpStatusCode.OK
            };
            var client = BatchTestHelper.GetBatchManagementClient(handler);

            IPage <OutboundEnvironmentEndpoint> result = client.BatchAccount.ListOutboundNetworkDependenciesEndpoints("default-azurebatch-japaneast", "sampleacct");

            Assert.Equal(2, result.Count());

            OutboundEnvironmentEndpoint endpoint = result.ElementAt(0);

            Assert.Equal("Azure Batch", endpoint.Category);
            Assert.Equal("japaneast.batch.azure.com", endpoint.Endpoints[0].DomainName);
            Assert.Equal("Applicable to all Azure Batch pools.", endpoint.Endpoints[0].Description);
            Assert.Equal(443, endpoint.Endpoints[0].EndpointDetails[0].Port);

            endpoint = result.ElementAt(1);
            Assert.Equal("Azure Storage", endpoint.Category);
            Assert.Equal("sampleautostorageaccountname.blob.core.windows.net", endpoint.Endpoints[0].DomainName);
            Assert.Equal("AutoStorage endpoint for this Batch account. Applicable to all Azure Batch pools under this account.", endpoint.Endpoints[0].Description);
            Assert.Equal(443, endpoint.Endpoints[0].EndpointDetails[0].Port);
        }