public void GetBatchJobTest()
        {
            // Setup cmdlet to get a Job by name
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = "job-1";
            cmdlet.Filter       = null;

            // Build a CloudJob instead of querying the service on a Get CloudJob call
            CloudJobGetResponse response    = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id);
            RequestInterceptor  interceptor = BatchTestHelpers.CreateNoOpInterceptor <CloudJobGetParameters, CloudJobGetResponse>(response);

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

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

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

            cmdlet.ExecuteCmdlet();

            // Verify that the cmdlet wrote the job returned from the OM to the pipeline
            Assert.Equal(1, pipeline.Count);
            Assert.Equal(cmdlet.Id, pipeline[0].Id);
        }
Ejemplo n.º 2
0
        public void GetBatchJobODataTest()
        {
            // Setup cmdlet to get a single job
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext = context;
            cmdlet.Id           = "testJob";
            cmdlet.Select       = "id,state";
            cmdlet.Expand       = "stats";

            string requestSelect = null;
            string requestExpand = null;

            // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used.
            CloudJobGetResponse getResponse         = BatchTestHelpers.CreateCloudJobGetResponse(cmdlet.Id);
            RequestInterceptor  requestInterceptor  = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CloudJobGetParameters, CloudJobGetResponse>(getResponse);
            ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) =>
            {
                requestSelect = request.Parameters.DetailLevel.SelectClause;
                requestExpand = request.Parameters.DetailLevel.ExpandClause;

                return(Task.FromResult(response));
            });

            cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>()
            {
                requestInterceptor, responseInterceptor
            };

            cmdlet.ExecuteCmdlet();

            Assert.Equal(cmdlet.Select, requestSelect);
            Assert.Equal(cmdlet.Expand, requestExpand);
        }