public void GetBatchWorkItemTest() { // Setup cmdlet to get a WorkItem by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.Name = "testWorkItem"; cmdlet.Filter = null; // Build a WorkItem instead of querying the service on a GetWorkItem call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is GetWorkItemRequest) { GetWorkItemResponse response = BatchTestHelpers.CreateGetWorkItemResponse(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 <PSCloudWorkItem> pipeline = new List <PSCloudWorkItem>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCloudWorkItem>())).Callback <object>(w => pipeline.Add((PSCloudWorkItem)w)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the WorkItem returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Name, pipeline[0].Name); }