示例#1
0
        public void AccountDeleteNotFoundValidateMessage()
        {
            var acceptedResponse = new HttpResponseMessage(HttpStatusCode.Accepted)
            {
                Content = new StringContent(@"")
            };

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

            var notFoundResponse = new HttpResponseMessage(HttpStatusCode.NotFound)
            {
                Content = new StringContent(@"")
            };

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

            var client = BatchTestHelper.GetBatchManagementClient(handler);

            var result = Assert.Throws <CloudException>(() => Task.Factory.StartNew(() =>
                                                                                    client.BatchAccount.DeleteWithHttpMessagesAsync(
                                                                                        "resGroup",
                                                                                        "acctname")).Unwrap().GetAwaiter().GetResult());

            // Validate headers
            Assert.Equal(HttpMethod.Delete, handler.Requests[0].Method);
            Assert.Equal(HttpStatusCode.NotFound, result.Response.StatusCode);
        }
示例#2
0
        public void AccountListNextThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <Microsoft.Rest.ValidationException>(() => client.BatchAccount.ListNext(null));
        }
示例#3
0
        public void ApplicationListNextThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Application.ListNext(null));
        }
示例#4
0
        public void DeleteApplicationPackageValidateMessage()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.NoContent
            };

            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.DeleteApplicationPackageWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName",
                                                   "appId",
                                                   "version")).Unwrap().GetAwaiter().GetResult();

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

            // Validate result
            Assert.Equal(HttpStatusCode.NoContent, result.Response.StatusCode);
        }
示例#5
0
        public void GetLocationQuotasThrowsException()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Location.GetQuotas(null));
        }
        public void AddApplicationValidateMessage()
        {
            HttpResponseMessage response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(ApplicationJson())
            };

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

            var result = Task.Factory.StartNew(() =>
                                               client.Application.CreateWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctname",
                                                   "appId",
                                                   new Application
            {
                AllowUpdates = true,
                DisplayName  = "displayName"
            })).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.OK, result.Response.StatusCode);
            AssertOnApplicationProperties(result.Body);
        }
        public async Task PrivateEndpointConnectionList()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'value': 
                            [{
                                'properties': {
                                    'provisioningState': 'Succeeded',
                                    'privateEndpoint': {
                                        'id': '/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Network/privateEndpoints/privateEndpointName'
                                    },
                                    'privateLinkServiceConnectionState': {
                                        'status': 'Approved',
                                        'description': 'Its approved'
                                    }
                                }
                            }]
                    }")
            };

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

            var client = BatchTestHelper.GetBatchManagementClient(handler);
            var result = (await client.PrivateEndpointConnection.ListByBatchAccountAsync("rg", "myaccount")).ToList();

            // Validate result
            Assert.Equal(PrivateEndpointConnectionProvisioningState.Succeeded, result.Single().ProvisioningState);
            Assert.Equal("/subscriptions/1234/resourceGroups/rg/providers/Microsoft.Network/privateEndpoints/privateEndpointName", result.Single().PrivateEndpoint.Id);
            Assert.Equal(PrivateLinkServiceConnectionStatus.Approved, result.Single().PrivateLinkServiceConnectionState.Status);
            Assert.Equal("Its approved", result.Single().PrivateLinkServiceConnectionState.Description);
            Assert.Null(result.Single().PrivateLinkServiceConnectionState.ActionRequired);
        }
示例#8
0
        public void AccountKeysRegenerateValidateMessage()
        {
            var primaryKeyString   = "primary key string which is alot longer than this";
            var secondaryKeyString = "secondary key string which is alot longer than this";

            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'primary' : 'primary key string which is alot longer than this',
                    'secondary' : 'secondary key string which is alot longer than this',
                }")
            };

            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.RegenerateKey(
                "foo",
                "acctname",
                AccountKeyType.Primary);

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

            // Validate result
            Assert.NotEmpty(result.Primary);
            Assert.Equal(primaryKeyString, result.Primary);
            Assert.NotEmpty(result.Secondary);
            Assert.Equal(secondaryKeyString, result.Secondary);
        }
        public void ListApplicationPackageValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent($@"{{ 'value':[{ApplicationPackageJson(utcNow)}] }}")
            };


            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.ApplicationPackage.ListWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctname",
                                                   "appName")).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);
            ApplicationPackage package = result.Body.First();

            AssertOnApplicationPackageProperties(package, utcNow);
        }
        public void GetApplicationValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(ApplicationJson())
            };


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

            var result = Task.Factory.StartNew(() =>
                                               client.Application.GetWithHttpMessagesAsync(
                                                   "applicationId",
                                                   "acctname",
                                                   "id")).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);
            AssertOnApplicationProperties(result.Body);
        }
示例#11
0
        public void UpdateApplicationValidateMessage()
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.NoContent
            };

            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.UpdateApplicationWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName",
                                                   "appId",
                                                   new UpdateApplicationParameters()
            {
                AllowUpdates   = true,
                DisplayName    = "display-name",
                DefaultVersion = "blah"
            }
                                                   )).Unwrap().GetAwaiter().GetResult();


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

            // Validate result
            Assert.Equal(HttpStatusCode.NoContent, result.Response.StatusCode);
        }
示例#12
0
        public void GetLocationQuotasValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'accountQuota' : '5'
                }")
            };

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

            var result = client.Location.GetQuotas("westus");

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

            // Validate result
            Assert.Equal(5, result.AccountQuota);
        }
        public void GetDetectorValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'type': 'Microsoft.Batch/batchAccounts/detectors',
                    'id': '/subscriptions/subid/resourceGroups/default-azurebatch-japaneast/providers/Microsoft.Batch/batchAccounts/sampleacct/detectors/poolsAndNodes',
                    'name': 'poolsAndNodes',
                    'properties': {
                        'value': 'ew0KICAibWV0YWRhdGEiOiB7DQogICAgImlkIjogInBvb2xzQW5kTm9kZXMiLA0KICAgICJuYW1lIjogIlBvb2xzIGFuZCBOb2RlcyIsDQogICAgImRlc2NyaXB0aW9uIjogbnVsbCwNCiAgICAiYXV0aG9yIjogIiIsDQogICAgImNhdGVnb3J5IjogbnVsbCwNCiAgICAic3VwcG9ydFRvcGljTGlzdCI6IFsNCiAgICAgIHsNCiAgICAgICAgImlkIjogIjMyNjM1MDc3IiwNCiAgICAgICAgInBlc0lkIj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tlbj1udWxsIg0KICAgICAgfQ0KICAgIF0sDQogICAgImFuYWx5c2lzVHlwZXMiOiBudWxsLA0KICAgICJ0eXBlIjogIkFuYWx5c2lzIiwNCiAgICAic2NvcmUiOiAwLjANCiAgfSwNCiAgImRhdGFzZXQiOiBbXSwNCiAgInN0YXR1cyI6IHsNCiAgICAibWVzc2FnZSI6IG51bGwsDQogICAgInN0YXR1c0lkIjogNA0KICB9LA0KICAiZGF0YVByb3ZpZGVyc01ldGFkYXRhIjogbnVsbCwNCiAgInN1Z2dlc3RlZFV0dGVyYW5jZXMiOiBudWxsDQp9'
                    }
                }"
                                            )
            };

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

            DetectorResponse result = client.BatchAccount.GetDetector("default-azurebatch-japaneast", "sampleacct", "poolsAndNodes");

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

            Assert.Equal("poolsAndNodes", result.Name);
            Assert.NotEmpty(result.Value);
        }
        public async Task PrivateEndpointConnectionList()
        {
            var okResponse = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"
                    {
                        'value': [
                            {
                                'properties': {
                                    'groupId': 'batchAccount',
                                    'requiredMembers': [
                                        'batchAccount'
                                    ]
                                }
                            }
                        ]
                    }")
            };

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

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

            // Validate result
            Assert.Equal("batchAccount", result.Single().GroupId);
            Assert.Single(result.Single().RequiredMembers, "batchAccount");
        }
示例#15
0
        public void ListSupportedCloudServiceSkusValidateResponse()
        {
            var response = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new StringContent(@"{
                    'value': [
                        {
                          'name': 'Small',
                          'familyName': 'standardA0_A7Family',
                          'capabilities': [
                            {
                              'name': 'MaxResourceVolumeMB',
                              'value': '20480'
                            },
                            {
                              'name': 'vCPUs',
                              'value': '1'
                            },
                            {
                              'name': 'HyperVGenerations',
                              'value': 'V1'
                            },
                            {
                              'name': 'MemoryGB',
                              'value': '0.75'
                            },
                            {
                              'name': 'LowPriorityCapable',
                              'value': 'False'
                            },
                            {
                              'name': 'vCPUsAvailable',
                              'value': '1'
                            },
                            {
                              'name': 'EphemeralOSDiskSupported',
                              'value': 'False'
                            }
                          ]
                        }
                      ]
                }")
            };

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

            var result = client.Location.ListSupportedCloudServiceSkus("westus");

            // Validate headers
            Assert.Equal(HttpMethod.Get, handler.Method);
            Assert.Equal("standardA0_A7Family", result.Single().FamilyName);
            Assert.Equal("Small", result.Single().Name);
            Assert.Equal(7, result.Single().Capabilities.Count());
        }
示例#16
0
        public void AccountKeysListThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.BatchAccount.GetKeys("foo", null));
            Assert.Throws <ValidationException>(() => client.BatchAccount.GetKeys(null, "bar"));
        }
示例#17
0
        public void CannotPassNullArgumentsToListApplications()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Application.List(null, "foo"));
            Assert.Throws <ValidationException>(() => client.Application.List("foo", null));
        }
示例#18
0
        public void AccountKeysRegenerateThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.BatchAccount.RegenerateKey(null, "bar", AccountKeyType.Primary));
            Assert.Throws <ValidationException>(() => client.BatchAccount.RegenerateKey("foo", null, AccountKeyType.Primary));
            Assert.Throws <ValidationException>(() => client.BatchAccount.RegenerateKey("rg", "invalid%", AccountKeyType.Primary));
        }
示例#19
0
        public void CannotPassNullArgumentsToUpdateApplication()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Application.UpdateApplication(null, "foo", "foo", new UpdateApplicationParameters()));
            Assert.Throws <ValidationException>(() => client.Application.UpdateApplication("foo", null, "foo", new UpdateApplicationParameters()));
            Assert.Throws <ValidationException>(() => client.Application.UpdateApplication("foo", "foo", null, new UpdateApplicationParameters()));
            Assert.Throws <ValidationException>(() => client.Application.UpdateApplication("foo", "foo", "foo", null));
        }
        public void CannotPassNullArgumentsToAddApplication()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Application.Create(null, "foo", "foo", new Application()));
            Assert.Throws <ValidationException>(() => client.Application.Create("foo", null, "foo", new Application()));
            Assert.Throws <ValidationException>(() => client.Application.Create("foo", "foo", null, new Application()));
            Assert.Throws <NullReferenceException>(() => client.Application.Create("foo", "foo", "foo", null));
        }
示例#21
0
        public void AccountDeleteThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.BatchAccount.Delete("foo", null));
            Assert.Throws <ValidationException>(() => client.BatchAccount.Delete(null, "bar"));
            Assert.Throws <ValidationException>(() => client.BatchAccount.Delete("rg", "invalid%"));
            Assert.Throws <ValidationException>(() => client.BatchAccount.Delete("rg", "/invalid"));
        }
示例#22
0
        public void AccountCreateAsyncValidateMessage()
        {
            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(@"{
                                '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'
                                },
                                'tags' : {
                                    'tag1' : 'value for tag1',
                                    'tag2' : 'value for tag2',
                                }
                            }")
            };

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

            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 = Task.Factory.StartNew(() => client.BatchAccount.CreateWithHttpMessagesAsync(
                                                   "foo",
                                                   "accountname",
                                                   new BatchAccountCreateParameters
            {
                Location = "South Central US",
                Tags     = tags
            })).Unwrap().GetAwaiter().GetResult();

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

            // Validate result
            Assert.Equal("South Central US", result.Body.Location);
            Assert.NotEmpty(result.Body.AccountEndpoint);
            Assert.Equal(ProvisioningState.Succeeded, result.Body.ProvisioningState);
            Assert.Equal(2, result.Body.Tags.Count);
        }
示例#23
0
        public void AccountKeysRegenerateThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Account.RegenerateKey(null, "bar", new BatchAccountRegenerateKeyParameters()));
            Assert.Throws <ValidationException>(() => client.Account.RegenerateKey("foo", null, new BatchAccountRegenerateKeyParameters()));
            Assert.Throws <ValidationException>(() => client.Account.RegenerateKey("foo", "bar", null));
            Assert.Throws <ValidationException>(() => client.Account.RegenerateKey("invalid+", "account", new BatchAccountRegenerateKeyParameters()));
            Assert.Throws <ValidationException>(() => client.Account.RegenerateKey("rg", "invalid%", new BatchAccountRegenerateKeyParameters()));
        }
        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;
            string resourceId = "abc123";

            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") + @"',
                                        'authenticationMode': 'BatchAccountManagedIdentity',
                                        'NodeIdentityReference': { 'resourceId': '" + resourceId + @"' }
                                    }
                                },
                            }")
            };

            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",
                    AuthenticationMode    = AutoStorageAuthenticationMode.BatchAccountManagedIdentity,
                    NodeIdentityReference = new ComputeNodeIdentityReference(resourceId)
                }
            });;

            // Validate result
            Assert.Equal("//storageAccount1", result.AutoStorage.StorageAccountId);
            Assert.Equal(AutoStorageAuthenticationMode.BatchAccountManagedIdentity, result.AutoStorage.AuthenticationMode);
            Assert.Equal(resourceId, result.AutoStorage.NodeIdentityReference.ResourceId);
            Assert.Equal(utcNow, result.AutoStorage.LastKeySync);
        }
示例#25
0
        public void AccountUpdateWithAutoStorageValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            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',
                                    'autoStorage' : {
                                        'storageAccountId' : '//StorageAccountId',
                                        'lastKeySync': '" + utcNow.ToString("o") + @"',
                                    }
                                },
                                '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,
            });

            // Validate headers - User-Agent for certs, Authorization for tokens
            //Assert.Equal(HttpMethod.Patch, handler.Method);
            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("//StorageAccountId", result.AutoStorage.StorageAccountId);
            Assert.Equal(utcNow, result.AutoStorage.LastKeySync);
            Assert.Equal(2, result.Tags.Count);
        }
示例#26
0
        public void AccountCreateThrowsExceptions()
        {
            var handler = new RecordedDelegatingHandler();
            var client  = BatchTestHelper.GetBatchManagementClient(handler);

            Assert.Throws <ValidationException>(() => client.Account.Create(null, "bar", new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("foo", null, new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("foo", "bar", null));
            Assert.Throws <ValidationException>(() => client.Account.Create("invalid+", "account", new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("rg", "invalid%", new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("rg", "/invalid", new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("rg", "s", new BatchAccountCreateParameters()));
            Assert.Throws <ValidationException>(() => client.Account.Create("rg", "account_name_that_is_too_long", new BatchAccountCreateParameters()));
        }
示例#27
0
        public void ListApplicationValidateMessage()
        {
            var utcNow = DateTime.UtcNow;

            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Created)
            {
                StatusCode = HttpStatusCode.OK,
                Content    = new StringContent(@"{ 'value':[{
                    'id': 'foo',
                    'allowUpdates': 'true',
                    'displayName' : 'DisplayName',
                    'defaultVersion' : 'beta',
                    'packages':[
                        {'version':'version1', 'state':'pending', 'format': 'beta', 'lastActivationTime': '" + utcNow.ToString("o") + @"'},
                        {'version':'version2', 'state':'pending', 'format': 'alpha', '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.ListWithHttpMessagesAsync(
                                                   "resourceGroupName",
                                                   "acctName")).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);

            Application application = result.Body.First();

            Assert.Equal("foo", application.Id);
            Assert.Equal(true, application.AllowUpdates);
            Assert.Equal("beta", application.DefaultVersion);
            Assert.Equal("DisplayName", application.DisplayName);
            Assert.Equal(2, application.Packages.Count);
            Assert.Equal("beta", application.Packages.First().Format);
            Assert.Equal(PackageState.Pending, application.Packages.First().State);
            Assert.Equal("version1", application.Packages.First().Version);
            Assert.Equal(utcNow, application.Packages.First().LastActivationTime);
        }
示例#28
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',
                        'dedicatedCoreQuota' : '20',
                        'lowPriorityCoreQuota' : '50',
                        '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.BatchAccount.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.DedicatedCoreQuota);
            Assert.Equal(50, result.LowPriorityCoreQuota);
            Assert.Equal(100, result.PoolQuota);
            Assert.Equal(200, result.ActiveJobAndJobScheduleQuota);

            Assert.True(result.Tags.ContainsKey("tag1"));
        }
示例#29
0
        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.Account.Create("resourceGroupName", "acctName", new BatchAccountCreateParameters
            {
                Location    = "South Central US",
                AutoStorage = new AutoStorageBaseProperties()
            }));

            Assert.Equal("StorageAccountId", ex.Target.ToString());
        }
示例#30
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);
        }