public void GetBatchComputeNodeExtensionTest() { string extensionName = "testExtension"; string publisher = "testPublisher"; string type = "testType"; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.Name = extensionName; VMExtension extension = new VMExtension(extensionName, publisher, type); // Build an extension instead of querying the service on a Get ComputeNodeExtension call AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionGetResponse(extension); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionGetOptions, AzureOperationResponse <ProxyModels.NodeVMExtension, ProxyModels.ComputeNodeExtensionGetHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeVMExtension> pipeline = new List <PSNodeVMExtension>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeVMExtension>())).Callback <object>(c => pipeline.Add((PSNodeVMExtension)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the compute node returned from the OM to the pipeline Assert.Single(pipeline); PSVMExtension pipelineExtension = pipeline[0].VmExtension; Assert.NotNull(pipelineExtension); Assert.Equal("testExtension", pipelineExtension.Name); Assert.Equal("testPublisher", pipelineExtension.Publisher); Assert.Equal("testType", pipelineExtension.Type); }
public void ListBatchComputeNodeExtensionsWithMaxCountTest() { int maxCount = 3; // Setup cmdlet to get a compute node by id BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.PoolId = "testPool"; cmdlet.ComputeNodeId = "testComputeNode"; cmdlet.MaxCount = maxCount; int count = 5; // Build an extension instead of querying the service on a Get ComputeNodeExtension call AzureOperationResponse <IPage <ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> response = BatchTestHelpers.CreateComputeNodeExtensionListResponse(CreateTestExtensions(count)); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor < ProxyModels.ComputeNodeExtensionListOptions, AzureOperationResponse <IPage <ProxyModels.NodeVMExtension>, ProxyModels.ComputeNodeExtensionListHeaders> >(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSNodeVMExtension> pipeline = new List <PSNodeVMExtension>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSNodeVMExtension>())).Callback <object>(c => pipeline.Add((PSNodeVMExtension)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the compute node returned from the OM to the pipeline Assert.Equal(maxCount, pipeline.Count); for (int i = 1; i <= maxCount; i++) { PSVMExtension extension = pipeline[i - 1].VmExtension; Assert.Equal($"testExtension{i}", extension.Name); Assert.Equal($"testPublisher{i}", extension.Publisher); Assert.Equal($"testType{i}", extension.Type); } }