public void ListPoolsMaxCountTest()
        {
            // Verify default max count
            Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);

            // Setup cmdlet to list Pools without filters and a max count
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Name         = null;
            cmdlet.Filter       = null;
            int maxCount = 2;

            cmdlet.MaxCount = maxCount;

            string[] namesOfConstructedPools = new[] { "name1", "name2", "name3" };

            // Build some Pools instead of querying the service on a ListPools call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListPoolsRequest)
                {
                    ListPoolsResponse response = BatchTestHelpers.CreateListPoolsResponse(namesOfConstructedPools);
                    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 max count was respected
            Assert.Equal(maxCount, pipeline.Count);

            // Verify setting max count <= 0 doesn't return nothing
            cmdlet.MaxCount = -5;
            pipeline.Clear();
            cmdlet.ExecuteCmdlet();

            Assert.Equal(namesOfConstructedPools.Length, pipeline.Count);
        }
        public void ListBatchPoolByODataFilterTest()
        {
            // Setup cmdlet to list Pools using an OData filter
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Name         = null;
            cmdlet.Filter       = "startswith(name,'test')";

            string[] namesOfConstructedPools = new[] { "test1", "test2" };

            // Build some Pools instead of querying the service on a ListPools call
            YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) =>
            {
                if (request is ListPoolsRequest)
                {
                    ListPoolsResponse response = BatchTestHelpers.CreateListPoolsResponse(namesOfConstructedPools);
                    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 constructed Pools to the pipeline
            Assert.Equal(2, pipeline.Count);
            int poolCount = 0;

            foreach (PSCloudPool p in pipeline)
            {
                Assert.True(namesOfConstructedPools.Contains(p.Name));
                poolCount++;
            }
            Assert.Equal(namesOfConstructedPools.Length, poolCount);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds a ListPoolsResponse object
        /// </summary>
        public static ListPoolsResponse CreateListPoolsResponse(IEnumerable <string> poolNames)
        {
            ListPoolsResponse response = new ListPoolsResponse();

            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            List <Pool> pools = new List <Pool>();

            foreach (string name in poolNames)
            {
                Pool pool = new Pool();
                SetProperty(pool, "Name", name);
                pools.Add(pool);
            }

            SetProperty(response, "Pools", pools);

            return(response);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Builds a ListPoolsResponse object
        /// </summary>
        public static ListPoolsResponse CreateListPoolsResponse(IEnumerable<string> poolNames)
        {
            ListPoolsResponse response = new ListPoolsResponse();
            SetProperty(response, "StatusCode", HttpStatusCode.OK);

            List<Pool> pools = new List<Pool>();

            foreach (string name in poolNames)
            {
                Pool pool = new Pool();
                SetProperty(pool, "Name", name);
                pools.Add(pool);
            }

            SetProperty(response, "Pools", pools);

            return response;
        }