Beispiel #1
0
        public void GetPoolStartTask()
        {
            var startTask = new Protocol.Models.StartTask
            {
                CommandLine         = "-start",
                EnvironmentSettings = new[] { new Models.EnvironmentSetting {
                                                  Name = "windows", Value = "foo"
                                              } },
                MaxTaskRetryCount = 3,
                RunElevated       = false,
                WaitForSuccess    = false
            };


            BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential();

            using (BatchClient client = BatchClient.Open(credentials))
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(baseRequest =>
                {
                    var request = (Protocol.BatchRequest <Models.PoolGetOptions, AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders> >)baseRequest;

                    request.ServiceRequestFunc = async(token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Models.CloudPool {
                                DisplayName = "batch-test", StartTask = startTask,
                            }
                        };

                        var task = Task.FromResult(response);
                        return(await task);
                    };
                });

                var pool = client.PoolOperations.GetPool("batch-test", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal("batch-test", pool.DisplayName);
                Assert.Equal(pool.StartTask.CommandLine, "-start");
                Assert.Equal(pool.StartTask.EnvironmentSettings.FirstOrDefault().Name, "windows");
                Assert.Equal(pool.StartTask.EnvironmentSettings.FirstOrDefault().Value, "foo");
                Assert.Equal(pool.StartTask.MaxTaskRetryCount, 3);
                Assert.Equal(pool.StartTask.RunElevated, false);
                Assert.Equal(pool.StartTask.WaitForSuccess, false);
            }
        }
        public void GetPoolStartTask()
        {
            var startTask = new Protocol.Models.StartTask
            {
                CommandLine         = "-start",
                EnvironmentSettings = new[] { new Models.EnvironmentSetting {
                                                  Name = "windows", Value = "foo"
                                              } },
                MaxTaskRetryCount = 3,
                UserIdentity      = new Protocol.Models.UserIdentity(
                    autoUser: new Protocol.Models.AutoUserSpecification(elevationLevel: Protocol.Models.ElevationLevel.NonAdmin)),
                WaitForSuccess = false
            };

            using (BatchClient client = ClientUnitTestCommon.CreateDummyClient())
            {
                Protocol.RequestInterceptor interceptor = new Protocol.RequestInterceptor(baseRequest =>
                {
                    var request = (Protocol.BatchRequest <Models.PoolGetOptions, AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders> >)baseRequest;

                    request.ServiceRequestFunc = async(token) =>
                    {
                        var response = new AzureOperationResponse <Models.CloudPool, Models.PoolGetHeaders>
                        {
                            Body = new Models.CloudPool {
                                DisplayName = "batch-test", StartTask = startTask,
                            }
                        };

                        var task = Task.FromResult(response);
                        return(await task);
                    };
                });

                var pool = client.PoolOperations.GetPool("batch-test", additionalBehaviors: new List <BatchClientBehavior> {
                    interceptor
                });

                Assert.Equal("batch-test", pool.DisplayName);
                Assert.Equal("-start", pool.StartTask.CommandLine);
                Assert.Equal("windows", pool.StartTask.EnvironmentSettings.FirstOrDefault().Name);
                Assert.Equal("foo", pool.StartTask.EnvironmentSettings.FirstOrDefault().Value);
                Assert.Equal(3, pool.StartTask.MaxTaskRetryCount);
                Assert.Equal(ElevationLevel.NonAdmin, pool.StartTask.UserIdentity.AutoUser.ElevationLevel);
                Assert.Equal(false, pool.StartTask.WaitForSuccess);
            }
        }