Example #1
0
        private static AWSCredentials GetCredentials(AmazonServiceClient client)
        {
            var type        = client.GetType();
            var property    = type.GetProperty("Credentials", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
            var credentials = property.GetValue(client, null) as AWSCredentials;

            return(credentials);
        }
Example #2
0
        public static void SetEndpoint(AmazonServiceClient client, string serviceUrl)
        {
            var clientConfig = client
                               .GetType()
                               .GetProperty("Config", BindingFlags.Instance | BindingFlags.NonPublic)
                               .GetValue(client, null) as ClientConfig;

            clientConfig.ServiceURL = serviceUrl;
        }
Example #3
0
        public static void ReplaceHttpHandler <T>(
            AmazonServiceClient client,
            HttpHandler <T> httpHandler)
        {
            var pipeline = client
                           .GetType()
                           .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                           .GetValue(client, null)
                           as RuntimePipeline;

            pipeline.ReplaceHandler <HttpHandler <T> >(httpHandler);
        }
Example #4
0
        public static void SetEndpoint(AmazonServiceClient client, string serviceUrl, string region = null)
        {
            var clientConfig = client
                               .GetType()
                               .GetProperty("Config", BindingFlags.Instance | BindingFlags.NonPublic)
                               .GetValue(client, null) as ClientConfig;

            clientConfig.ServiceURL = serviceUrl;
            if (region != null)
            {
                clientConfig.AuthenticationRegion = region;
            }
        }
Example #5
0
            public static void AddToClient(AmazonServiceClient client)
            {
                var pipeline = client
                               .GetType()
                               .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                               .GetValue(client, null)
                               as RuntimePipeline;

                var requestFactory = new RetryHttpRequestFactory();
                var httpHandler    = new HttpHandler <Stream>(requestFactory, client);

                pipeline.ReplaceHandler <HttpHandler <Stream> >(httpHandler);
            }
Example #6
0
        public static void AssertClientHasCredentials(AmazonServiceClient client, AWSCredentials credentials)
        {
            var prop = client.GetType().GetProperty("Credentials", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy);
            var actualCredentials = ((AWSCredentials)prop.GetValue(client)).GetCredentials();
            var givenCredentials  = credentials.GetCredentials();

            if (actualCredentials?.AccessKey != givenCredentials.AccessKey ||
                actualCredentials?.SecretKey != givenCredentials.SecretKey ||
                actualCredentials?.Token != givenCredentials.Token)
            {
                throw new Exception("Credentials do not match");
            }
        }
Example #7
0
        public static void SetResponse(
            AmazonServiceClient client,
            Func<HttpHandlerTests.MockHttpRequest, HttpWebResponse> responseCreator)
        {
            var pipeline = client
                .GetType()
                .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                .GetValue(client, null)
                as RuntimePipeline;

            var requestFactory = new HttpHandlerTests.MockHttpRequestFactory();
            requestFactory.ResponseCreator = responseCreator;
            var httpHandler = new HttpHandler<Stream>(requestFactory, client);
            pipeline.ReplaceHandler<HttpHandler<Stream>>(httpHandler);
        }
        public static void SetResponse(AmazonServiceClient client, Func <MockHttpRequest, HttpResponseMessage> responseCreator)
        {
            var pipeline = client
                           .GetType()
                           .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                           .GetValue(client, null)
                           as RuntimePipeline;

            var requestFactory = new MockHttpRequestFactory();

            requestFactory.ResponseCreator = responseCreator;
            var httpHandler = new HttpHandler <HttpContent>(requestFactory, client);

            pipeline.ReplaceHandler <HttpHandler <HttpContent> >(httpHandler);
        }
Example #9
0
            public static void AddToClient(AmazonServiceClient client, Mocker mocker)
            {
                var pipeline = client
                               .GetType()
                               .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
                               .GetValue(client, null)
                               as RuntimePipeline;

                var requestFactory = new MockHttpRequestFactory(mocker);
                var httpHandler    = new HttpHandler <Stream>(requestFactory, client);

                Console.WriteLine("Pipeline before adding mock");
                LogHandlers(pipeline);
                pipeline.ReplaceHandler <HttpHandler <Stream> >(httpHandler);
                Console.WriteLine("Pipeline after adding mock");
                LogHandlers(pipeline);
            }
Example #10
0
 private static AWSCredentials GetCredentials(AmazonServiceClient client)
 {
     var type = client.GetType();
     var property = type.GetProperty("Credentials", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
     var credentials = property.GetValue(client, null) as AWSCredentials;
     return credentials;
 }