public void GetBatchCertificateODataTest() { // Setup cmdlet to get a single certificate BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = "sha1"; cmdlet.Thumbprint = "123456789"; cmdlet.Select = "thumbprint,state"; string requestSelect = null; // Fetch the OData clauses off the request. The OData clauses are applied after user provided RequestInterceptors, so a ResponseInterceptor is used. CertificateGetResponse getResponse = BatchTestHelpers.CreateCertificateGetResponse(cmdlet.Thumbprint); RequestInterceptor requestInterceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateGetParameters, CertificateGetResponse>(getResponse); ResponseInterceptor responseInterceptor = new ResponseInterceptor((response, request) => { requestSelect = request.Parameters.DetailLevel.SelectClause; return(Task.FromResult(response)); }); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { requestInterceptor, responseInterceptor }; cmdlet.ExecuteCmdlet(); Assert.Equal(cmdlet.Select, requestSelect); }
public void GetBatchCertificateTest() { // Setup cmdlet to get a cert by its thumbprint BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys(); cmdlet.BatchContext = context; cmdlet.ThumbprintAlgorithm = "sha1"; cmdlet.Thumbprint = "123456789"; cmdlet.Filter = null; // Build a Certificate instead of querying the service on a Get Certificate call CertificateGetResponse response = BatchTestHelpers.CreateCertificateGetResponse(cmdlet.Thumbprint); RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateGetParameters, CertificateGetResponse>(response); cmdlet.AdditionalBehaviors = new List <BatchClientBehavior>() { interceptor }; // Setup the cmdlet to write pipeline output to a list that can be examined later List <PSCertificate> pipeline = new List <PSCertificate>(); commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny <PSCertificate>())).Callback <object>(c => pipeline.Add((PSCertificate)c)); cmdlet.ExecuteCmdlet(); // Verify that the cmdlet wrote the cert returned from the OM to the pipeline Assert.Equal(1, pipeline.Count); Assert.Equal(cmdlet.Thumbprint, pipeline[0].Thumbprint); }