예제 #1
0
        public void ListCertificatesMaxCountTest()
        {
            // Verify default max count
            Assert.Equal(Microsoft.Azure.Commands.Batch.Utils.Constants.DefaultMaxCount, cmdlet.MaxCount);

            // Setup cmdlet to list pools without filters and a max count
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext        = context;
            cmdlet.ThumbprintAlgorithm = null;
            cmdlet.Thumbprint          = null;
            cmdlet.Filter = null;
            int maxCount = 2;

            cmdlet.MaxCount = maxCount;

            string[] thumbprintsOfConstructedCerts = new[] { "12345", "67890", "ABCDE" };

            // Build some Certificates instead of querying the service on a List Certificates call
            CertificateListResponse response    = BatchTestHelpers.CreateCertificateListResponse(thumbprintsOfConstructedCerts);
            RequestInterceptor      interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateListParameters, CertificateListResponse>(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 max count was respected
            Assert.Equal(maxCount, pipeline.Count);

            // Verify setting max count <= 0 doesn't return nothing
            cmdlet.MaxCount = -5;
            pipeline.Clear();
            cmdlet.ExecuteCmdlet();

            Assert.Equal(thumbprintsOfConstructedCerts.Length, pipeline.Count);
        }
예제 #2
0
        public void ListBatchCertificatesWithoutFiltersTest()
        {
            // Setup cmdlet to list certs without filters
            BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();

            cmdlet.BatchContext        = context;
            cmdlet.ThumbprintAlgorithm = null;
            cmdlet.Thumbprint          = null;
            cmdlet.Filter = null;

            string[] thumbprintsOfConstructedCerts = new[] { "12345", "67890", "ABCDE" };

            // Build some Certificates instead of querying the service on a List Certificates call
            CertificateListResponse response    = BatchTestHelpers.CreateCertificateListResponse(thumbprintsOfConstructedCerts);
            RequestInterceptor      interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor <CertificateListParameters, CertificateListResponse>(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 constructed certs to the pipeline
            Assert.Equal(3, pipeline.Count);
            int poolCount = 0;

            foreach (PSCertificate c in pipeline)
            {
                Assert.True(thumbprintsOfConstructedCerts.Contains(c.Thumbprint));
                poolCount++;
            }
            Assert.Equal(thumbprintsOfConstructedCerts.Length, poolCount);
        }