Esempio n. 1
0
        public async Task TestRequestWhichDoesSupportSelect()
        {
            using (BatchClient client = await BatchClient.OpenAsync(ClientUnitTestCommon.CreateDummySharedKeyCredential()))
            {
                ODATADetailLevel    detailLevel = new ODATADetailLevel(selectClause: "foo");
                bool                wasHit      = false;
                BatchClientBehavior behavior    = new Protocol.RequestInterceptor(request =>
                {
                    PoolGetBatchRequest poolGetRequest = request as PoolGetBatchRequest;

                    poolGetRequest.ServiceRequestFunc = t =>
                    {
                        Assert.Equal(detailLevel.SelectClause, poolGetRequest.Options.Select);
                        wasHit = true; //Ensure the interceptor was hit
                        return(Task.FromResult(new AzureOperationResponse <CloudPool, PoolGetHeaders>()
                        {
                            Body = new CloudPool()
                        }));
                    };
                });
                const string dummyPoolId = "dummy";

                await client.PoolOperations.GetPoolAsync(dummyPoolId, detailLevel, new[] { behavior });

                Assert.True(wasHit);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Fabricates a CloudPool that's in the bound state
        /// </summary>
        public static CloudPool CreateFakeBoundPool(BatchAccountContext context)
        {
            string poolId = "testPool";

            RequestInterceptor interceptor = new RequestInterceptor((baseRequest) =>
            {
                PoolGetBatchRequest request = (PoolGetBatchRequest)baseRequest;

                request.ServiceRequestFunc = (cancellationToken) =>
                {
                    var response  = new AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders>();
                    response.Body = new ProxyModels.CloudPool(poolId, "small", "4");

                    Task <AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> > task = Task.FromResult(response);
                    return(task);
                };
            });

            return(context.BatchOMClient.PoolOperations.GetPool(poolId, additionalBehaviors: new BatchClientBehavior[] { interceptor }));
        }
Esempio n. 3
0
        public async Task TestRequestWhichDoesntSupportFilter()
        {
            using BatchClient client = ClientUnitTestCommon.CreateDummyClient();
            BatchClientBehavior behavior = new Protocol.RequestInterceptor(request =>
            {
                PoolGetBatchRequest poolGetRequest = request as PoolGetBatchRequest;
                poolGetRequest.ServiceRequestFunc  = t =>
                {
                    return(Task.FromResult(new AzureOperationResponse <CloudPool, PoolGetHeaders>()
                    {
                        Body = new CloudPool()
                    }));
                };
            });
            const string      dummyPoolId = "dummy";
            DetailLevel       detailLevel = new ODATADetailLevel(filterClause: "foo");
            ArgumentException e           = await Assert.ThrowsAsync <ArgumentException>(async() => await client.PoolOperations.GetPoolAsync(dummyPoolId, detailLevel, new[] { behavior }));

            Assert.Contains("Type Microsoft.Azure.Batch.Protocol.BatchRequests.PoolGetBatchRequest does not support a filter clause.", e.Message);
            Assert.Equal("detailLevel", e.ParamName);
        }