Esempio n. 1
0
        public void GetBatchPoolTest()
        {
            // Setup cmdlet to get a pool by id
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = "testPool";
            cmdlet.Filter       = null;

            // Build a CloudPool instead of querying the service on a Get CloudPool call
            CloudPoolGetResponse response    = BatchTestHelpers.CreateCloudPoolGetResponse(cmdlet.Id);
            RequestInterceptor   interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudPoolGetParameters, CloudPoolGetResponse>(response);

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSCloudPool> pipeline = new List <PSCloudPool>();

            commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the pool returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Id, pipeline[0].Id);
        }
        public void GetBatchPoolTest()
        {
            // Setup cmdlet to get a Pool by name
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Name         = "testPool";
            cmdlet.Filter       = null;

            // Build a Pool instead of querying the service on a GetPool call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is GetPoolRequest)
                {
                    GetPoolResponse response = BatchTestHelpers.CreateGetPoolResponse(cmdlet.Name);
                    Task <object> task       = Task <object> .Factory.StartNew(() => { return(response); });
                    return(task);
                }
                return(null);
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSCloudPool> pipeline = new List <PSCloudPool>();

            commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the Pool returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Name, pipeline[0].Name);
        }
        public void GetBatchPoolTest()
        {
            // Setup cmdlet to get a pool by id
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = "testPool";
            cmdlet.Filter       = null;

            // Pool returned in the response
            ProxyModels.CloudPool pool = new ProxyModels.CloudPool();
            pool.Id = cmdlet.Id;
            pool.TaskSlotsPerNode = 16;

            // Build a CloudPool instead of querying the service on a Get CloudPool call
            AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> response = BatchTestHelpers.CreateCloudPoolGetResponse(pool);
            RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <
                ProxyModels.PoolGetOptions,
                AzureOperationResponse <ProxyModels.CloudPool, ProxyModels.PoolGetHeaders> >(response);

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                interceptor
            };

            // Setup the cmdlet to write pipeline output to a list that can be examined later
            List <PSCloudPool> pipeline = new List <PSCloudPool>();

            commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudPool>())).Callback <object>(p => pipeline.Add((PSCloudPool)p));

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the pool returned from the OM to the pipeline
            Assert.Single(pipeline);
            Assert.Equal(cmdlet.Id, pipeline[0].Id);
            Assert.Equal(16, pipeline[0].TaskSlotsPerNode);
        }