public void GetBatchVMTest() { // Setup cmdlet to get a vm by name BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolName = "pool"; cmdlet.Name = "vm1"; cmdlet.Filter = null; // Build a vm instead of querying the service on a GetTVM call YieldInjectionInterceptor interceptor = new YieldInjectionInterceptor((opContext, request) => { if (request is GetTVMRequest) { GetTVMResponse response = BatchTestHelpers.CreateGetTVMResponse(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 <PSVM> pipeline = new List <PSVM>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSVM>())).Callback <object>(v => pipeline.Add((PSVM)v)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the vm returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Name, pipeline[0].Name); }